Skip to content

Commit 47fe7b2

Browse files
authored
Merge pull request #3667 from childrentime/dev_wlw
Replace all getOption/setOption usage with options
2 parents 842f4c2 + 51d18e5 commit 47fe7b2

File tree

10 files changed

+67
-67
lines changed

10 files changed

+67
-67
lines changed

addons/xterm-addon-ligatures/src/index.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('xterm-addon-ligatures', () => {
7878
});
7979

8080
it('handles quoted font names', done => {
81-
term.setOption('fontFamily', '"Fira Code", monospace');
81+
term.options.fontFamily = '"Fira Code", monospace';
8282
assert.deepEqual(term.joiner!(input), []);
8383
onRefresh.callsFake(() => {
8484
assert.deepEqual(term.joiner!(input), [[2, 4], [7, 10]]);
@@ -87,7 +87,7 @@ describe('xterm-addon-ligatures', () => {
8787
});
8888

8989
it('falls back to later fonts if earlier ones are not present', done => {
90-
term.setOption('fontFamily', 'notinstalled, Fira Code, monospace');
90+
term.options.fontFamily = 'notinstalled, Fira Code, monospace';
9191
assert.deepEqual(term.joiner!(input), []);
9292
onRefresh.callsFake(() => {
9393
assert.deepEqual(term.joiner!(input), [[2, 4], [7, 10]]);
@@ -98,17 +98,17 @@ describe('xterm-addon-ligatures', () => {
9898
it('uses the current font value', done => {
9999
// The first three calls are all synchronous so that we don't allow time for
100100
// any fonts to load while we're switching things around
101-
term.setOption('fontFamily', 'Fira Code');
101+
term.options.fontFamily = 'Fira Code';
102102
assert.deepEqual(term.joiner!(input), []);
103-
term.setOption('fontFamily', 'notinstalled');
103+
term.options.fontFamily = 'notinstalled';
104104
assert.deepEqual(term.joiner!(input), []);
105-
term.setOption('fontFamily', 'Iosevka');
105+
term.options.fontFamily = 'Iosevka';
106106
assert.deepEqual(term.joiner!(input), []);
107107
onRefresh.callsFake(() => {
108108
assert.deepEqual(term.joiner!(input), [[2, 4]]);
109109

110110
// And switch it back to Fira Code for good measure
111-
term.setOption('fontFamily', 'Fira Code');
111+
term.options.fontFamily = 'Fira Code';
112112

113113
// At this point, we haven't loaded the new font, so the result reverts
114114
// back to empty until that happens
@@ -124,7 +124,7 @@ describe('xterm-addon-ligatures', () => {
124124
it('allows multiple terminal instances that use different fonts', done => {
125125
const onRefresh2 = sinon.stub();
126126
const term2 = new MockTerminal(onRefresh2);
127-
term2.setOption('fontFamily', 'Iosevka');
127+
term2.options.fontFamily = 'Iosevka';
128128
ligatureSupport.enableLigatures(term2 as any);
129129

130130
assert.deepEqual(term.joiner!(input), []);
@@ -140,39 +140,39 @@ describe('xterm-addon-ligatures', () => {
140140
});
141141

142142
it('fails if it finds but cannot load the font', async () => {
143-
term.setOption('fontFamily', 'Nonexistant Font, monospace');
143+
term.options.fontFamily = 'Nonexistant Font, monospace';
144144
assert.deepEqual(term.joiner!(input), []);
145145
await delay(500);
146146
assert.isTrue(onRefresh.notCalled);
147147
assert.throws(() => term.joiner!(input));
148148
});
149149

150150
it('returns nothing if the font is not present on the system', async () => {
151-
term.setOption('fontFamily', 'notinstalled');
151+
term.options.fontFamily = 'notinstalled';
152152
assert.deepEqual(term.joiner!(input), []);
153153
await delay(500);
154154
assert.isTrue(onRefresh.notCalled);
155155
assert.deepEqual(term.joiner!(input), []);
156156
});
157157

158158
it('returns nothing if no specific font is specified', async () => {
159-
term.setOption('fontFamily', 'monospace');
159+
term.options.fontFamily = 'monospace';
160160
assert.deepEqual(term.joiner!(input), []);
161161
await delay(500);
162162
assert.isTrue(onRefresh.notCalled);
163163
assert.deepEqual(term.joiner!(input), []);
164164
});
165165

166166
it('returns nothing if no fonts are provided', async () => {
167-
term.setOption('fontFamily', '');
167+
term.options.fontFamily = '';
168168
assert.deepEqual(term.joiner!(input), []);
169169
await delay(500);
170170
assert.isTrue(onRefresh.notCalled);
171171
assert.deepEqual(term.joiner!(input), []);
172172
});
173173

174174
it('fails when given malformed inputs', async () => {
175-
term.setOption('fontFamily', {} as any);
175+
term.options.fontFamily = {} as any;
176176
assert.deepEqual(term.joiner!(input), []);
177177
await delay(500);
178178
assert.isTrue(onRefresh.notCalled);
@@ -181,7 +181,7 @@ describe('xterm-addon-ligatures', () => {
181181

182182
it('ensures no empty errors are thrown', async () => {
183183
sinon.stub(fontLigatures, 'loadFile').callsFake(async () => { throw undefined; });
184-
term.setOption('fontFamily', 'Iosevka');
184+
term.options.fontFamily = 'Iosevka';
185185
assert.deepEqual(term.joiner!(input), []);
186186
await delay(500);
187187
assert.isTrue(onRefresh.notCalled);
@@ -209,11 +209,11 @@ class MockTerminal {
209209
public deregisterCharacterJoiner(id: number): void {
210210
this.joiner = undefined;
211211
}
212-
public setOption(name: string, value: string | number): void {
213-
this._options[name] = value;
214-
}
215-
public getOption(name: string): string | number {
216-
return this._options[name];
212+
public get options(): { [name: string]: string | number } { return this._options; }
213+
public set options(options: { [name: string]: string | number }) {
214+
for (const key in this._options) {
215+
this._options[key] = options[key];
216+
}
217217
}
218218
}
219219

addons/xterm-addon-ligatures/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function enableLigatures(term: Terminal): void {
3434

3535
term.registerCharacterJoiner((text: string): [number, number][] => {
3636
// If the font hasn't been loaded yet, load it and return an empty result
37-
const termFont = term.getOption('fontFamily');
37+
const termFont = term.options.fontFamily;
3838
if (
3939
termFont &&
4040
(loadingState === LoadingState.UNLOADED || currentFontName !== termFont)
@@ -48,20 +48,20 @@ export function enableLigatures(term: Terminal): void {
4848
.then(f => {
4949
// Another request may have come in while we were waiting, so make
5050
// sure our font is still vaild.
51-
if (currentCallFontName === term.getOption('fontFamily')) {
51+
if (currentCallFontName === term.options.fontFamily) {
5252
loadingState = LoadingState.LOADED;
5353
font = f;
5454

5555
// Only refresh things if we actually found a font
5656
if (f) {
57-
term.refresh(0, term.getOption('rows') - 1);
57+
term.refresh(0, term.options.rows! - 1);
5858
}
5959
}
6060
})
6161
.catch(e => {
6262
// Another request may have come in while we were waiting, so make
6363
// sure our font is still vaild.
64-
if (currentCallFontName === term.getOption('fontFamily')) {
64+
if (currentCallFontName === term.options.fontFamily) {
6565
loadingState = LoadingState.FAILED;
6666
font = undefined;
6767
loadError = e;

addons/xterm-addon-webgl/src/WebglRenderer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,18 @@ export class WebglRenderer extends Disposable implements IRenderer {
440440
// will be floored because since lineHeight can never be lower then 1, there
441441
// is a guarentee that the scaled line height will always be larger than
442442
// scaled char height.
443-
this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.getOption('lineHeight'));
443+
this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight!);
444444

445445
// Calculate the y coordinate within a cell that text should draw from in
446446
// order to draw in the center of a cell.
447-
this.dimensions.scaledCharTop = this._terminal.getOption('lineHeight') === 1 ? 0 : Math.round((this.dimensions.scaledCellHeight - this.dimensions.scaledCharHeight) / 2);
447+
this.dimensions.scaledCharTop = this._terminal.options.lineHeight === 1 ? 0 : Math.round((this.dimensions.scaledCellHeight - this.dimensions.scaledCharHeight) / 2);
448448

449449
// Calculate the scaled cell width, taking the letterSpacing into account.
450-
this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.getOption('letterSpacing'));
450+
this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing!);
451451

452452
// Calculate the x coordinate with a cell that text should draw from in
453453
// order to draw in the center of a cell.
454-
this.dimensions.scaledCharLeft = Math.floor(this._terminal.getOption('letterSpacing') / 2);
454+
this.dimensions.scaledCharLeft = Math.floor(this._terminal.options.letterSpacing! / 2);
455455

456456
// Recalculate the canvas dimensions; scaled* define the actual number of
457457
// pixel in the canvas

addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ export function generateConfig(scaledCellWidth: number, scaledCellHeight: number
2828
contrastCache: colors.contrastCache
2929
};
3030
return {
31-
customGlyphs: terminal.getOption('customGlyphs'),
31+
customGlyphs: terminal.options.customGlyphs!,
3232
devicePixelRatio: window.devicePixelRatio,
33-
letterSpacing: terminal.getOption('letterSpacing'),
34-
lineHeight: terminal.getOption('lineHeight'),
33+
letterSpacing: terminal.options.letterSpacing!,
34+
lineHeight: terminal.options.lineHeight!,
3535
scaledCellWidth,
3636
scaledCellHeight,
3737
scaledCharWidth,
3838
scaledCharHeight,
39-
fontFamily: terminal.getOption('fontFamily'),
40-
fontSize: terminal.getOption('fontSize'),
41-
fontWeight: terminal.getOption('fontWeight') as FontWeight,
42-
fontWeightBold: terminal.getOption('fontWeightBold') as FontWeight,
43-
allowTransparency: terminal.getOption('allowTransparency'),
44-
drawBoldTextInBrightColors: terminal.getOption('drawBoldTextInBrightColors'),
45-
minimumContrastRatio: terminal.getOption('minimumContrastRatio'),
39+
fontFamily: terminal.options.fontFamily!,
40+
fontSize: terminal.options.fontSize!,
41+
fontWeight: terminal.options.fontWeight as FontWeight,
42+
fontWeightBold: terminal.options.fontWeightBold as FontWeight,
43+
allowTransparency: terminal.options.allowTransparency!,
44+
drawBoldTextInBrightColors: terminal.options.drawBoldTextInBrightColors!,
45+
minimumContrastRatio: terminal.options.minimumContrastRatio!,
4646
colors: clonedColors
4747
};
4848
}

addons/xterm-addon-webgl/src/renderLayer/BaseRenderLayer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ export abstract class BaseRenderLayer implements IRenderLayer {
254254
* @param isBold If we should use the bold fontWeight.
255255
*/
256256
protected _getFont(terminal: Terminal, isBold: boolean, isItalic: boolean): string {
257-
const fontWeight = isBold ? terminal.getOption('fontWeightBold') : terminal.getOption('fontWeight');
257+
const fontWeight = isBold ? terminal.options.fontWeightBold : terminal.options.fontWeight;
258258
const fontStyle = isItalic ? 'italic' : '';
259259

260-
return `${fontStyle} ${fontWeight} ${terminal.getOption('fontSize') * window.devicePixelRatio}px ${terminal.getOption('fontFamily')}`;
260+
return `${fontStyle} ${fontWeight} ${terminal.options.fontSize! * window.devicePixelRatio}px ${terminal.options.fontFamily}`;
261261
}
262262
}
263263

addons/xterm-addon-webgl/src/renderLayer/CursorRenderLayer.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
8383
}
8484

8585
public onOptionsChanged(terminal: Terminal): void {
86-
if (terminal.getOption('cursorBlink')) {
86+
if (terminal.options.cursorBlink) {
8787
if (!this._cursorBlinkStateManager) {
8888
this._cursorBlinkStateManager = new CursorBlinkStateManager(terminal, () => {
8989
this._render(terminal, true);
@@ -140,7 +140,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
140140
this._clearCursor();
141141
this._ctx.save();
142142
this._ctx.fillStyle = this._colors.cursor.css;
143-
const cursorStyle = terminal.getOption('cursorStyle');
143+
const cursorStyle = terminal.options.cursorStyle;
144144
if (cursorStyle && cursorStyle !== 'block') {
145145
this._cursorRenderers[cursorStyle](terminal, cursorX, viewportRelativeCursorY, this._cell);
146146
} else {
@@ -150,7 +150,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
150150
this._state.x = cursorX;
151151
this._state.y = viewportRelativeCursorY;
152152
this._state.isFocused = false;
153-
this._state.style = cursorStyle;
153+
this._state.style = cursorStyle!;
154154
this._state.width = this._cell.getWidth();
155155
return;
156156
}
@@ -166,21 +166,21 @@ export class CursorRenderLayer extends BaseRenderLayer {
166166
if (this._state.x === cursorX &&
167167
this._state.y === viewportRelativeCursorY &&
168168
this._state.isFocused === isTerminalFocused(terminal) &&
169-
this._state.style === terminal.getOption('cursorStyle') &&
169+
this._state.style === terminal.options.cursorStyle &&
170170
this._state.width === this._cell.getWidth()) {
171171
return;
172172
}
173173
this._clearCursor();
174174
}
175175

176176
this._ctx.save();
177-
this._cursorRenderers[terminal.getOption('cursorStyle') || 'block'](terminal, cursorX, viewportRelativeCursorY, this._cell);
177+
this._cursorRenderers[terminal.options.cursorStyle || 'block'](terminal, cursorX, viewportRelativeCursorY, this._cell);
178178
this._ctx.restore();
179179

180180
this._state.x = cursorX;
181181
this._state.y = viewportRelativeCursorY;
182182
this._state.isFocused = false;
183-
this._state.style = terminal.getOption('cursorStyle');
183+
this._state.style = terminal.options.cursorStyle!;
184184
this._state.width = this._cell.getWidth();
185185
}
186186

@@ -205,7 +205,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
205205
private _renderBarCursor(terminal: Terminal, x: number, y: number, cell: ICellData): void {
206206
this._ctx.save();
207207
this._ctx.fillStyle = this._colors.cursor.css;
208-
this._fillLeftLineAtCell(x, y, terminal.getOption('cursorWidth'));
208+
this._fillLeftLineAtCell(x, y, terminal.options.cursorWidth!);
209209
this._ctx.restore();
210210
}
211211

0 commit comments

Comments
 (0)