-
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
Add support for OSC 4 ; color ; color spec #3163
Changes from all commits
5c7644a
1c3da7e
b22d7f1
b127436
712f0ae
b898e01
d5f4ae5
bc86b78
77ed5ba
6535995
e6917d1
4c6dc45
52b64be
f4a5638
5a74ce2
2804bfa
7d3f537
5c33e40
676aabc
19c14b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* @license MIT | ||
*/ | ||
|
||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions } from 'common/Types'; | ||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IAnsiColorChangeEvent } from 'common/Types'; | ||
import { C0, C1 } from 'common/data/EscapeSequences'; | ||
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets'; | ||
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser'; | ||
|
@@ -250,6 +250,8 @@ export class InputHandler extends Disposable implements IInputHandler { | |
public get onScroll(): IEvent<number> { return this._onScroll.event; } | ||
private _onTitleChange = new EventEmitter<string>(); | ||
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; } | ||
private _onAnsiColorChange = new EventEmitter<IAnsiColorChangeEvent>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats the idea for a custom event here? Shall this be interceptable later on from outside? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure 😊 I modeled it after "title change". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it some more, using the event is the way that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes sounds good that way. I still wonder, if we would need a stricter coupling of the color manager to the input handler, esp. for those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, @slawekzachcial! Thanks for the great PR! Would it be possible to also make |
||
public get onAnsiColorChange(): IEvent<IAnsiColorChangeEvent> { return this._onAnsiColorChange.event; } | ||
|
||
constructor( | ||
private readonly _bufferService: IBufferService, | ||
|
@@ -372,6 +374,7 @@ export class InputHandler extends Disposable implements IInputHandler { | |
this._parser.setOscHandler(2, new OscHandler((data: string) => this.setTitle(data))); | ||
// 3 - set property X in the form "prop=value" | ||
// 4 - Change Color Number | ||
this._parser.setOscHandler(4, new OscHandler((data: string) => this.setAnsiColor(data))); | ||
// 5 - Change Special Color Number | ||
// 6 - Enable/disable Special Color Number c | ||
// 7 - current directory? (not in xterm spec, see https://gitlab.com/gnachman/iterm2/issues/3939) | ||
|
@@ -2711,6 +2714,45 @@ export class InputHandler extends Disposable implements IInputHandler { | |
this._iconName = data; | ||
} | ||
|
||
protected _parseAnsiColorChange(data: string): IAnsiColorChangeEvent | null { | ||
const result: IAnsiColorChangeEvent = { colors: [] }; | ||
// example data: 5;rgb:aa/bb/cc | ||
const regex = /(\d+);rgb:([0-9a-f]{2})\/([0-9a-f]{2})\/([0-9a-f]{2})/gi; | ||
let match; | ||
|
||
while ((match = regex.exec(data)) !== null) { | ||
result.colors.push({ | ||
colorIndex: parseInt(match[1]), | ||
red: parseInt(match[2], 16), | ||
green: parseInt(match[3], 16), | ||
blue: parseInt(match[4], 16) | ||
}); | ||
} | ||
|
||
if (result.colors.length === 0) { | ||
return null; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* OSC 4; <num> ; <text> ST (set ANSI color <num> to <text>) | ||
* | ||
* @vt: #Y OSC 4 "Set ANSI color" "OSC 4 ; c ; spec BEL" "Change color number `c` to the color specified by `spec`." | ||
* `c` is the color index between 0 and 255. `spec` color format is 'rgb:hh/hh/hh' where `h` are hexadecimal digits. | ||
* There may be multipe c ; spec elements present in the same instruction, e.g. 1;rgb:10/20/30;2;rgb:a0/b0/c0. | ||
*/ | ||
public setAnsiColor(data: string): void { | ||
const event = this._parseAnsiColorChange(data); | ||
if (event) { | ||
this._onAnsiColorChange.fire(event); | ||
} | ||
else { | ||
this._logService.warn(`Expected format <num>;rgb:<rr>/<gg>/<bb> but got data: ${data}`); | ||
} | ||
} | ||
|
||
/** | ||
* ESC E | ||
* C1.NEL | ||
|
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.
Hmm yes, it basically increases the atlas size from 16 * 256 pixmaps to 256 * 256. Not sure thought if it will cause problems in terms of browser limits. This needs some serious testing by someone with more atlas insights than me.
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.
@Tyriar Is it safe to expand the atlas here that way?
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.
Looking at the code it seems like this should be fine, I think the slice is there as previously it was static but it ends up falling back to
DEFAULT_ANSI_COLORS
in ColorManager.