Skip to content

Commit ca46b8c

Browse files
authored
Merge branch 'master' into clear_texture_atlas
2 parents 189ff56 + ef6516e commit ca46b8c

7 files changed

Lines changed: 86 additions & 36 deletions

File tree

addons/xterm-addon-serialize/src/SerializeAddon.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function equalFlags(cell1: IBufferCell, cell2: IBufferCell): boolean {
7272
&& cell1.isBlink() === cell2.isBlink()
7373
&& cell1.isInvisible() === cell2.isInvisible()
7474
&& cell1.isItalic() === cell2.isItalic()
75-
&& cell1.isDim() === cell2.isDim();
75+
&& cell1.isDim() === cell2.isDim()
76+
&& cell1.isStrikethrough() === cell2.isStrikethrough();
7677
}
7778

7879
class StringSerializeHandler extends BaseSerializeHandler {
@@ -160,7 +161,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
160161
if (
161162
// you must output character to cause overflow, control sequence can't do this
162163
nextRowFirstChar.getChars() &&
163-
isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0
164+
isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0
164165
) {
165166
if (
166167
// the last character can't be null,
@@ -259,6 +260,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
259260
if (cell.isInvisible() !== oldCell.isInvisible()) { sgrSeq.push(cell.isInvisible() ? 8 : 28); }
260261
if (cell.isItalic() !== oldCell.isItalic()) { sgrSeq.push(cell.isItalic() ? 3 : 23); }
261262
if (cell.isDim() !== oldCell.isDim()) { sgrSeq.push(cell.isDim() ? 2 : 22); }
263+
if (cell.isStrikethrough() !== oldCell.isStrikethrough()) { sgrSeq.push(cell.isStrikethrough() ? 9 : 29); }
262264
}
263265
}
264266
}
@@ -433,26 +435,37 @@ export class SerializeAddon implements ITerminalAddon {
433435
return content;
434436
}
435437

