Skip to content

Commit aa046b7

Browse files
committed
Handle undefined rows or cols better
1 parent 52d00a4 commit aa046b7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/common/services/BufferService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export class BufferService extends Disposable implements IBufferService {
3636
@IOptionsService private _optionsService: IOptionsService
3737
) {
3838
super();
39-
this.cols = Math.max(_optionsService.options.cols, MINIMUM_COLS);
40-
this.rows = Math.max(_optionsService.options.rows, MINIMUM_ROWS);
39+
this.cols = Math.max(_optionsService.options.cols || 0, MINIMUM_COLS);
40+
this.rows = Math.max(_optionsService.options.rows || 0, MINIMUM_ROWS);
4141
this.buffers = new BufferSet(_optionsService, this);
4242
}
4343

src/common/services/OptionsService.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@ describe('OptionsService', () => {
1010
describe('constructor', () => {
1111
const originalError = console.error;
1212
beforeEach(() => {
13-
console.error = () => {};
13+
console.error = () => { };
1414
});
1515
afterEach(() => {
1616
console.error = originalError;
1717
});
18+
it('uses default value if invalid constructor option values passed for cols/rows', () => {
19+
const optionsService = new OptionsService({ cols: undefined, rows: undefined });
20+
assert.equal(optionsService.getOption('rows'), DEFAULT_OPTIONS.rows);
21+
assert.equal(optionsService.getOption('cols'), DEFAULT_OPTIONS.cols);
22+
});
23+
it('uses values from constructor option values if correctly passed', () => {
24+
const optionsService = new OptionsService({ cols: 80, rows: 25 });
25+
assert.equal(optionsService.getOption('rows'), 25);
26+
assert.equal(optionsService.getOption('cols'), 80);
27+
});
1828
it('uses default value if invalid constructor option value passed', () => {
19-
assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
29+
assert.equal(new OptionsService({ tabStopWidth: 0 }).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth);
2030
});
2131
});
2232
describe('setOption', () => {

src/common/services/OptionsService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
2222
cursorStyle: 'block',
2323
cursorWidth: 1,
2424
customGlyphs: true,
25-
bellSound: DEFAULT_BELL_SOUND,
25+
bellSound: DEFAULT_BELL_SOUND,
2626
bellStyle: 'none',
2727
drawBoldTextInBrightColors: true,
2828
fastScrollModifier: 'alt',
@@ -128,7 +128,7 @@ export class OptionsService implements IOptionsService {
128128
break;
129129
case 'cursorWidth':
130130
value = Math.floor(value);
131-
// Fall through for bounds check
131+
// Fall through for bounds check
132132
case 'lineHeight':
133133
case 'tabStopWidth':
134134
if (value < 1) {
@@ -149,6 +149,11 @@ export class OptionsService implements IOptionsService {
149149
if (value <= 0) {
150150
throw new Error(`${key} cannot be less than or equal to 0, value: ${value}`);
151151
}
152+
case 'rows':
153+
case 'cols':
154+
if (!value && value !== 0) {
155+
throw new Error(`${key} must be numeric, value: ${value}`);
156+
}
152157
break;
153158
}
154159
return value;

0 commit comments

Comments
 (0)