-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Separate bright and bold #1391
Separate bright and bold #1391
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually also helps address a concern I had with my implementation of #1327, since cached and uncached codepaths currently appear to handle the bold-as-bright logic differently. #1327 (comment)
This is probably going to affect people who relied on this previously, so I'm working on an option that re-enables the old behavior. I will push that as a separate commit to this same branch.
As @Tyriar indicated, we'll probably want to hold off on merging this until that's in place. Let me know if you encounter any issues implementing it. Otherwise, looks good so far.
Thanks for the feedback. One question, if we have a We could also make it two options: Personally leaning most towards |
I don't think that drawing bright text as bold would make sense. Most terminals offer two options:
So we might end up with something like |
I agree, but as far as I know, that is the current behaviour of xterm.js. So if we want to keep backwards compatibility, I think we need an option for that 🤔 |
Hmmm I haven't tested it, but I don't think that the current default behaviour is to draw bright text as bold (I've also not found any code that would point towards that). Imo we should not support an option that draws bright text as bold as it is confusing -- just as you noted. @xtermjs/core Any thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @LinusU, thanks for your contribution.
Let me try to help here to provide a path, so we can get this merged:
- Both default behavior of xterm.js for the end-user and the public API should stay the same, since this is not planned for a major release
- Implement an additional option
drawBoldTextInBrightColors
that will draw bold characters in bright colors and will default tofalsetrue
Afterwards we can plan an API breakage in 4.0 and drop the enableBlog
flag in favor of the fontWeightBold
superset, as @Tyriar proposed in #1239 (comment). This is also close to the proposal of @mofux in #1391 (comment).
Also, I agree with @mofux on not providing an option to draw bright colored text as bold:
we should not support an option that draws bright text as bold as it is confusing
I did a bit of research on how the xterm.js based Hyper draws bold characters and how Terminal.app, iTerm2 approach bold character drawing configuration.
In general it looks like drawing bold characters with bright colors is a universal option and that disabling bold character drawing at all is a thing as well.
Hyper / xterm.js drawing non-bright bold
Terminal.app Bold Option
iTerm2 Bold Options
@parisk The default should be |
Nah, you are right 😅. Fixed it. |
Hmmm, when I test it doesn't seem to happen that way, although I cannot understand why 🤔 😂 To me, this bit of code that I removed: - // Convert the FG color to the bold variant
- if (fg < 8) {
- fg += 8;
- } Made it so that when the bold flag was set, we simply turned ordinary colors into their bright counterpart. Before my patch, when drawing the char atlas, the bright colors would be drawn with the bold font: - // colors 8-15 are bold
- if (colorIndex === 8) {
- ctx.font = getFont(config.fontWeightBold, config);
- } The char atlas only held 2 + 16 colors before. Those 18 colors were:
Since the bright colors were drawn bold in the char atlas, I don't see how you would be able to print bright colors that aren't bold 🤔 That being said, it seems that it's actually possible to print non-bold bright colors, since this is the output on Hyper 2.0.0: Anyhow... this is good news 😄 I'll add an option to print bold colors bright, and then we should be good to go 👍 |
Hahahhaaha 🤦♂️ 🤦♂️ 🤦♂️ const isAscii = code < 256;
// A color is basic if it is one of the standard normal or bold weight
// colors of the characters held in the char atlas. Note that this excludes
// the normal weight _light_ color characters.
const isBasicColor = (colorIndex > 1 && fg < 16) && (fg < 8 || bold);
const isDefaultColor = fg >= 256;
const isDefaultBackground = bg >= 256;
if (this._charAtlas && isAscii && (isBasicColor || isDefaultColor) && isDefaultBackground) {
// draw from atlas
} else {
// draw using ctx
} |
Rebased on master, and added two new commits. The first one fixed so that I'm actually utilizing the char atlas for all 4-bit ANSI colors, bold and non-bold. The second one adds the 2f1ec3b, and fd185a5 with fd185a5, which is same as current master: From my side, this is ready for merging now 🚀 let me know if anything else should be fixed 🙌 |
typings/xterm.d.ts
Outdated
@@ -54,6 +54,11 @@ declare module 'xterm' { | |||
*/ | |||
disableStdin?: boolean; | |||
|
|||
/** | |||
* Wheter to draw bold text in bright colors. The default is true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Wheter/Whether/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👌
This lets term.setOption() work for drawBoldTextInBrightColors.
I added this small commit to fix a minor bug: 9893338 Otherwise, LGTM. I manually tested it, and it seemed to work well for me. I'll merge once Travis finishes. Thanks for your contribution, sorry it took me so long to merge it. |
Travis is failing, but the issue is unrelated. It looks like a recent change to one of our dependencies broke some types. I was able to reproduce them locally in master by wiping and re-installing my node_modules. |
@bgw thank you ❤️ |
Previously all bright colors were always rendered bold, and all bold text was always rendered using the bright colors. This patch separates that so that bold and bright can be controlled individually.
This is probably going to affect people who relied on this previously, so I'm working on an option that re-enables the old behavior. I will push that as a separate commit to this same branch.
Feedback appreciated! 🙌
Fixes vercel/hyper#2836