You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before that PR, all colors had an implicit 'bold,' and all colors in the Windows API had an implicit FOREGROUND_INTENSITY.
I've pushed an update to make colors not bold by default (the ;1m), which kind of defeated the purpose of .bold
This makes sense to do from the perspective of ANSI escape sequences, but it complicates making setColor work similarly when the Config is .windows_api. In the Windows API, there's no builtin way to persist something like .bold, so attempting to use .bold and then set a color does not have the intended effect--the 'bold' is always lost after setting the color.
About bold
Historically, 'bold' has been implemented as making the text a brighter color rather than actually bold. From Wikipedia:
Quite a few terminals implemented "bold" (SGR code 1) as a brighter color rather than a different font, thus providing 8 additional foreground colors.
This is still an option in e.g. Gnome terminal ('Show bold text in bright colors'), and is the default behavior in Windows Terminal. This doesn't really affect the problem, but it's worth noting when thinking about potential solutions.
A visualization
This is cmd.exe in Windows Terminal with the default font/settings:
(note: dim is not expected to match, there's no 'dim' equivalent in the Windows Console API)
Note that with modified settings to use a font that supports bold text and to render bold text as bold only (instead of the default setting of rendering bold text as 'bright colors'), the difference is less impactful visually but the difference can still be seen:
Go back to every-color-is-bold/every-color-is-intense. This gives us an easy path to cross-API conformity but makes the setColor API less useful/flexible than it could be.
Modify the setColor API to take a mutable *Config, add something like intensity: enum { normal, bold, dim } to Config.WindowsContext and apply/remove FOREGROUND_INTENSITY accordingly during each setColor call. This would keep the usefulness of the API but add a wrinkle to Config where the same instance would need to be re-used consistently (and without other SetConsoleTextAttribute calls in between setColor calls) in order to ensure that the intensity state would remain correct.
Add a GetConsoleTextAttribute call in setColor, check for FOREGROUND_INTENSITY and persist it if it's present. This would provide some support for persistent bold but it may not always behave in the intended/expected way from the perspective of the user, and would add the overhead of an extra GetConsoleTextAttribute call.
Keep it as is and accept the incongruous behavior between the APIs. Ideally this would be supplemented by windows: detect ANSI support in more terminals #15282 getting merged which would make .escape_codes get used on Windows in more situations (e.g. in Windows Terminal).
I personally see some merit to all of the potential solutions, and I may be missing some potential solutions.
This is something of a follow-up to #15806.
Before that PR, all colors had an implicit 'bold,' and all colors in the Windows API had an implicit
FOREGROUND_INTENSITY.This makes sense to do from the perspective of ANSI escape sequences, but it complicates making
setColorwork similarly when theConfigis.windows_api. In the Windows API, there's no builtin way to persist something like.bold, so attempting to use.boldand then set a color does not have the intended effect--the 'bold' is always lost after setting the color.About bold
Historically, 'bold' has been implemented as making the text a brighter color rather than actually bold. From Wikipedia:
This is still an option in e.g. Gnome terminal ('Show bold text in bright colors'), and is the default behavior in Windows Terminal. This doesn't really affect the problem, but it's worth noting when thinking about potential solutions.
A visualization
This is
cmd.exein Windows Terminal with the default font/settings:(note: dim is not expected to match, there's no 'dim' equivalent in the Windows Console API)
Note that with modified settings to use a font that supports bold text and to render bold text as bold only (instead of the default setting of rendering bold text as 'bright colors'), the difference is less impactful visually but the difference can still be seen:
Output with modified settings
Code used to generate this output
Potential solutions
setColorAPI less useful/flexible than it could be.setColorAPI to take a mutable*Config, add something likeintensity: enum { normal, bold, dim }toConfig.WindowsContextand apply/removeFOREGROUND_INTENSITYaccordingly during eachsetColorcall. This would keep the usefulness of the API but add a wrinkle toConfigwhere the same instance would need to be re-used consistently (and without otherSetConsoleTextAttributecalls in betweensetColorcalls) in order to ensure that theintensitystate would remain correct.GetConsoleTextAttributecall insetColor, check forFOREGROUND_INTENSITYand persist it if it's present. This would provide some support for persistentboldbut it may not always behave in the intended/expected way from the perspective of the user, and would add the overhead of an extraGetConsoleTextAttributecall..escape_codesget used on Windows in more situations (e.g. in Windows Terminal).I personally see some merit to all of the potential solutions, and I may be missing some potential solutions.
cc @linusg if you'd like to weigh in