436-
public serialize(scrollback?: number): string {
438+
public serialize(options?: ISerializeOptions): string {
437439
// TODO: Add combinedData support
438440
if (!this._terminal) {
439441
throw new Error('Cannot use addon until it has been loaded');
440442
}
441443

442444
// Normal buffer
443-
let content = this._serializeBuffer(this._terminal, this._terminal.buffer.normal, scrollback);
445+
let content = this._serializeBuffer(this._terminal, this._terminal.buffer.normal, options?.scrollback);
444446

445447
// Alternate buffer
446-
if (this._terminal.buffer.active.type === 'alternate') {
447-
const alternativeScreenContent = this._serializeBuffer(this._terminal, this._terminal.buffer.alternate, undefined);
448-
content += `\u001b[?1049h\u001b[H${alternativeScreenContent}`;
448+
if (!options?.excludeAltBuffer) {
449+
if (this._terminal.buffer.active.type === 'alternate') {
450+
const alternativeScreenContent = this._serializeBuffer(this._terminal, this._terminal.buffer.alternate, undefined);
451+
content += `\u001b[?1049h\u001b[H${alternativeScreenContent}`;
452+
}
449453
}
450454

451455
// Modes
452-
content += this._serializeModes(this._terminal);
456+
if (!options?.excludeModes) {
457+
content += this._serializeModes(this._terminal);
458+
}
453459

454460
return content;
455461
}
456462

457463
public dispose(): void { }
458464
}
465+
466+
467+
interface ISerializeOptions {
468+
scrollback?: number;
469+
excludeModes?: boolean;
470+
excludeAltBuffer?: boolean;
471+
}

addons/xterm-addon-serialize/test/SerializeAddon.api.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,27 @@ describe('SerializeAddon', () => {
146146
const cols = 10;
147147
const lines = newArray<string>((index: number) => digitsString(cols, index), rows);
148148
await writeSync(page, lines.join('\\r\\n'));
149-
assert.equal(await page.evaluate(`serializeAddon.serialize(${halfScrollback});`), lines.slice(halfScrollback, rows).join('\r\n'));
149+
assert.equal(await page.evaluate(`serializeAddon.serialize({ scrollback: ${halfScrollback} });`), lines.slice(halfScrollback, rows).join('\r\n'));
150150
});
151151

152152
it('serialize 0 rows of scrollback', async function(): Promise<any> {
153153
const rows = 20;
154154
const cols = 10;
155155
const lines = newArray<string>((index: number) => digitsString(cols, index), rows);
156156
await writeSync(page, lines.join('\\r\\n'));
157-
assert.equal(await page.evaluate(`serializeAddon.serialize(0);`), lines.slice(rows - 10, rows).join('\r\n'));
157+
assert.equal(await page.evaluate(`serializeAddon.serialize({ scrollback: 0 });`), lines.slice(rows - 10, rows).join('\r\n'));
158+
});
159+
160+
it('serialize exclude modes', async () => {
161+
await writeSync(page, 'before\\x1b[?1hafter');
162+
assert.equal(await page.evaluate(`serializeAddon.serialize();`), 'beforeafter\x1b[?1h');
163+
assert.equal(await page.evaluate(`serializeAddon.serialize({ excludeModes: true });`), 'beforeafter');
164+
});
165+
166+
it('serialize exclude alt buffer', async () => {
167+
await writeSync(page, 'normal\\x1b[?1049h\\x1b[Halt');
168+
assert.equal(await page.evaluate(`serializeAddon.serialize();`), 'normal\x1b[?1049h\x1b[Halt');
169+
assert.equal(await page.evaluate(`serializeAddon.serialize({ excludeAltBuffer: true });`), 'normal');
158170
});
159171

160172
it('serialize all rows of content with color16', async function(): Promise<any> {
@@ -184,11 +196,13 @@ describe('SerializeAddon', () => {
184196
sgr(UNDERLINED) + line,
185197
sgr(BLINK) + line,
186198
sgr(INVISIBLE) + line,
199+
sgr(STRIKETHROUGH) + line,
187200
sgr(NO_INVERSE) + line,
188201
sgr(NO_BOLD) + line,
189202
sgr(NO_UNDERLINED) + line,
190203
sgr(NO_BLINK) + line,
191-
sgr(NO_INVISIBLE) + line
204+
sgr(NO_INVISIBLE) + line,
205+
sgr(NO_STRIKETHROUGH) + line
192206
];
193207
const rows = lines.length;
194208
await writeSync(page, lines.join('\\r\\n'));
@@ -579,20 +593,20 @@ const BG_RGB_GREEN = '48;2;0;255;0';
579593
const BG_RGB_YELLOW = '48;2;255;255;0';
580594
const BG_RESET = '49';
581595

582-
const INVERSE = '7';
583596
const BOLD = '1';
597+
const DIM = '2';
598+
const ITALIC = '3';
584599
const UNDERLINED = '4';
585600
const BLINK = '5';
601+
const INVERSE = '7';
586602
const INVISIBLE = '8';
603+
const STRIKETHROUGH = '9';
587604

588-
const NO_INVERSE = '27';
589605
const NO_BOLD = '22';
606+
const NO_DIM = '22';
607+
const NO_ITALIC = '23';
590608
const NO_UNDERLINED = '24';
591609
const NO_BLINK = '25';
610+
const NO_INVERSE = '27';
592611
const NO_INVISIBLE = '28';
593-
594-
const ITALIC = '3';
595-
const DIM = '2';
596-
597-
const NO_ITALIC = '23';
598-
const NO_DIM = '22';
612+
const NO_STRIKETHROUGH = '29';

addons/xterm-addon-serialize/typings/xterm-addon-serialize.d.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { Terminal, ITerminalAddon } from 'xterm';
77

88
declare module 'xterm-addon-serialize' {
99
/**
10-
* An xterm.js addon that enables web links.
10+
* An xterm.js addon that enables serialization of terminal contents.
1111
*/
1212
export class SerializeAddon implements ITerminalAddon {
1313

1414
constructor();
1515

1616
/**
17-
* Activates the addon
17+
* Activates the addon.
1818
* @param terminal The terminal the addon is being loaded in.
1919
*/
2020
public activate(terminal: Terminal): void;
@@ -24,15 +24,32 @@ declare module 'xterm-addon-serialize' {
2424
* the state. The cursor will also be positioned to the correct cell. When restoring a terminal
2525
* it is best to do before `Terminal.open` is called to avoid wasting CPU cycles rendering
2626
* incomplete frames.
27-
* @param scrollback The number of rows in scrollback buffer to serialize, starting from the
28-
* bottom of the scrollback buffer. This defaults to the all available rows in the scrollback
29-
* buffer.
27+
* @param options Custom options to allow control over what gets serialized.
3028
*/
31-
public serialize(scrollback?: number): string;
29+
public serialize(options?: ISerializeOptions): string;
3230

3331
/**
3432
* Disposes the addon.
3533
*/
3634
public dispose(): void;
3735
}
36+
37+
export interface ISerializeOptions {
38+
/**
39+
* The number of rows in the scrollback buffer to serialize, starting from the bottom of the
40+
* scrollback buffer. When not specified, all available rows in the scrollback buffer will be
41+
* serialized.
42+
*/
43+
scrollback?: number;
44+
45+
/**
46+
* Whether to exclude the terminal modes from the serialization. False by default.
47+
*/
48+
excludeModes?: boolean;
49+
50+
/**
51+
* Whether to exclude the alt buffer from the serialization. False by default.
52+
*/
53+
excludeAltBuffer?: boolean;
54+
}
3855
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "xterm",
33
"description": "Full xterm terminal, in your browser",
4-
"version": "4.14.0",
4+
"version": "4.14.1",
55
"main": "lib/xterm.js",
66
"style": "css/xterm.css",
77
"types": "typings/xterm.d.ts",

src/browser/Terminal.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,9 @@ export class Terminal extends CoreTerminal implements ITerminal {
11801180
* @param ev The input event to be handled.
11811181
*/
11821182
protected _inputEvent(ev: InputEvent): boolean {
1183-
if (ev.data && ev.inputType === 'insertText') {
1183+
// Only support emoji IMEs when screen reader mode is disabled as the event must bubble up to
1184+
// support reading out character input which can doubling up input characters
1185+
if (ev.data && ev.inputType === 'insertText' && !this.optionsService.options.screenReaderMode) {
11841186
if (this._keyPressHandled) {
11851187
return false;
11861188
}

typings/xterm-headless.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ declare module 'xterm-headless' {
8484
* line height and letter spacing is used. Note that this doesn't work with the DOM renderer
8585
* which renders all characters using the font. The default is true.
8686
*/
87-
customGlyphs?: boolean;
87+
customGlyphs?: boolean;
8888

8989
/**
9090
* Whether input should be disabled.
@@ -1085,18 +1085,20 @@ declare module 'xterm-headless' {
10851085

10861086
/** Whether the cell has the bold attribute (CSI 1 m). */
10871087
isBold(): number;
1088-
/** Whether the cell has the inverse attribute (CSI 3 m). */
1088+
/** Whether the cell has the italic attribute (CSI 3 m). */
10891089
isItalic(): number;
1090-
/** Whether the cell has the inverse attribute (CSI 2 m). */
1090+
/** Whether the cell has the dim attribute (CSI 2 m). */
10911091
isDim(): number;
10921092
/** Whether the cell has the underline attribute (CSI 4 m). */
10931093
isUnderline(): number;
1094-
/** Whether the cell has the inverse attribute (CSI 5 m). */
1094+
/** Whether the cell has the blink attribute (CSI 5 m). */
10951095
isBlink(): number;
10961096
/** Whether the cell has the inverse attribute (CSI 7 m). */
10971097
isInverse(): number;
1098-
/** Whether the cell has the inverse attribute (CSI 8 m). */
1098+
/** Whether the cell has the invisible attribute (CSI 8 m). */
10991099
isInvisible(): number;
1100+
/** Whether the cell has the strikethrough attribute (CSI 9 m). */
1101+
isStrikethrough(): number;
11001102

11011103
/** Whether the cell is using the RGB foreground color mode. */
11021104
isFgRGB(): boolean;

typings/xterm.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,18 +1452,20 @@ declare module 'xterm' {
14521452

14531453
/** Whether the cell has the bold attribute (CSI 1 m). */
14541454
isBold(): number;
1455-
/** Whether the cell has the inverse attribute (CSI 3 m). */
1455+
/** Whether the cell has the italic attribute (CSI 3 m). */
14561456
isItalic(): number;
1457-
/** Whether the cell has the inverse attribute (CSI 2 m). */
1457+
/** Whether the cell has the dim attribute (CSI 2 m). */
14581458
isDim(): number;
14591459
/** Whether the cell has the underline attribute (CSI 4 m). */
14601460
isUnderline(): number;
1461-
/** Whether the cell has the inverse attribute (CSI 5 m). */
1461+
/** Whether the cell has the blink attribute (CSI 5 m). */
14621462
isBlink(): number;
14631463
/** Whether the cell has the inverse attribute (CSI 7 m). */
14641464
isInverse(): number;
1465-
/** Whether the cell has the inverse attribute (CSI 8 m). */
1465+
/** Whether the cell has the invisible attribute (CSI 8 m). */
14661466
isInvisible(): number;
1467+
/** Whether the cell has the strikethrough attribute (CSI 9 m). */
1468+
isStrikethrough(): number;
14671469

14681470
/** Whether the cell is using the RGB foreground color mode. */
14691471
isFgRGB(): boolean;

0 commit comments

Comments
 (0)