Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support bold ANSI escape sequence #154

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gabe565
Copy link

@gabe565 gabe565 commented Nov 21, 2024

The code to print bold text is currently commented out, even though it works fine. This PR uncomments it to add support for rendering bold text.

I also noticed that bold text wasn't very pronounced, so I changed the font-weight to bolder. If this is undesired, just let me know and I can remove that change.

Before:
Example of current behavior

After (with font-weight="bold"):
Example with bold font

After (with font-weight="bolder"):
Example with bolder font

I also noticed the bold

Fixes #75

@meowgorithm
Copy link
Member

Awesome, thanks for the PR. One question: why bolder instead of bold?

@gabe565
Copy link
Author

gabe565 commented Dec 5, 2024

@meowgorithm Maybe my machine is rendering fonts strangely, but bold doesn't look very different than regular text, so I was trying to make the effect more obvious. Would you prefer bold? That might make more sense

@meowgorithm
Copy link
Member

meowgorithm commented Dec 5, 2024

@gabe565 can you render to PNG and post the results here? SVGs render differently depending on device (for example, the SVGs above look different on my phone versus my desktop).

bold is probably the better choice as the renderer will typically choose the actual bold typeface (i.e. JetBrains Mono Bold). bolder will look for the next weight heavier than regular (called medium), however because that font is typically not available, the renderer will synthesize a bolder version of the font, which is a bit of a typographic horror.

In other words, given than 400 (regular) is the default weight, bolder will look for the 500 weight which is typically not available, and synthesize a bold version of regular. If it is installed it likely won't be bold enough. bold, on the other hand, will always refer to 700.

Weight Name Filename
400 Regular JetBrains-Mono-Regular.otf
500 Medium Often not installed
600 Semibold Often not installed
700 Bold JetBrains-Mono-Bold.otf
800 Extra Bold Often not installed
900 Black Often not installed

@bashbunni bashbunni assigned meowgorithm and unassigned aymanbagabas Dec 5, 2024
Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than using "bold", looks good 🙂

ansi.go Outdated Show resolved Hide resolved
@gabe565
Copy link
Author

gabe565 commented Dec 6, 2024

Thanks for the insight, I hadn't thought about rendering handled when a 500 weight font wasn't available. For some reason PNG rendering doesn't work on my machine, so let me try it in a container. I'm curious to see the difference

@gabe565
Copy link
Author

gabe565 commented Dec 6, 2024

Ok I went ahead and changed the weight back to bold since it sounds like that's the best solution. I tried generating PNGs, but the font weight looks exactly the same. I'm sure it isn't a testing issue because it still works when rendering to an SVG, so I'm not sure why the font weight looks the same.

I don't think it's super helpful, but here's what I get:

If I render to an SVG, the font-weight: bold is definitely there:

<tspan xml:space="preserve" font-weight="bold">Bold text</tspan>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support bold in ANSI coloring
4 participants