Skip to content

Commit

Permalink
Merge pull request #3947 from Tyriar/v5_deprecated
Browse files Browse the repository at this point in the history
Remove remaining deprecated APIs for v5 (getOption, setOption, writeUtf8)
  • Loading branch information
Tyriar authored Jul 27, 2022
2 parents b2aa100 + 8c16d9d commit e7dbdb1
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 294 deletions.
4 changes: 2 additions & 2 deletions src/browser/Terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe('Terminal', () => {

describe('when scrollback === 0', () => {
beforeEach(() => {
term.optionsService.setOption('scrollback', 0);
term.optionsService.options.scrollback = 0;
assert.equal(term.buffer.lines.maxLength, INIT_ROWS);
});

Expand Down Expand Up @@ -1346,7 +1346,7 @@ describe('Terminal', () => {
term = new TestTerminal({});
markers = [];
disposeStack = [];
term.optionsService.setOption('scrollback', 1);
term.optionsService.options.scrollback = 1;
term.resize(10, 5);
markers.push(term.buffers.active.addMarker(term.buffers.active.y));
await term.writeP('\x1b[r0\r\n');
Expand Down
3 changes: 0 additions & 3 deletions src/browser/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ export class MockTerminal implements ITerminal {
public write(data: string): void {
throw new Error('Method not implemented.');
}
public writeUtf8(data: Uint8Array): void {
throw new Error('Method not implemented.');
}
public bracketedPasteMode!: boolean;
public renderer!: IRenderer;
public linkifier2!: ILinkifier2;
Expand Down
24 changes: 0 additions & 24 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,37 +219,13 @@ export class Terminal implements ITerminalApi {
public write(data: string | Uint8Array, callback?: () => void): void {
this._core.write(data, callback);
}
public writeUtf8(data: Uint8Array, callback?: () => void): void {
this._core.write(data, callback);
}
public writeln(data: string | Uint8Array, callback?: () => void): void {
this._core.write(data);
this._core.write('\r\n', callback);
}
public paste(data: string): void {
this._core.paste(data);
}
public getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord'): boolean;
public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
public getOption(key: 'fontWeight' | 'fontWeightBold'): FontWeight;
public getOption(key: string): any;
public getOption(key: any): any {
return this._core.optionsService.getOption(key);
}
public setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void;
public setOption(key: 'fontWeight' | 'fontWeightBold', value: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void;
public setOption(key: 'logLevel', value: 'debug' | 'info' | 'warn' | 'error' | 'off'): void;
public setOption(key: 'cursorStyle', value: 'block' | 'underline' | 'bar'): void;
public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord', value: boolean): void;
public setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
public setOption(key: 'theme', value: ITheme): void;
public setOption(key: 'cols' | 'rows', value: number): void;
public setOption(key: string, value: any): void;
public setOption(key: any, value: any): void {
this._checkReadonlyOptions(key);
this._core.optionsService.setOption(key, value);
}
public refresh(start: number, end: number): void {
this._verifyIntegers(start, end);
this._core.refresh(start, end);
Expand Down
2 changes: 1 addition & 1 deletion src/browser/services/SelectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ export class SelectionService extends Disposable implements ISelectionService {

this._removeMouseDownListeners();

if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME && event.altKey && this._optionsService.getOption('altClickMovesCursor')) {
if (this.selectionText.length <= 1 && timeElapsed < ALT_CLICK_MOVE_CURSOR_TIME && event.altKey && this._optionsService.rawOptions.altClickMovesCursor) {
if (this._bufferService.buffer.ybase === this._bufferService.buffer.ydisp) {
const coordinates = this._mouseService.getCoords(
event,
Expand Down
6 changes: 0 additions & 6 deletions src/common/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ export class MockOptionsService implements IOptionsService {
this.options[key] = options[key];
}
}
public setOption<T>(key: string, value: T): void {
throw new Error('Method not implemented.');
}
public getOption<T>(key: string): T {
throw new Error('Method not implemented.');
}
}

// defaults to V6 always to keep tests passing
Expand Down
52 changes: 26 additions & 26 deletions src/common/services/OptionsService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ describe('OptionsService', () => {
});
it('uses default value if invalid constructor option values passed for cols/rows', () => {
const optionsService = new OptionsService({ cols: undefined, rows: undefined });
assert.equal(optionsService.getOption('rows'), DEFAULT_OPTIONS.rows);
assert.equal(optionsService.getOption('cols'), DEFAULT_OPTIONS.cols);
assert.equal(optionsService.options.rows, DEFAULT_OPTIONS.rows);
assert.equal(optionsService.options.cols, DEFAULT_OPTIONS.cols);
});
it('uses values from constructor option values if correctly passed', () => {
const optionsService = new OptionsService({ cols: 80, rows: 25 });
assert.equal(optionsService.getOption('rows'), 25);
assert.equal(optionsService.getOption('cols'), 80);
assert.equal(optionsService.options.rows, 25);
assert.equal(optionsService.options.cols, 80);
});
it('uses default value if invalid constructor option value passed', () => {
assert.equal(new OptionsService({ tabStopWidth: 0 }).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
assert.equal(new OptionsService({ tabStopWidth: 0 }).options.tabStopWidth, DEFAULT_OPTIONS.tabStopWidth);
});
it('object.keys return the correct number of options', () => {
const optionsService = new OptionsService({ cols: 80, rows: 25 });
Expand All @@ -39,36 +39,36 @@ describe('OptionsService', () => {
service = new OptionsService({});
});
it('applies valid fontWeight option values', () => {
service.setOption('fontWeight', 'bold');
assert.equal(service.getOption('fontWeight'), 'bold', '"bold" keyword value should be applied');
service.options.fontWeight = 'bold';
assert.equal(service.options.fontWeight, 'bold', '"bold" keyword value should be applied');

service.setOption('fontWeight', 'normal');
assert.equal(service.getOption('fontWeight'), 'normal', '"normal" keyword value should be applied');
service.options.fontWeight = 'normal';
assert.equal(service.options.fontWeight, 'normal', '"normal" keyword value should be applied');

service.setOption('fontWeight', '600');
assert.equal(service.getOption('fontWeight'), '600', 'String numeric values should be applied');
service.options.fontWeight = '600';
assert.equal(service.options.fontWeight, '600', 'String numeric values should be applied');

service.setOption('fontWeight', 350);
assert.equal(service.getOption('fontWeight'), 350, 'Values between 1 and 1000 should be applied as is');
service.options.fontWeight = 350;
assert.equal(service.options.fontWeight, 350, 'Values between 1 and 1000 should be applied as is');

service.setOption('fontWeight', 1);
assert.equal(service.getOption('fontWeight'), 1, 'Range should include minimum value: 1');
service.options.fontWeight = 1;
assert.equal(service.options.fontWeight, 1, 'Range should include minimum value: 1');

service.setOption('fontWeight', 1000);
assert.equal(service.getOption('fontWeight'), 1000, 'Range should include maximum value: 1000');
service.options.fontWeight = 1000;
assert.equal(service.options.fontWeight, 1000, 'Range should include maximum value: 1000');
});
it('normalizes invalid fontWeight option values', () => {
service.setOption('fontWeight', 350);
assert.doesNotThrow(() => service.setOption('fontWeight', 10000), 'fontWeight should be normalized instead of throwing');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');
service.options.fontWeight = 350;
assert.doesNotThrow(() => service.options.fontWeight = 10000), 'fontWeight should be normalized instead of throwing';
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Values greater than 1000 should be reset to default');

service.setOption('fontWeight', 350);
service.setOption('fontWeight', -10);
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');
service.options.fontWeight = 350;
service.options.fontWeight = -10;
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Values less than 1 should be reset to default');

service.setOption('fontWeight', 350);
service.setOption('fontWeight', 'bold700');
assert.equal(service.getOption('fontWeight'), DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
service.options.fontWeight = 350;
service.options.fontWeight = 'bold700' as any;
assert.equal(service.options.fontWeight, DEFAULT_OPTIONS.fontWeight, 'Wrong string literals should be reset to default');
});
});
});
8 changes: 0 additions & 8 deletions src/common/services/OptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ export class OptionsService implements IOptionsService {
}
}

public setOption(key: string, value: any): void {
this.options[key] = value;
}

private _sanitizeAndValidateOption(key: string, value: any): any {
switch (key) {
case 'cursorStyle':
Expand Down Expand Up @@ -170,10 +166,6 @@ export class OptionsService implements IOptionsService {
}
return value;
}

public getOption(key: string): any {
return this.options[key];
}
}

function isCursorStyle(value: unknown): value is CursorStyle {
Expand Down
3 changes: 0 additions & 3 deletions src/common/services/Services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ export interface IOptionsService {
readonly options: ITerminalOptions;

readonly onOptionChange: IEvent<string>;

setOption<T>(key: string, value: T): void;
getOption<T>(key: string): T | undefined;
}

export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
Expand Down
6 changes: 0 additions & 6 deletions src/headless/public/Terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ describe('Headless API Tests', function (): void {
}
});

it('getOption, setOption', async () => {
strictEqual(term.getOption('scrollback'), 1000);
term.setOption('scrollback', 50);
strictEqual(term.getOption('scrollback'), 50);
});

describe('options', () => {
const termOptions = {
cols: 80,
Expand Down
21 changes: 0 additions & 21 deletions src/headless/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,10 @@ export class Terminal implements ITerminalApi {
public write(data: string | Uint8Array, callback?: () => void): void {
this._core.write(data, callback);
}
public writeUtf8(data: Uint8Array, callback?: () => void): void {
this._core.write(data, callback);
}
public writeln(data: string | Uint8Array, callback?: () => void): void {
this._core.write(data);
this._core.write('\r\n', callback);
}
public getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
public getOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord'): boolean;
public getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
public getOption(key: string): any;
public getOption(key: any): any {
return this._core.optionsService.getOption(key);
}
public setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void;
public setOption(key: 'fontWeight' | 'fontWeightBold', value: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void;
public setOption(key: 'logLevel', value: 'debug' | 'info' | 'warn' | 'error' | 'off'): void;
public setOption(key: 'cursorStyle', value: 'block' | 'underline' | 'bar'): void;
public setOption(key: 'allowTransparency' | 'altClickMovesCursor' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord', value: boolean): void;
public setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
public setOption(key: 'cols' | 'rows', value: number): void;
public setOption(key: string, value: any): void;
public setOption(key: any, value: any): void {
this._core.optionsService.setOption(key, value);
}
public reset(): void {
this._core.reset();
}
Expand Down
7 changes: 0 additions & 7 deletions test/api/Terminal.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ describe('API Integration Tests', function(): void {
}
});

it('getOption, setOption', async () => {
await openTerminal(page);
assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'canvas');
await page.evaluate(`window.term.setOption('rendererType', 'dom')`);
assert.equal(await page.evaluate(`window.term.getOption('rendererType')`), 'dom');
});

describe('options', () => {
it('getter', async () => {
await openTerminal(page);
Expand Down
84 changes: 0 additions & 84 deletions typings/xterm-headless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,90 +689,6 @@ declare module 'xterm-headless' {
*/
writeln(data: string | Uint8Array, callback?: () => void): void;

/**
* Write UTF8 data to the terminal.
* @param data The data to write to the terminal.
* @param callback Optional callback when data was processed.
* @deprecated use `write` instead
*/
writeUtf8(data: Uint8Array, callback?: () => void): void;

/**
* Retrieves an option's value from the terminal.
* @param key The option key.
*/
getOption(key: 'cursorStyle' | 'fontFamily' | 'logLevel' | 'rendererType' | 'termName' | 'wordSeparator'): string;
/**
* Retrieves an option's value from the terminal.
* @param key The option key.
*/
getOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode'): boolean;
/**
* Retrieves an option's value from the terminal.
* @param key The option key.
*/
getOption(key: 'cols' | 'fontSize' | 'letterSpacing' | 'lineHeight' | 'rows' | 'tabStopWidth' | 'scrollback'): number;
/**
* Retrieves an option's value from the terminal.
* @param key The option key.
*/
getOption(key: string): any;

/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'fontFamily' | 'termName' | 'wordSeparator', value: string): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'fontWeight' | 'fontWeightBold', value: null | 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'logLevel', value: LogLevel): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'cursorStyle', value: null | 'block' | 'underline' | 'bar'): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'allowTransparency' | 'cancelEvents' | 'convertEol' | 'cursorBlink' | 'disableStdin' | 'macOptionIsMeta' | 'rightClickSelectsWord' | 'windowsMode', value: boolean): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'fontSize' | 'letterSpacing' | 'lineHeight' | 'tabStopWidth' | 'scrollback', value: number): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'theme', value: ITheme): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: 'cols' | 'rows', value: number): void;
/**
* Sets an option on the terminal.
* @param key The option key.
* @param value The option value.
*/
setOption(key: string, value: any): void;

/**
* Perform a full reset (RIS, aka '\x1bc').
*/
Expand Down
Loading

0 comments on commit e7dbdb1

Please sign in to comment.