Add IntRange type for ColorIndex

Fixes #4614
This commit is contained in:
Daniel Imms
2023-07-28 13:51:46 -07:00
parent 17b8247c3d
commit 79c1fff853
5 changed files with 59 additions and 46 deletions
+11 -7
View File
@@ -4,7 +4,7 @@
* @license MIT
*/
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType } from 'common/Types';
import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, ColorIndexValue } from 'common/Types';
import { C0, C1 } from 'common/data/EscapeSequences';
import { CHARSETS, DEFAULT_CHARSET } from 'common/data/Charsets';
import { EscapeSequenceParser } from 'common/parser/EscapeSequenceParser';
@@ -2915,7 +2915,7 @@ export class InputHandler extends Disposable implements IInputHandler {
const spec = slots.shift() as string;
if (/^\d+$/.exec(idx)) {
const index = parseInt(idx);
if (0 <= index && index < 256) {
if (isValidColorIndex(index) && index < 256) {
if (spec === '?') {
event.push({ type: ColorRequestType.REPORT, index });
} else {
@@ -2988,7 +2988,7 @@ export class InputHandler extends Disposable implements IInputHandler {
}
// special colors - OSC 10 | 11 | 12
private _specialColors = [ColorIndex.FOREGROUND, ColorIndex.BACKGROUND, ColorIndex.CURSOR];
private _specialColors = [ColorIndexValue.FOREGROUND, ColorIndexValue.BACKGROUND, ColorIndexValue.CURSOR];
/**
* Apply colors requests for special colors in OSC 10 | 11 | 12.
@@ -3073,7 +3073,7 @@ export class InputHandler extends Disposable implements IInputHandler {
for (let i = 0; i < slots.length; ++i) {
if (/^\d+$/.exec(slots[i])) {
const index = parseInt(slots[i]);
if (0 <= index && index < 256) {
if (isValidColorIndex(index) && index < 256) {
event.push({ type: ColorRequestType.RESTORE, index });
}
}
@@ -3090,7 +3090,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 110 "Restore default foreground color" "OSC 110 BEL" "Restore default foreground to themed color."
*/
public restoreFgColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.FOREGROUND }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndexValue.FOREGROUND }]);
return true;
}
@@ -3100,7 +3100,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 111 "Restore default background color" "OSC 111 BEL" "Restore default background to themed color."
*/
public restoreBgColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.BACKGROUND }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndexValue.BACKGROUND }]);
return true;
}
@@ -3110,7 +3110,7 @@ export class InputHandler extends Disposable implements IInputHandler {
* @vt: #Y OSC 112 "Restore default cursor color" "OSC 112 BEL" "Restore default cursor to themed color."
*/
public restoreCursorColor(data: string): boolean {
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndex.CURSOR }]);
this._onColor.fire([{ type: ColorRequestType.RESTORE, index: ColorIndexValue.CURSOR }]);
return true;
}
@@ -3429,3 +3429,7 @@ class DirtyRowTracker implements IDirtyRowTracker {
this.markRangeDirty(0, this._bufferService.rows - 1);
}
}
function isValidColorIndex(value: number): value is ColorIndex {
return 0 <= value && value < 259;
}