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

Underline styles and colors - core part #2751

Merged
merged 9 commits into from
May 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
179 changes: 178 additions & 1 deletion src/InputHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Terminal } from './Terminal';
import { IBufferLine, IAttributeData } from 'common/Types';
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
import { CellData } from 'common/buffer/CellData';
import { Attributes } from 'common/buffer/Constants';
import { Attributes, UnderlineStyle } from 'common/buffer/Constants';
import { AttributeData } from 'common/buffer/AttributeData';
import { Params } from 'common/parser/Params';
import { MockCoreService, MockBufferService, MockDirtyRowService, MockOptionsService, MockLogService, MockCoreMouseService, MockCharsetService, MockUnicodeService } from 'common/TestUtils.test';
Expand Down Expand Up @@ -1445,6 +1445,183 @@ describe('InputHandler', () => {
assert.deepEqual(getLines(term), ['¥¥ ¥¥', '¥¥ ¥', '¥¥ ¥', '¥¥¥¥¥', '']);
});
});
describe('extended underline style support (SGR 4)', () => {
let term: TestTerminal;
beforeEach(() => {
term = new TestTerminal({cols: 10, rows: 5});
});
it('4 | 24', () => {
term.writeSync('\x1b[4m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.SINGLE);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('21 | 24', () => {
term.writeSync('\x1b[21m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DOUBLE);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:1 | 4:0', () => {
term.writeSync('\x1b[4:1m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.SINGLE);
term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
term.writeSync('\x1b[4:1m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.SINGLE);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:2 | 4:0', () => {
term.writeSync('\x1b[4:2m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DOUBLE);
term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
term.writeSync('\x1b[4:2m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DOUBLE);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:3 | 4:0', () => {
term.writeSync('\x1b[4:3m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.CURLY);
term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
term.writeSync('\x1b[4:3m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.CURLY);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:4 | 4:0', () => {
term.writeSync('\x1b[4:4m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DOTTED);
term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
term.writeSync('\x1b[4:4m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DOTTED);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:5 | 4:0', () => {
term.writeSync('\x1b[4:5m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DASHED);
term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
term.writeSync('\x1b[4:5m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DASHED);
term.writeSync('\x1b[24m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.NONE);
});
it('4:x --> 4 should revert to single underline', () => {
term.writeSync('\x1b[4:5m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.DASHED);
term.writeSync('\x1b[4m');
assert.equal(term.curAttrData.getUnderlineStyle(), UnderlineStyle.SINGLE);
});
});
describe('underline colors (SGR 58 & SGR 59)', () => {
let term: TestTerminal;
beforeEach(() => {
term = new TestTerminal({cols: 10, rows: 5});
});
it('defaults to FG color', () => {
for (const s of ['', '\x1b[30m', '\x1b[38;510m', '\x1b[38;2;1;2;3m']) {
term.writeSync(s);
assert.equal(term.curAttrData.getUnderlineColor(), term.curAttrData.getFgColor());
assert.equal(term.curAttrData.getUnderlineColorMode(), term.curAttrData.getFgColorMode());
assert.equal(term.curAttrData.isUnderlineColorRGB(), term.curAttrData.isFgRGB());
assert.equal(term.curAttrData.isUnderlineColorPalette(), term.curAttrData.isFgPalette());
assert.equal(term.curAttrData.isUnderlineColorDefault(), term.curAttrData.isFgDefault());
}
});
it('correctly sets P256/RGB colors', () => {
term.writeSync('\x1b[4m');
term.writeSync('\x1b[58;5;123m');
assert.equal(term.curAttrData.getUnderlineColor(), 123);
assert.equal(term.curAttrData.getUnderlineColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.isUnderlineColorRGB(), false);
assert.equal(term.curAttrData.isUnderlineColorPalette(), true);
assert.equal(term.curAttrData.isUnderlineColorDefault(), false);
term.writeSync('\x1b[58;2::1:2:3m');
assert.equal(term.curAttrData.getUnderlineColor(), (1 << 16) | (2 << 8) | 3);
assert.equal(term.curAttrData.getUnderlineColorMode(), Attributes.CM_RGB);
assert.equal(term.curAttrData.isUnderlineColorRGB(), true);
assert.equal(term.curAttrData.isUnderlineColorPalette(), false);
assert.equal(term.curAttrData.isUnderlineColorDefault(), false);
});
it('P256/RGB persistence', () => {
const cell = new CellData();
term.writeSync('\x1b[4m');
term.writeSync('\x1b[58;5;123m');
assert.equal(term.curAttrData.getUnderlineColor(), 123);
assert.equal(term.curAttrData.getUnderlineColorMode(), Attributes.CM_P256);
assert.equal(term.curAttrData.isUnderlineColorRGB(), false);
assert.equal(term.curAttrData.isUnderlineColorPalette(), true);
assert.equal(term.curAttrData.isUnderlineColorDefault(), false);
term.writeSync('ab');
(term as any)._bufferService.buffers.active.lines.get(0).loadCell(1, cell);
assert.equal(cell.getUnderlineColor(), 123);
assert.equal(cell.getUnderlineColorMode(), Attributes.CM_P256);
assert.equal(cell.isUnderlineColorRGB(), false);
assert.equal(cell.isUnderlineColorPalette(), true);
assert.equal(cell.isUnderlineColorDefault(), false);

term.writeSync('\x1b[4:0m');
assert.equal(term.curAttrData.getUnderlineColor(), term.curAttrData.getFgColor());
assert.equal(term.curAttrData.getUnderlineColorMode(), term.curAttrData.getFgColorMode());
assert.equal(term.curAttrData.isUnderlineColorRGB(), term.curAttrData.isFgRGB());
assert.equal(term.curAttrData.isUnderlineColorPalette(), term.curAttrData.isFgPalette());
assert.equal(term.curAttrData.isUnderlineColorDefault(), term.curAttrData.isFgDefault());
term.writeSync('a');
(term as any)._bufferService.buffers.active.lines.get(0).loadCell(1, cell);
assert.equal(cell.getUnderlineColor(), 123);
assert.equal(cell.getUnderlineColorMode(), Attributes.CM_P256);
assert.equal(cell.isUnderlineColorRGB(), false);
assert.equal(cell.isUnderlineColorPalette(), true);
assert.equal(cell.isUnderlineColorDefault(), false);
(term as any)._bufferService.buffers.active.lines.get(0).loadCell(2, cell);
assert.equal(cell.getUnderlineColor(), term.curAttrData.getFgColor());
assert.equal(cell.getUnderlineColorMode(), term.curAttrData.getFgColorMode());
assert.equal(cell.isUnderlineColorRGB(), term.curAttrData.isFgRGB());
assert.equal(cell.isUnderlineColorPalette(), term.curAttrData.isFgPalette());
assert.equal(cell.isUnderlineColorDefault(), term.curAttrData.isFgDefault());

term.writeSync('\x1b[4m');
term.writeSync('\x1b[58;2::1:2:3m');
assert.equal(term.curAttrData.getUnderlineColor(), (1 << 16) | (2 << 8) | 3);
assert.equal(term.curAttrData.getUnderlineColorMode(), Attributes.CM_RGB);
assert.equal(term.curAttrData.isUnderlineColorRGB(), true);
assert.equal(term.curAttrData.isUnderlineColorPalette(), false);
assert.equal(term.curAttrData.isUnderlineColorDefault(), false);
term.writeSync('a');
term.writeSync('\x1b[24m');
(term as any)._bufferService.buffers.active.lines.get(0).loadCell(1, cell);
assert.equal(cell.getUnderlineColor(), 123);
assert.equal(cell.getUnderlineColorMode(), Attributes.CM_P256);
assert.equal(cell.isUnderlineColorRGB(), false);
assert.equal(cell.isUnderlineColorPalette(), true);
assert.equal(cell.isUnderlineColorDefault(), false);
(term as any)._bufferService.buffers.active.lines.get(0).loadCell(3, cell);
assert.equal(cell.getUnderlineColor(), (1 << 16) | (2 << 8) | 3);
assert.equal(cell.getUnderlineColorMode(), Attributes.CM_RGB);
assert.equal(cell.isUnderlineColorRGB(), true);
assert.equal(cell.isUnderlineColorPalette(), false);
assert.equal(cell.isUnderlineColorDefault(), false);

// eAttrs in buffer pos 0 and 1 should be the same object
assert.equal(
(term as any)._bufferService.buffers.active.lines.get(0)._extendedAttrs[0],
(term as any)._bufferService.buffers.active.lines.get(0)._extendedAttrs[1]
);
// should not have written eAttr for pos 2 in the buffer
assert.equal((term as any)._bufferService.buffers.active.lines.get(0)._extendedAttrs[2], undefined);
// eAttrs in buffer pos 1 and pos 3 must be different objs
assert.notEqual(
(term as any)._bufferService.buffers.active.lines.get(0)._extendedAttrs[1],
(term as any)._bufferService.buffers.active.lines.get(0)._extendedAttrs[3]
);
});
});
describe('DECSTR', () => {
let term: TestTerminal;
beforeEach(() => {
Expand Down
Loading