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

Support "dim"/"faint" modifier #78

Open
nwalters512 opened this issue May 3, 2023 · 9 comments
Open

Support "dim"/"faint" modifier #78

nwalters512 opened this issue May 3, 2023 · 9 comments
Milestone

Comments

@nwalters512
Copy link

nwalters512 commented May 3, 2023

Consider the following code:

const chalk = require('chalk')
const { default: AnsiUp } = require('ansi_up');

const ansiUp = new AnsiUp();
console.log(ansiUp.ansi_to_html(chalk.dim('testing')));

Per the "SGR" section where $n = 2$ on https://en.wikipedia.org/wiki/ANSI_escape_code, the modifier in use here is defined as "Faint, decreased intensity, or dim". I would expect this to render as something like either of the following:

<span style="filter:brightness(0.7)">testing</span>
<span style="opacity:0.7">testing</span>

However, it just prints the string testing, indicating that this library doesn't support this modifier.

I'd be willing to open a PR if you'd accept one!

For reference, here's how a few other similar libraries implement this:

@drudru
Copy link
Owner

drudru commented Jun 23, 2023

Hi. Just thinking out loud.

We currently handle bold as 'font-weight: bold' for that span.
The Wikipedia page is stating that faint/dim should be handled as a font-weight.
If we do that, this becomes a tri-state for the font-weight, not too difficult.

If we have to set the CSS to a filter or opacity, that is also, ok, but could be configured as a non default option.

@nwalters512 - How does that sound?

@silverwind
Copy link

I guess I would also prefer font weight. BTW, are there equvialent CSS classes for font-weight? The example does not show any.

@drudru
Copy link
Owner

drudru commented Jul 7, 2023

Lets go with font weight and add the classes to the example.
This will go into the next major release.

@drudru drudru added this to the 6.0 milestone Jul 8, 2023
@nwalters512
Copy link
Author

I don't love doing this with font weight, as that doesn't align with how the other terminals I have access to display text with the dim/faint modifier.

Here's the macOS terminal:

Screenshot 2023-07-11 at 10 11 16

And here's iTerm 2:

Screenshot 2023-07-11 at 10 11 44

Each of them are distinguished by a dimmer apparent color, not a different weight.

@silverwind
Copy link

silverwind commented Jul 11, 2023

If color manipulation can be done cleanly, e.g. no filter (which causes fringe issues, but could maybe be worked around using mix-blend-mode), and no opacity (does not work on non-opaque background), I guess I do have a preference for it too.

The ideal way to do it is with the brand-new color-mix, but it may be too new to use. Personally, I don't care as I'll not be using the built-in styles but style via classes where I can decide myself whether to use color-mix.

@drudru
Copy link
Owner

drudru commented Aug 15, 2023

Released

@drudru drudru closed this as completed Aug 15, 2023
@silverwind
Copy link

silverwind commented Aug 18, 2023

For some reason, I see no difference on SGR 2 using v6.0.0:

image

HTML rendering:

Screenshot 2023-08-18 at 18 54 53

Same rendering in iTerm2 (bold is disabled in my settings):

Screenshot 2023-08-18 at 19 04 12

Output was produced with this:

curl -sL https://gist.github.com/lilydjwg/fdeaf79e921c2f413f44b6f613f6ad53/raw/94d8b2be62657e96488038b0e547e3009ed87d40/colors.py | python3

@drudru drudru reopened this Sep 10, 2023
@drudru
Copy link
Owner

drudru commented Sep 10, 2023

@silverwind - just saw this in my email. Sorry. I will look at your examples.

@silverwind
Copy link

silverwind commented Sep 11, 2023

Thanks, besides SGR2, SGR7 and SGR8 and the whole second row except SGR21 and hyperlink in the example could be improved. Maybe do it like iTerm and never output unknown escape sequences, which imho are never useful in a rendering.

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

No branches or pull requests

3 participants