Skip to content

Commit 874e767

Browse files
authored
Merge pull request #5840 from xtermjs/fix_apc
changes in APC handling
2 parents 605a7c6 + 73d87b2 commit 874e767

19 files changed

Lines changed: 1081 additions & 472 deletions

addons/addon-image/src/ImageAddon.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,47 @@ import { SixelImageStorage } from './SixelImageStorage';
1616
import { IIPImageStorage } from './IIPImageStorage';
1717
import { ITerminalExt, IImageAddonOptions, IResetHandler } from './Types';
1818

19+
20+
/**
21+
* Document VT features provided by this addon.
22+
*
23+
* @vt: #E[Supported via @xterm/addon-image.] DCS SIXEL "SIXEL Graphics" "DCS Ps ; Ps ; Ps ; q Pt ST" "Draw SIXEL image."
24+
*
25+
* Sixel support is provided by the addon @xterm/addon-image with these limitations:
26+
* - immediate coloring (no shared palette, allows high color settings of `img2sixel`)
27+
* - max. palette size of 4096 colors
28+
* - max. pixel width of 16K
29+
* - max. 25 MB per sixel sequence
30+
* - VT340 cursor positioning (begin of last sixel data row)
31+
*
32+
* See [addon readme](https://github.com/xtermjs/xterm.js/tree/master/addons/addon-image) for more details.
33+
*
34+
*
35+
* @vt: #E[Supported via @xterm/addon-image.] OSC 1337 "iTerm2 Commands" "OSC 1337 ; Pt BEL" "Custom iTerm2 commands."
36+
*
37+
* Only the inline image protocol (IIP) is supported by the addon @xterm/addon-image with
38+
* the following limitations:
39+
* - sequence:
40+
* - format: `OSC 1337 ; File=inline=1 ; size=<unencoded size> ; ... : <base64 payload> BEL`
41+
* - size param must be set and payload may not exceed CEIL(size * 4 / 3)
42+
* - strict base64 handling as of RFC4648 §4 (standard alphabet, optional padding,
43+
* no separator bytes allowed)
44+
* - supported params: size, name, width, height, preserveAspectRatio
45+
* - image formats: PNG, JPEG and GIF
46+
* - no animation support (renders first image of a GIF)
47+
* - no multipart support
48+
* - VT340 cursor positioning (begin of last sixel data row)
49+
*
50+
* See [addon readme](https://github.com/xtermjs/xterm.js/tree/master/addons/addon-image)
51+
* and [iTerm2 IIP docs](https://iterm2.com/documentation-images.html) for more details.
52+
*
53+
*
54+
* @vt: #E[Supported via @xterm/addon-image.] APC KITTY_GRAPHICS "Kitty Graphics" "APC G Pt ST" "Kitty Graphics Protocol."
55+
*
56+
* Kitty graphics support is provided by the addon @xterm/addon-image.
57+
* Note that while basic image output already works, this is still work in progress.
58+
*/
59+
1960
// default values of addon ctor options
2061
const DEFAULT_OPTIONS: IImageAddonOptions = {
2162
enableSizeReports: true,
@@ -166,7 +207,7 @@ export class ImageAddon implements ITerminalAddon, IImageApi {
166207
this._disposeLater(
167208
kittyStorage,
168209
kittyHandler,
169-
terminal._core._inputHandler._parser.registerApcHandler(0x47, kittyHandler)
210+
terminal._core._inputHandler._parser.registerApcHandler({ final: 'G' }, kittyHandler)
170211
);
171212
}
172213
}

