From 71195b5370aa367e8d1df5db506196b138251c1b Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 10 Jul 2022 11:43:45 -0700 Subject: [PATCH 1/2] Throw when setting an invalid cursorStyle Fixes #3477 --- demo/client.ts | 1 + src/common/Types.d.ts | 2 ++ src/common/services/OptionsService.ts | 13 +++++++++++++ src/common/services/Services.ts | 4 ++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 1c38af0f..9dd04a74 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -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); diff --git a/src/common/Types.d.ts b/src/common/Types.d.ts index c48b23ea..94058a58 100644 --- a/src/common/Types.d.ts +++ b/src/common/Types.d.ts @@ -35,6 +35,8 @@ export interface ITerminalOptions extends IPublicTerminalOptions { termName?: string; } +export type CursorStyle = 'block' | 'underline' | 'bar'; + export type XtermListener = (...args: any[]) => void; /** diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index 4008a431..4f9600a4 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -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'; +} diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 017eb386..b4536eb1 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -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; From f61ff9fd46473dfdc82cedab0664d463aa253af1 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 11 Jul 2022 05:56:42 -0700 Subject: [PATCH 2/2] Fix lint --- src/common/services/Services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index b4536eb1..bad6c004 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -217,7 +217,7 @@ export interface ITerminalOptions { cols: number; convertEol: boolean; cursorBlink: boolean; - cursorStyle: CursorStyle, + cursorStyle: CursorStyle; cursorWidth: number; customGlyphs: boolean; disableStdin: boolean;