From 8b3f9ad8e1ac77e6585c6ee48c540ea4e3a27fa6 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 19 Jul 2022 05:10:31 -0700 Subject: [PATCH 1/2] Be more defensive when setting extended ansi colors Part of #3601 --- src/browser/ColorManager.test.ts | 4 ++-- src/browser/ColorManager.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/browser/ColorManager.test.ts b/src/browser/ColorManager.test.ts index dfcc9ec8f3..3fbd92f1c4 100644 --- a/src/browser/ColorManager.test.ts +++ b/src/browser/ColorManager.test.ts @@ -315,14 +315,14 @@ describe('ColorManager', () => { extendedAnsi: DEFAULT_ANSI_COLORS.map(a => a.css).slice().reverse() }); - for (let ansiColor = 16; ansiColor <= 255; ansiColor++){ + for (let ansiColor = 16; ansiColor <= 255; ansiColor++) { assert.equal(cm.colors.ansi[ansiColor].css, DEFAULT_ANSI_COLORS[255 + 16 - ansiColor].css); } }); it('should set one extended ansi colors and keep the other default', () => { cm.setTheme({ - extendedAnsi: [ '#ffffff' ] + extendedAnsi: ['#ffffff'] }); assert.equal(cm.colors.ansi[16].css, '#ffffff'); diff --git a/src/browser/ColorManager.ts b/src/browser/ColorManager.ts index 1d1b567229..9eac2f5cc5 100644 --- a/src/browser/ColorManager.ts +++ b/src/browser/ColorManager.ts @@ -168,9 +168,9 @@ export class ColorManager implements IColorManager { this.colors.ansi[14] = this._parseColor(theme.brightCyan, DEFAULT_ANSI_COLORS[14]); this.colors.ansi[15] = this._parseColor(theme.brightWhite, DEFAULT_ANSI_COLORS[15]); if (theme.extendedAnsi) { - const colorCount = Math.max(theme.extendedAnsi.length + 16, 256); - for (let i = 16; i < colorCount; i++) { - this.colors.ansi[i] = this._parseColor(theme.extendedAnsi[i - 16], DEFAULT_ANSI_COLORS[i]); + const colorCount = Math.min(240/* 256 - base 16 */, this.colors.ansi.length - 16); + for (let i = 0; i < colorCount; i++) { + this.colors.ansi[i + 16] = this._parseColor(theme.extendedAnsi[i], DEFAULT_ANSI_COLORS[i + 16]); } } // Clear our the cache From 67f83d51c95ba5eb4cd73a8d1168fbdfce32f633 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 19 Jul 2022 05:58:20 -0700 Subject: [PATCH 2/2] Fix min color count --- src/browser/ColorManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/ColorManager.ts b/src/browser/ColorManager.ts index 9eac2f5cc5..84e5d58d44 100644 --- a/src/browser/ColorManager.ts +++ b/src/browser/ColorManager.ts @@ -168,7 +168,7 @@ export class ColorManager implements IColorManager { this.colors.ansi[14] = this._parseColor(theme.brightCyan, DEFAULT_ANSI_COLORS[14]); this.colors.ansi[15] = this._parseColor(theme.brightWhite, DEFAULT_ANSI_COLORS[15]); if (theme.extendedAnsi) { - const colorCount = Math.min(240/* 256 - base 16 */, this.colors.ansi.length - 16); + const colorCount = Math.min(this.colors.ansi.length - 16, theme.extendedAnsi.length); for (let i = 0; i < colorCount; i++) { this.colors.ansi[i + 16] = this._parseColor(theme.extendedAnsi[i], DEFAULT_ANSI_COLORS[i + 16]); }