Merge branch 'master' into clear_texture_atlas

This commit is contained in:
Daniel Imms
2021-09-22 06:39:53 -07:00
committed by GitHub
7 changed files with 86 additions and 36 deletions
@@ -72,7 +72,8 @@ function equalFlags(cell1: IBufferCell, cell2: IBufferCell): boolean {
&& cell1.isBlink() === cell2.isBlink() && cell1.isBlink() === cell2.isBlink()
&& cell1.isInvisible() === cell2.isInvisible() && cell1.isInvisible() === cell2.isInvisible()
&& cell1.isItalic() === cell2.isItalic() && cell1.isItalic() === cell2.isItalic()
&& cell1.isDim() === cell2.isDim(); && cell1.isDim() === cell2.isDim()
&& cell1.isStrikethrough() === cell2.isStrikethrough();
} }
class StringSerializeHandler extends BaseSerializeHandler { class StringSerializeHandler extends BaseSerializeHandler {
@@ -160,7 +161,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
if ( if (
// you must output character to cause overflow, control sequence can't do this // you must output character to cause overflow, control sequence can't do this
nextRowFirstChar.getChars() && nextRowFirstChar.getChars() &&
isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0 isNextRowFirstCharDoubleWidth ? this._nullCellCount <= 1 : this._nullCellCount <= 0
) { ) {
if ( if (
// the last character can't be null, // the last character can't be null,
@@ -259,6 +260,7 @@ class StringSerializeHandler extends BaseSerializeHandler {
if (cell.isInvisible() !== oldCell.isInvisible()) { sgrSeq.push(cell.isInvisible() ? 8 : 28); } if (cell.isInvisible() !== oldCell.isInvisible()) { sgrSeq.push(cell.isInvisible() ? 8 : 28); }
if (cell.isItalic() !== oldCell.isItalic()) { sgrSeq.push(cell.isItalic() ? 3 : 23); } if (cell.isItalic() !== oldCell.isItalic()) { sgrSeq.push(cell.isItalic() ? 3 : 23); }
if (cell.isDim() !== oldCell.isDim()) { sgrSeq.push(cell.isDim() ? 2 : 22); } if (cell.isDim() !== oldCell.isDim()) { sgrSeq.push(cell.isDim() ? 2 : 22); }
if (cell.isStrikethrough() !== oldCell.isStrikethrough()) { sgrSeq.push(cell.isStrikethrough() ? 9 : 29); }
} }
} }
} }
@@ -433,26 +435,37 @@ export class SerializeAddon implements ITerminalAddon {
return content; return content;
} }
public serialize(scrollback?: number): string { public serialize(options?: ISerializeOptions): string {
// TODO: Add combinedData support // TODO: Add combinedData support
if (!this._terminal) { if (!this._terminal) {
throw new Error('Cannot use addon until it has been loaded'); throw new Error('Cannot use addon until it has been loaded');
} }
// Normal buffer // Normal buffer
let content = this._serializeBuffer(this._terminal, this._terminal.buffer.normal, scrollback); let content = this._serializeBuffer(this._terminal, this._terminal.buffer.normal, options?.scrollback);
// Alternate buffer // Alternate buffer
if (this._terminal.buffer.active.type === 'alternate') { if (!options?.excludeAltBuffer) {
const alternativeScreenContent = this._serializeBuffer(this._terminal, this._terminal.buffer.alternate, undefined); if (this._terminal.buffer.active.type === 'alternate') {
content += `\u001b[?1049h\u001b[H${alternativeScreenContent}`; const alternativeScreenContent = this._serializeBuffer(this._terminal, this._terminal.buffer.alternate, undefined);
content += `\u001b[?1049h\u001b[H${alternativeScreenContent}`;
}
} }
// Modes // Modes
content += this._serializeModes(this._terminal); if (!options?.excludeModes) {
content += this._serializeModes(this._terminal);
}
return content; return content;
} }
public dispose(): void { } public dispose(): void { }
} }
interface ISerializeOptions {
scrollback?: number;
excludeModes?: boolean;
excludeAltBuffer?: boolean;
}
@@ -146,7 +146,7 @@ describe('SerializeAddon', () => {
const cols = 10; const cols = 10;
const lines = newArray<string>((index: number) => digitsString(cols, index), rows); const lines = newArray<string>((index: number) => digitsString(cols, index), rows);
await writeSync(page, lines.join('\\r\\n')); await writeSync(page, lines.join('\\r\\n'));
assert.equal(await page.evaluate(`serializeAddon.serialize(${halfScrollback});`), lines.slice(halfScrollback, rows).join('\r\n')); assert.equal(await page.evaluate(`serializeAddon.serialize({ scrollback: ${halfScrollback} });`), lines.slice(halfScrollback, rows).join('\r\n'));
}); });
it('serialize 0 rows of scrollback', async function(): Promise<any> { it('serialize 0 rows of scrollback', async function(): Promise<any> {
@@ -154,7 +154,19 @@ describe('SerializeAddon', () => {
const cols = 10; const cols = 10;
const lines = newArray<string>((index: number) => digitsString(cols, index), rows); const lines = newArray<string>((index: number) => digitsString(cols, index), rows);
await writeSync(page, lines.join('\\r\\n')); await writeSync(page, lines.join('\\r\\n'));
assert.equal(await page.evaluate(`serializeAddon.serialize(0);`), lines.slice(rows - 10, rows).join('\r\n')); assert.equal(await page.evaluate(`serializeAddon.serialize({ scrollback: 0 });`), lines.slice(rows - 10, rows).join('\r\n'));
});
it('serialize exclude modes', async () => {
await writeSync(page, 'before\\x1b[?1hafter');
assert.equal(await page.evaluate(`serializeAddon.serialize();`), 'beforeafter\x1b[?1h');
assert.equal(await page.evaluate(`serializeAddon.serialize({ excludeModes: true });`), 'beforeafter');
});
it('serialize exclude alt buffer', async () => {
await writeSync(page, 'normal\\x1b[?1049h\\x1b[Halt');
assert.equal(await page.evaluate(`serializeAddon.serialize();`), 'normal\x1b[?1049h\x1b[Halt');
assert.equal(await page.evaluate(`serializeAddon.serialize({ excludeAltBuffer: true });`), 'normal');
}); });
it('serialize all rows of content with color16', async function(): Promise<any> { it('serialize all rows of content with color16', async function(): Promise<any> {
@@ -184,11 +196,13 @@ describe('SerializeAddon', () => {
sgr(UNDERLINED) + line, sgr(UNDERLINED) + line,
sgr(BLINK) + line, sgr(BLINK) + line,
sgr(INVISIBLE) + line, sgr(INVISIBLE) + line,
sgr(STRIKETHROUGH) + line,
sgr(NO_INVERSE) + line, sgr(NO_INVERSE) + line,
sgr(NO_BOLD) + line, sgr(NO_BOLD) + line,
sgr(NO_UNDERLINED) + line, sgr(NO_UNDERLINED) + line,
sgr(NO_BLINK) + line, sgr(NO_BLINK) + line,
sgr(NO_INVISIBLE) + line sgr(NO_INVISIBLE) + line,
sgr(NO_STRIKETHROUGH) + line
]; ];
const rows = lines.length; const rows = lines.length;
await writeSync(page, lines.join('\\r\\n')); await writeSync(page, lines.join('\\r\\n'));
@@ -579,20 +593,20 @@ const BG_RGB_GREEN = '48;2;0;255;0';
const BG_RGB_YELLOW = '48;2;255;255;0'; const BG_RGB_YELLOW = '48;2;255;255;0';
const BG_RESET = '49'; const BG_RESET = '49';
const INVERSE = '7';
const BOLD = '1'; const BOLD = '1';
const DIM = '2';
const ITALIC = '3';
const UNDERLINED = '4'; const UNDERLINED = '4';
const BLINK = '5'; const BLINK = '5';
const INVERSE = '7';
const INVISIBLE = '8'; const INVISIBLE = '8';
const STRIKETHROUGH = '9';
const NO_INVERSE = '27';
const NO_BOLD = '22'; const NO_BOLD = '22';
const NO_DIM = '22';
const NO_ITALIC = '23';
const NO_UNDERLINED = '24'; const NO_UNDERLINED = '24';
const NO_BLINK = '25'; const NO_BLINK = '25';
const NO_INVERSE = '27';
const NO_INVISIBLE = '28'; const NO_INVISIBLE = '28';
const NO_STRIKETHROUGH = '29';
const ITALIC = '3';
const DIM = '2';
const NO_ITALIC = '23';
const NO_DIM = '22';
@@ -7,14 +7,14 @@ import { Terminal, ITerminalAddon } from 'xterm';
declare module 'xterm-addon-serialize' { declare module 'xterm-addon-serialize' {
/** /**
* An xterm.js addon that enables web links. * An xterm.js addon that enables serialization of terminal contents.
*/ */
export class SerializeAddon implements ITerminalAddon { export class SerializeAddon implements ITerminalAddon {
constructor(); constructor();
/** /**
* Activates the addon * Activates the addon.
* @param terminal The terminal the addon is being loaded in. * @param terminal The terminal the addon is being loaded in.
*/ */
public activate(terminal: Terminal): void; public activate(terminal: Terminal): void;
@@ -24,15 +24,32 @@ declare module 'xterm-addon-serialize' {
* the state. The cursor will also be positioned to the correct cell. When restoring a terminal * the state. The cursor will also be positioned to the correct cell. When restoring a terminal
* it is best to do before `Terminal.open` is called to avoid wasting CPU cycles rendering * it is best to do before `Terminal.open` is called to avoid wasting CPU cycles rendering
* incomplete frames. * incomplete frames.
* @param scrollback The number of rows in scrollback buffer to serialize, starting from the * @param options Custom options to allow control over what gets serialized.
* bottom of the scrollback buffer. This defaults to the all available rows in the scrollback
* buffer.
*/ */
public serialize(scrollback?: number): string; public serialize(options?: ISerializeOptions): string;
/** /**
* Disposes the addon. * Disposes the addon.
*/ */
public dispose(): void; public dispose(): void;
} }
export interface ISerializeOptions {
/**
* The number of rows in the scrollback buffer to serialize, starting from the bottom of the
* scrollback buffer. When not specified, all available rows in the scrollback buffer will be
* serialized.
*/
scrollback?: number;
/**
* Whether to exclude the terminal modes from the serialization. False by default.
*/
excludeModes?: boolean;
/**
* Whether to exclude the alt buffer from the serialization. False by default.
*/
excludeAltBuffer?: boolean;
}
} }
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "xterm", "name": "xterm",
"description": "Full xterm terminal, in your browser", "description": "Full xterm terminal, in your browser",
"version": "4.14.0", "version": "4.14.1",
"main": "lib/xterm.js", "main": "lib/xterm.js",
"style": "css/xterm.css", "style": "css/xterm.css",
"types": "typings/xterm.d.ts", "types": "typings/xterm.d.ts",
+3 -1
View File
@@ -1180,7 +1180,9 @@ export class Terminal extends CoreTerminal implements ITerminal {
* @param ev The input event to be handled. * @param ev The input event to be handled.
*/ */
protected _inputEvent(ev: InputEvent): boolean { protected _inputEvent(ev: InputEvent): boolean {
if (ev.data && ev.inputType === 'insertText') { // Only support emoji IMEs when screen reader mode is disabled as the event must bubble up to
// support reading out character input which can doubling up input characters
if (ev.data && ev.inputType === 'insertText' && !this.optionsService.options.screenReaderMode) {
if (this._keyPressHandled) { if (this._keyPressHandled) {
return false; return false;
} }
+7 -5
View File
@@ -84,7 +84,7 @@ declare module 'xterm-headless' {
* line height and letter spacing is used. Note that this doesn't work with the DOM renderer * line height and letter spacing is used. Note that this doesn't work with the DOM renderer
* which renders all characters using the font. The default is true. * which renders all characters using the font. The default is true.
*/ */
customGlyphs?: boolean; customGlyphs?: boolean;
/** /**
* Whether input should be disabled. * Whether input should be disabled.
@@ -1085,18 +1085,20 @@ declare module 'xterm-headless' {
/** Whether the cell has the bold attribute (CSI 1 m). */ /** Whether the cell has the bold attribute (CSI 1 m). */
isBold(): number; isBold(): number;
/** Whether the cell has the inverse attribute (CSI 3 m). */ /** Whether the cell has the italic attribute (CSI 3 m). */
isItalic(): number; isItalic(): number;
/** Whether the cell has the inverse attribute (CSI 2 m). */ /** Whether the cell has the dim attribute (CSI 2 m). */
isDim(): number; isDim(): number;
/** Whether the cell has the underline attribute (CSI 4 m). */ /** Whether the cell has the underline attribute (CSI 4 m). */
isUnderline(): number; isUnderline(): number;
/** Whether the cell has the inverse attribute (CSI 5 m). */ /** Whether the cell has the blink attribute (CSI 5 m). */
isBlink(): number; isBlink(): number;
/** Whether the cell has the inverse attribute (CSI 7 m). */ /** Whether the cell has the inverse attribute (CSI 7 m). */
isInverse(): number; isInverse(): number;
/** Whether the cell has the inverse attribute (CSI 8 m). */ /** Whether the cell has the invisible attribute (CSI 8 m). */
isInvisible(): number; isInvisible(): number;
/** Whether the cell has the strikethrough attribute (CSI 9 m). */
isStrikethrough(): number;
/** Whether the cell is using the RGB foreground color mode. */ /** Whether the cell is using the RGB foreground color mode. */
isFgRGB(): boolean; isFgRGB(): boolean;
+6 -4
View File
@@ -1452,18 +1452,20 @@ declare module 'xterm' {
/** Whether the cell has the bold attribute (CSI 1 m). */ /** Whether the cell has the bold attribute (CSI 1 m). */
isBold(): number; isBold(): number;
/** Whether the cell has the inverse attribute (CSI 3 m). */ /** Whether the cell has the italic attribute (CSI 3 m). */
isItalic(): number; isItalic(): number;
/** Whether the cell has the inverse attribute (CSI 2 m). */ /** Whether the cell has the dim attribute (CSI 2 m). */
isDim(): number; isDim(): number;
/** Whether the cell has the underline attribute (CSI 4 m). */ /** Whether the cell has the underline attribute (CSI 4 m). */
isUnderline(): number; isUnderline(): number;
/** Whether the cell has the inverse attribute (CSI 5 m). */ /** Whether the cell has the blink attribute (CSI 5 m). */
isBlink(): number; isBlink(): number;
/** Whether the cell has the inverse attribute (CSI 7 m). */ /** Whether the cell has the inverse attribute (CSI 7 m). */
isInverse(): number; isInverse(): number;
/** Whether the cell has the inverse attribute (CSI 8 m). */ /** Whether the cell has the invisible attribute (CSI 8 m). */
isInvisible(): number; isInvisible(): number;
/** Whether the cell has the strikethrough attribute (CSI 9 m). */
isStrikethrough(): number;
/** Whether the cell is using the RGB foreground color mode. */ /** Whether the cell is using the RGB foreground color mode. */
isFgRGB(): boolean; isFgRGB(): boolean;