Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more defensive when setting extended ansi colors #3909

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/browser/ColorManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions src/browser/ColorManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(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]);
}
}
// Clear our the cache
Expand Down