Merge pull request #3900 from Tyriar/3477

Throw when setting an invalid cursorStyle
This commit is contained in:
Daniel Imms
2022-07-11 11:42:59 -07:00
committed by GitHub
4 changed files with 18 additions and 2 deletions
+1
View File
@@ -173,6 +173,7 @@ function createTerminal(): void {
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0;
term = new Terminal({
allowTransparency: true,
windowsMode: isWindows,
fontFamily: 'Fira Code, courier-new, courier, monospace'
} as ITerminalOptions);
+2
View File
@@ -35,6 +35,8 @@ export interface ITerminalOptions extends IPublicTerminalOptions {
termName?: string;
}
export type CursorStyle = 'block' | 'underline' | 'bar';
export type XtermListener = (...args: any[]) => void;
/**
+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';
}
+2 -2
View File
@@ -5,7 +5,7 @@
import { IEvent, IEventEmitter } from 'common/EventEmitter';
import { IBuffer, IBufferSet } from 'common/buffer/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource, IDisposable, IColorRGB, IColor } from 'common/Types';
import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEncoding, ICoreMouseProtocol, CoreMouseEventType, ICharset, IWindowOptions, IModes, IAttributeData, ScrollSource, IDisposable, IColorRGB, IColor, CursorStyle } from 'common/Types';
import { createDecorator } from 'common/services/ServiceRegistry';
import { IDecorationOptions, IDecoration } from 'xterm';
@@ -217,7 +217,7 @@ export interface ITerminalOptions {
cols: number;
convertEol: boolean;
cursorBlink: boolean;
cursorStyle: 'block' | 'underline' | 'bar';
cursorStyle: CursorStyle;
cursorWidth: number;
customGlyphs: boolean;
disableStdin: boolean;