bin/extract_vtfeatures.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ xterm.js version: {{version}}
5757
{{#CSI.length}}
5858
- [CSI](#csi)
5959
{{/CSI.length}}
60+
{{#APC.length}}
61+
- [APC](#apc)
62+
{{/APC.length}}
6063
{{#DCS.length}}
6164
- [DCS](#dcs)
6265
{{/DCS.length}}
@@ -80,8 +83,9 @@ This document lists xterm.js' support of terminal sequences. The sequences are g
8083
- CSI - Control Sequence Introducer: sequence starting with \`ESC [\` (7bit) or CSI (\`\\x9B\`, 8bit)
8184
- DCS - Device Control String: sequence starting with \`ESC P\` (7bit) or DCS (\`\\x90\`, 8bit)
8285
- OSC - Operating System Command: sequence starting with \`ESC ]\` (7bit) or OSC (\`\\x9D\`, 8bit)
86+
- APC - Application Program Command: sequence starting with \`ESC _\` (7bit) or OSC (\`\\x9F\`, 8bit)
8387
84-
Application Program Command (APC), Privacy Message (PM) and Start of String (SOS) are recognized but not supported,
88+
Privacy Message (PM) and Start of String (SOS) are recognized but not supported,
8589
any sequence of these types will be silently ignored. They are also not hookable by the API.
8690
8791
Note that the list only marks sequences implemented in xterm.js' core codebase as supported. Missing sequences are either
@@ -178,6 +182,33 @@ To denote the sequences the tables use the same abbreviations as xterm does:
178182
{{/CSI.length}}
179183
180184
185+
{{#APC.length}}
186+
## APC
187+
188+
| Mnemonic | Name | Sequence | Short Description | Support |
189+
| -------- | ---- | -------- | ----------------- | ------- |
190+
{{#APC}}
191+
| {{mnemonic}} | {{name}} | \`{{sequence}}\` | {{{shortDescription}}} {{#longDescription.length}}_[more](#{{longTarget}}){: .link-details}_{{/longDescription.length}} | {{{status}}} |
192+
{{/APC}}
193+
194+
{{#APC.hasLongDescriptions}}
195+
{{#APC}}
196+
{{#longDescription.length}}
197+
<section class="sequence-details">
198+
199+
### {{name}}
200+
{{#longDescription}}
201+
{{{.}}}
202+
{{/longDescription}}
203+
204+
</section>
205+
{{/longDescription.length}}
206+
{{/APC}}
207+
{{/APC.hasLongDescriptions}}
208+
209+
{{/APC.length}}
210+
211+
181212
{{#DCS.length}}
182213
## DCS
183214

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"benchmark-baseline": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json --baseline out-test/benchmark/*benchmark.js",
6767
"benchmark-eval": "NODE_PATH=./out xterm-benchmark -r 5 -c test/benchmark/benchmark.json --eval out-test/benchmark/*benchmark.js",
6868
"clean": "rm -rf lib out addons/*/lib addons/*/out",
69-
"vtfeatures": "node bin/extract_vtfeatures.js src/**/*.ts src/*.ts",
69+
"vtfeatures": "node bin/extract_vtfeatures.js src/*/*.ts src/*/*/*.ts src/*.ts addons/**/src/*.ts",
7070
"prepackage": "npm run build",
7171
"package": "webpack",
7272
"postpackage": "npm run esbuild-package",

src/browser/TestUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class MockTerminal implements ITerminal {
107107
public registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
108108
throw new Error('Method not implemented.');
109109
}
110-
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
110+
public registerApcHandler(id: IFunctionIdentifier, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
111111
throw new Error('Method not implemented.');
112112
}
113113
public registerLinkProvider(linkProvider: ILinkProvider): IDisposable {

src/common/CoreTerminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
243243
}
244244

245245
/** Add handler for APC escape sequence. See xterm.d.ts for details. */
246-
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
247-
return this._inputHandler.registerApcHandler(ident, callback);
246+
public registerApcHandler(id: IFunctionIdentifier, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
247+
return this._inputHandler.registerApcHandler(id, callback);
248248
}
249249

250250
protected _setup(): void {

src/common/InputHandler.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,9 @@ import { XTERM_VERSION } from 'common/Version';
3030
*/
3131
const GLEVEL: { [key: string]: number } = { '(': 0, ')': 1, '*': 2, '+': 3, '-': 1, '.': 2 };
3232

33-
/**
34-
* VT commands done by the parser - FIXME: move this to the parser?
35-
*/
36-
// @vt: #Y ESC CSI "Control Sequence Introducer" "ESC [" "Start of a CSI sequence."
37-
// @vt: #Y ESC OSC "Operating System Command" "ESC ]" "Start of an OSC sequence."
38-
// @vt: #Y ESC DCS "Device Control String" "ESC P" "Start of a DCS sequence."
39-
// @vt: #Y ESC ST "String Terminator" "ESC \" "Terminator used for string type sequences."
40-
// @vt: #Y ESC PM "Privacy Message" "ESC ^" "Start of a privacy message."
41-
// @vt: #Y ESC APC "Application Program Command" "ESC _" "Start of an APC sequence."
42-
// @vt: #Y C1 CSI "Control Sequence Introducer" "\x9B" "Start of a CSI sequence."
43-
// @vt: #Y C1 OSC "Operating System Command" "\x9D" "Start of an OSC sequence."
44-
// @vt: #Y C1 DCS "Device Control String" "\x90" "Start of a DCS sequence."
45-
// @vt: #Y C1 ST "String Terminator" "\x9C" "Terminator used for string type sequences."
46-
// @vt: #Y C1 PM "Privacy Message" "\x9E" "Start of a privacy message."
47-
// @vt: #Y C1 APC "Application Program Command" "\x9F" "Start of an APC sequence."
48-
// @vt: #Y C0 NUL "Null" "\0, \x00" "NUL is ignored."
49-
// @vt: #Y C0 ESC "Escape" "\e, \x1B" "Start of a sequence. Cancels any other sequence."
50-
5133
/**
5234
* Document xterm VT features here that are currently unsupported
5335
*/
54-
// @vt: #E[Supported via @xterm/addon-image.] DCS SIXEL "SIXEL Graphics" "DCS Ps ; Ps ; Ps ; q Pt ST" "Draw SIXEL image."
5536
// @vt: #N DCS DECUDK "User Defined Keys" "DCS Ps ; Ps \| Pt ST" "Definitions for user-defined keys."
5637
// @vt: #N DCS XTGETTCAP "Request Terminfo String" "DCS + q Pt ST" "Request Terminfo String."
5738
// @vt: #N DCS XTSETTCAP "Set Terminfo Data" "DCS + p Pt ST" "Set Terminfo Data."
@@ -211,6 +192,9 @@ export class InputHandler extends Disposable implements IInputHandler {
211192
}
212193
this._logService.debug('Unknown DCS code: ', { identifier: this._parser.identToString(ident), action, payload });
213194
});
195+
this._parser.setApcHandlerFallback((ident, action, payload) => {
196+
this._logService.debug('Unknown APC code: ', { identifier: this._parser.identToString(ident), action, payload });
197+
});
214198

215199
/**
216200
* print handler
@@ -729,8 +713,8 @@ export class InputHandler extends Disposable implements IInputHandler {
729713
/**
730714
* Forward registerApcHandler from parser.
731715
*/
732-
public registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
733-
return this._parser.registerApcHandler(ident, new ApcHandler(callback));
716+
public registerApcHandler(id: IFunctionIdentifier, callback: (data: string) => boolean | Promise<boolean>): IDisposable {
717+
return this._parser.registerApcHandler(id, new ApcHandler(callback));
734718
}
735719

736720
/**

src/common/Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface ICoreTerminal {
2222
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
2323
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
2424
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
25-
registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
25+
registerApcHandler(id: IFunctionIdentifier, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
2626
}
2727

2828
export interface IDisposable {
@@ -476,7 +476,7 @@ export interface IInputHandler {
476476
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
477477
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
478478
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
479-
registerApcHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
479+
registerApcHandler(id: IFunctionIdentifier, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
480480

481481
/** C0 BEL */ bell(): boolean;
482482
/** C0 LF */ lineFeed(): boolean;

0 commit comments

Comments
 (0)