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
To upsample, or not to upsample? #370
Comments
Here are the relevant code snippets from the const levelMapping = [
'ansi',
'ansi',
'ansi256',
'ansi16m'
]; Here are places for potential short-cut to avoid upsample for some
|
The dependency is there anyway, and ansi to ansi in I'd like to see benchmarking results to see if this is really a bottleneck. Also something worth mentioning: the 16 basic (level 1) color palette is considered sacred; many users override the default colors in their emulator and rely on applications to differentiate between "I'm using the green palette color" and "I seriously need this to be green on the screen", because those are not equal use cases. In the former case, one would use Here's kind of where things get less-than-ideal (this isn't a dig at you, I'm merely stating this here to explain why Chalk's API might seem ugly or counterintuitive): Chalk is dealing with a horribly outdated and under-documented standard that is decades old and mainly laid out by a wikipedia article, completely ignoring the terminfo database (which would make it functionally 'correct') - which would be worse if it weren't for the fact that the terminfo database's format is also horribly outdated (e.g. 256 colors nor truecolor are represented in the database format) and getting PRs into that project can take longer than some Chalk users have been alive. This is all exasperated by the fact that most emulators and shells don't adhere to any single terminfo database entry and generally implement the version on Wikipedia (which loosely resembles the official Xterm terminfo profile). And even worse, most modern applications that don't use a wrapper just assume the emulator supports these codes, too - so the terminfo database is quickly becoming obsolete and irrelevant. However, there is no replacement - there is (currently) no standard for control sequences, and given that most applications use text-only streams, there's no great way to make an alternative programmatic interface to the enclosing emulator (assuming there is an enclosing emulator, which is not always the case when the application runs under e.g. systemd, docker, etc.) Further, there is no "intended use" of the color sequences. As I mentioned above, the basic 16 color palette has no guarantee that e.g. Conversely, I've yet to see an emulator that supports re-defining the 256 color palette or re-interpret truecolor control sequences. Since both ansi256 and truecolor escapes give the application developer reasonable near-guarantees that the color they specified is the color that will show up on the screen, they might choose those colors over the basic 16-color palette in cases where accurate colors are important. Fast-forward to the Chalk library's API design. We have to support this kind of bizarre, rock-and-a-hard-place use case if we're going to support higher level color models (e.g. ansi256 or truecolor). If there is a better way to handle the API given all of this information, please by all means suggest it, because I would love to see the UX improved if it's possible. At the very least, if nothing functional comes out of this issue, we should document this since I also think this is an important observation. Thank you for bringing it up :) |
Josh, thanks for sharing your experience with ANSI escape codes Two thoughts jumped out:
|
Hey there, thanks for the detailed response. 2020 was a wild ride - sorry for the insane delay on this. I really appreciate all of the exploration and suggestions. A few others (including Sindre) have since agreed, and we're removing the upscaling by removing the color conversion altogether (save for a few simple methods). Going to go ahead and close this to clean up a bit - thanks again for making me think quite a lot about this 😃 |
Please read this as an observation from a thankful user, instead of a late request for chalk 3
It might be relevant input to your discussion about performance and simplification
While studying
bgAnsi256
as a visual enhancement when available, I noticed thatchalk
also upsamples from lower-level color models to higher-level ANSI color formatsIt looks like a side-effect of the implementation more than an intended feature, because:
color-convert
green
Here is
(new chalk.Instance({level)).green('…')
with^
as placeholder for escape:0
…
1
^[32m…^[39m
2
^[32m…^[39m
3
^[32m…^[39m
This is predictable: it uses lowest-level format and downsamples when needed
ansi
Here is
(new chalk.Instance({level)).ansi(32)('…')
which is a synonym for green:0
…
1
^[32m…^[39m
2
^[38;5;34m…^[39m
3
^[38;2;0;128;0m…^[39m
The visual result is less predictable because on macOS 10.12.6 Terminal:
1
output has color#17a41a
from default theme2
output has color#19ad1d
This is research, because I don’t need to use
ansi
norbgAnsi
ansi256
Here is
(new chalk.Instance({level)).bgAnsi256(194)('…')
0
…
1
^[107m…^[49m
2
^[48;5;194m…^[49m
3
^[48;2;204;255;204m…^[49m
Because the contrasting background colors that I intend to use both downsample to
107
I would usechalk.level >= 2
as condition for foreground color with or without background colorHowever, it would eliminate a test case if levels
2
and3
have the same formatThe text was updated successfully, but these errors were encountered: