Throw when setting an invalid cursorStyle

Fixes #3477
This commit is contained in:
Daniel Imms
2022-07-10 11:43:45 -07:00
parent 55beec8b96
commit 71195b5370
4 changed files with 18 additions and 2 deletions
+13
View File
@@ -6,6 +6,7 @@
import { IOptionsService, ITerminalOptions, FontWeight } from 'common/services/Services';
import { EventEmitter, IEvent } from 'common/EventEmitter';
import { isMac } from 'common/Platform';
import { CursorStyle } from 'common/Types';
// Source: https://freesound.org/people/altemark/sounds/45759/
// This sound is released under the Creative Commons Attribution 3.0 Unported
@@ -123,6 +124,14 @@ export class OptionsService implements IOptionsService {
private _sanitizeAndValidateOption(key: string, value: any): any {
switch (key) {
case 'cursorStyle':
if (!value) {
value = DEFAULT_OPTIONS[key];
}
if (!isCursorStyle(value)) {
throw new Error(`"${value}" is not a valid value for ${key}`);
}
break;
case 'bellStyle':
case 'cursorStyle':
case 'rendererType':
@@ -176,3 +185,7 @@ export class OptionsService implements IOptionsService {
return this.options[key];
}
}
function isCursorStyle(value: unknown): value is CursorStyle {
return value === 'block' || value === 'underline' || value === 'bar';
}