Skip to content

Commit

Permalink
Merge pull request #2125 from jerch/2124_fix_colormode_switches
Browse files Browse the repository at this point in the history
fix colormode switches
  • Loading branch information
jerch committed May 24, 2019
2 parents b8f55f1 + c387180 commit bbefedb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,46 @@ describe('InputHandler', () => {
assert.equal(term.curAttrData.getBgColorMode(), 0);
assert.equal(term.curAttrData.getBgColor(), -1);
});
it('colormode transition RGB to 256', () => {
// enter RGB for FG and BG
term.writeSync(`\x1b[38;2;1;2;3;48;2;4;5;6m`);
// enter 256 for FG and BG
term.writeSync(`\x1b[38;5;255;48;5;255m`);
assert.equal(term.curAttrData.getFgColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.getFgColor(), 255);
assert.equal(term.curAttrData.getBgColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.getBgColor(), 255);
});
it('colormode transition RGB to 16', () => {
// enter RGB for FG and BG
term.writeSync(`\x1b[38;2;1;2;3;48;2;4;5;6m`);
// enter 16 for FG and BG
term.writeSync(`\x1b[37;47m`);
assert.equal(term.curAttrData.getFgColorMode(), Attributes.CM_P16);
assert.equal(term.curAttrData.getFgColor(), 7);
assert.equal(term.curAttrData.getBgColorMode(), Attributes.CM_P16);
assert.equal(term.curAttrData.getBgColor(), 7);
});
it('colormode transition 16 to 256', () => {
// enter 16 for FG and BG
term.writeSync(`\x1b[37;47m`);
// enter 256 for FG and BG
term.writeSync(`\x1b[38;5;255;48;5;255m`);
assert.equal(term.curAttrData.getFgColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.getFgColor(), 255);
assert.equal(term.curAttrData.getBgColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.getBgColor(), 255);
});
it('colormode transition 256 to 16', () => {
// enter 256 for FG and BG
term.writeSync(`\x1b[38;5;255;48;5;255m`);
// enter 16 for FG and BG
term.writeSync(`\x1b[37;47m`);
assert.equal(term.curAttrData.getFgColorMode(), Attributes.CM_P16);
assert.equal(term.curAttrData.getFgColor(), 7);
assert.equal(term.curAttrData.getBgColorMode(), Attributes.CM_P16);
assert.equal(term.curAttrData.getBgColor(), 7);
});
it('should zero missing RGB values', () => {
term.writeSync(`\x1b[38;2;1;2;3m`);
term.writeSync(`\x1b[38;2;5m`);
Expand Down
8 changes: 4 additions & 4 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ export class InputHandler extends Disposable implements IInputHandler {
attr.bg &= ~(Attributes.CM_MASK | Attributes.RGB_MASK);
attr.bg |= DEFAULT_ATTR_DATA.bg & (Attributes.PCOLOR_MASK | Attributes.RGB_MASK);
} else if (p === 38) {
// fg color 256
// fg color 256 and RGB
if (params[i + 1] === 2) {
i += 2;
attr.fg |= Attributes.CM_RGB;
Expand All @@ -1703,11 +1703,11 @@ export class InputHandler extends Disposable implements IInputHandler {
} else if (params[i + 1] === 5) {
i += 2;
p = params[i] & 0xff;
attr.fg &= ~Attributes.PCOLOR_MASK;
attr.fg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
attr.fg |= Attributes.CM_P256 | p;
}
} else if (p === 48) {
// bg color 256
// bg color 256 and RGB
if (params[i + 1] === 2) {
i += 2;
attr.bg |= Attributes.CM_RGB;
Expand All @@ -1717,7 +1717,7 @@ export class InputHandler extends Disposable implements IInputHandler {
} else if (params[i + 1] === 5) {
i += 2;
p = params[i] & 0xff;
attr.bg &= ~Attributes.PCOLOR_MASK;
attr.bg &= ~(Attributes.CM_MASK | Attributes.PCOLOR_MASK);
attr.bg |= Attributes.CM_P256 | p;
}
} else if (p === 100) {
Expand Down

0 comments on commit bbefedb

Please sign in to comment.