OSC link progress
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType } from 'common/Types';
|
||||
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, IOscLinkData } from 'common/Types';
|
||||
import { C0, C1 } from 'common/data/EscapeSequences';
|
||||
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
|
||||
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
|
||||
@@ -214,8 +214,6 @@ class DECRQSS implements IDcsHandler {
|
||||
* @vt: #N DCS XTSETTCAP "Set Terminfo Data" "DCS + p Pt ST" "Set Terminfo Data."
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The terminal's standard implementation of IInputHandler, this handles all
|
||||
* input from the Parser.
|
||||
@@ -230,6 +228,7 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
private _workCell: CellData = new CellData();
|
||||
private _windowTitle = '';
|
||||
private _iconName = '';
|
||||
private _currentHyperlink?: IOscLinkData;
|
||||
protected _windowTitleStack: string[] = [];
|
||||
protected _iconNameStack: string[] = [];
|
||||
|
||||
@@ -265,6 +264,10 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
public get onTitleChange(): IEvent<string> { return this._onTitleChange.event; }
|
||||
private _onColor = new EventEmitter<IColorEvent>();
|
||||
public get onColor(): IEvent<IColorEvent> { return this._onColor.event; }
|
||||
private _onStartHyperlink = new EventEmitter<IOscLinkData>();
|
||||
public get onStartHyperlink(): IEvent<IOscLinkData> { return this._onStartHyperlink.event; }
|
||||
private _onFinishHyperlink = new EventEmitter<void>();
|
||||
public get onFinishHyperlink(): IEvent<void> { return this._onFinishHyperlink.event; }
|
||||
|
||||
private _parseStack: IParseStack = {
|
||||
paused: false,
|
||||
@@ -403,6 +406,8 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
// 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)
|
||||
// 8 - create hyperlink (not in xterm spec, see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)
|
||||
this._parser.registerOscHandler(8, new OscHandler(data => this.setHyperlink(data)));
|
||||
// 10 - Change VT100 text foreground color to Pt.
|
||||
this._parser.registerOscHandler(10, new OscHandler(data => this.setOrReportFgColor(data)));
|
||||
// 11 - Change VT100 text background color to Pt.
|
||||
@@ -2889,6 +2894,66 @@ export class InputHandler extends Disposable implements IInputHandler {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* OSC 8 ; <params> ; <uri> ST - create hyperlink
|
||||
* OSC 8 ; ; ST - finish hyperlink
|
||||
*
|
||||
* Test case:
|
||||
*
|
||||
* ```sh
|
||||
* printf '\e]8;;http://example.com\e\\This is a link\e]8;;\e\\\n'
|
||||
* ```
|
||||
*
|
||||
* @vt: #Y OSC 8 "Create hyperlink" "OSC 8 ; params ; uri BEL" "Create a hyperlink to `uri` using `params`."
|
||||
* `uri` is a hyperlink starting with `http://`, `https://`, `ftp://`, `file://` or `mailto://`. `params` is an
|
||||
* optional list of key=value assignments, separated by the : character. Example: `id=xyz123:foo=bar:baz=quux`.
|
||||
* Currently only the id key is defined. Cells that share the same ID and URI share hover feedback.
|
||||
* Use `OSC 8 ; ; BEL` to finish the current hyperlink.
|
||||
*/
|
||||
public setHyperlink(data: string): boolean {
|
||||
const args = data.split(';');
|
||||
console.log('hyperlink', args);
|
||||
if (args.length < 2) {
|
||||
return false;
|
||||
}
|
||||
if (args[1]) {
|
||||
return this._createHyperlink(args[0], args[1]);
|
||||
}
|
||||
if (args[0]) {
|
||||
return false;
|
||||
}
|
||||
return this._finishHyperlink();
|
||||
}
|
||||
|
||||
private _createHyperlink(params: string, uri: string): boolean {
|
||||
// It's legal to open a new hyperlink without explicitly finishing the previous one
|
||||
if (this._currentHyperlink) {
|
||||
this._finishHyperlink();
|
||||
}
|
||||
const parsedParams = params.split(':');
|
||||
let id: string | undefined;
|
||||
const idParamIndex = parsedParams.findIndex(e => e.startsWith('id='));
|
||||
if (idParamIndex !== -1) {
|
||||
id = parsedParams[idParamIndex].slice(3) || undefined;
|
||||
}
|
||||
this._currentHyperlink = { id, uri };
|
||||
this._curAttrData.extended = this._curAttrData.extended.clone();
|
||||
this._curAttrData.extended.urlId = 1;
|
||||
this._curAttrData.updateExtended();
|
||||
console.log('hasExtendedAttrs?', this._curAttrData.hasExtendedAttrs());
|
||||
this._onStartHyperlink.fire(this._currentHyperlink);
|
||||
return true;
|
||||
}
|
||||
|
||||
private _finishHyperlink(): boolean {
|
||||
this._curAttrData.extended = this._curAttrData.extended.clone();
|
||||
this._curAttrData.extended.urlId = 0;
|
||||
this._curAttrData.updateExtended();
|
||||
this._onFinishHyperlink.fire();
|
||||
this._currentHyperlink = undefined;
|
||||
return true;
|
||||
}
|
||||
|
||||
// special colors - OSC 10 | 11 | 12
|
||||
private _specialColors = [ColorIndex.FOREGROUND, ColorIndex.BACKGROUND, ColorIndex.CURSOR];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user