-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
OSC 4/10/11/12 color handling #3524
Conversation
@Tyriar Figured that terminals properly implementing the OSC color commands support named colors, e.g. you can set there the background with: $> echo -e '\x1b]11;ForestGreen\x07' which would switch to some greenish background. Currently I hesitate to add support for those named colors in xterm.js, because the name definitions are really big for very little benefit. X11 defines 753 color names in I think we should not support named colors at all, as it has little benefit for 8 - 10kB more on the package. First the OSC color commands are a niche use case, second ppl can always use the RGB channel notation to get them. At least we should state this in the sequence docs. Thoughts? Do we care for those 10kB? Edit: An interesting finger exercise might be to reduce the storage needs by finding a perfect hash function for those color names (should get us <4kB). Edit2: Created a PHF version, which takes ~5kB for the data (see commit below). |
I know 10kb is small in related to the current ~320kb of the package but it's already too big imo. At the same point in time we shouldn't be creating addons for everything as that makes consuming the package harder. What about expecting an rgb.json to be served from the module directory or something. So we would only request it when a named color is encountered, then using the async handler infrastructure request the file from the directory. We may need an option to customize the directory, for example when using ASAR. Thoughts? |
Yes I second your concern regarding the overall package size. I am not sure by what changes the major shifts happened, thats what I see when asking CDNs for various versions:
Ofc big part of the deal are tech extensions, that are rather code expensive, like the whole canvas renderer, the reflow logic is a big block of code and also the parser/buffer rewrites created several code modules, that did not exist before. But is a 6 times bigger package justified by that functionality? I'd say yes, still 6 times is scary, esp. when considering the fact, that we are still lacking several cores features (like the PR here).
Yes I think we need to solve the "foreign data problem" for xterm.js in a uniform way, as things like proper unicode v13/14 handling with grapheme support alone would pull several 10kB of "blob" data, that are not easy/nice to integrate in the normal code units. The way it is done currently for wcwidth with its big table inline in the code is not very size friendly. So I have no clear answer to that yet. Maybe we can learn from others, how they deal with blob data. |
Wouldn't a dynamic import (e.g. https://webpack.js.org/guides/code-splitting/#dynamic-imports |
I'm not sure how well that works with other bundlers (Rollup etc.), and even with Webpack, that takes away the user's control over the chunk name (which is set through a magic comment inside the IMHO it would be much more flexible to just add a field/method for the user to set the color data and then they can decide whether to |
@mofux I think for that we have to switch to ESM first, as in CommonJS top level awaits are not allowed? But switching to full ESM removes support for The whole story behind CommonJS vs ESM is kinda frustrating. I tried mixed CJS/ESM package support with Edit:
You mean like a compile/bundling switch (because that would have to be eval'ed at building time)? Thats a thing I kinda miss around TS - I dont see a nice way to "macro" things or create compile time settings (thats why the |
To not stall this PR too much creating another eternity PR, I suggest we just dump the named color support for now, until we have solved the "additional data loading issue" (created #3530 for that). While my PHF solution works, it still adds 5kB to the package size for no good reason, thus gonna remove it. |
@Tyriar Done with this PR. I postponed several aspects and created follow-up issues, see the PR todo list at the top. |
@Tyriar Now done for real. 😸 |
@@ -197,6 +206,7 @@ export namespace rgba { | |||
return (fgR << 24 | fgG << 16 | fgB << 8 | 0xFF) >>> 0; | |||
} | |||
|
|||
// FIXME: Move this to channels NS? |
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.
The namespace was meant to represent the source, so rgba.toChannels
= rgba format to channels format
src/browser/Color.ts
Outdated
@@ -4,6 +4,9 @@ | |||
*/ | |||
|
|||
import { IColor } from 'browser/Types'; | |||
import { IColorRGB } from 'common/Types'; | |||
|
|||
// FIXME: Move Color.ts lib to common? |
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.
Color.ts lives in browser historically as it's only required when a renderer is active, things have changed a little with this PR where InputHandler knows more about color. Sounds like a good change if XParseColor
ends up using these utils, but if not it would be best to keep in browser as then it's not included unnecessarily in xterm-headless
.
Shall implement OSC10/11 color handling, and extend OSC 4 by the query notation.
Fixes #3487. Also closes #3549.
Beside OSC 4/10/11 there are more color commands, but I am not quite sure yet, how they are supposed to work (esp. OSC 5 with its "special colors" is a mystery to me). Not sure if the PR will deal with those as well in the end, they have no priority on my side. Most of OSC 12 -19 is def. out of scope for xterm.js.
TODO:
support X11 color names(removed, to be done when investigate ways to load additional data on demand #3530 got fixed)lsix
apply color change immediatelypostponed: canvas renderer CharAtlas life cycling/refreshing issue #3548