|
5 | 5 |
|
6 | 6 | import { assert, expect } from 'chai'; |
7 | 7 | import { InputHandler } from 'common/InputHandler'; |
8 | | -import { IBufferLine, IAttributeData } from 'common/Types'; |
| 8 | +import { IBufferLine, IAttributeData, IAnsiColorChangeEvent } from 'common/Types'; |
9 | 9 | import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine'; |
10 | 10 | import { CellData } from 'common/buffer/CellData'; |
11 | 11 | import { Attributes, UnderlineStyle } from 'common/buffer/Constants'; |
@@ -40,6 +40,7 @@ class TestInputHandler extends InputHandler { |
40 | 40 | public get curAttrData(): IAttributeData { return (this as any)._curAttrData; } |
41 | 41 | public get windowTitleStack(): string[] { return this._windowTitleStack; } |
42 | 42 | public get iconNameStack(): string[] { return this._iconNameStack; } |
| 43 | + public parseAnsiColorChange(data: string): IAnsiColorChangeEvent | null { return this._parseAnsiColorChange(data); } |
43 | 44 | } |
44 | 45 |
|
45 | 46 | describe('InputHandler', () => { |
@@ -1692,4 +1693,55 @@ describe('InputHandler', () => { |
1692 | 1693 | assert.equal(coreService.decPrivateModes.origin, false); |
1693 | 1694 | }); |
1694 | 1695 | }); |
| 1696 | + describe('OSC', () => { |
| 1697 | + it('4: should parse correct Ansi color change data', () => { |
| 1698 | + // this is testing a private method |
| 1699 | + const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3'); |
| 1700 | + |
| 1701 | + assert.isNotNull(event); |
| 1702 | + assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 }); |
| 1703 | + }), |
| 1704 | + it('4: should ignore incorrect Ansi color change data', () => { |
| 1705 | + // this is testing a private method |
| 1706 | + assert.isNull(inputHandler.parseAnsiColorChange('17;rgb:a/b/c')); |
| 1707 | + assert.isNull(inputHandler.parseAnsiColorChange('17;rgb:#aabbcc')); |
| 1708 | + assert.isNull(inputHandler.parseAnsiColorChange('17;rgba:aa/bb/cc')); |
| 1709 | + assert.isNull(inputHandler.parseAnsiColorChange('rgb:aa/bb/cc')); |
| 1710 | + }); |
| 1711 | + it('4: should parse a list of Ansi color changes', () => { |
| 1712 | + // this is testing a private method |
| 1713 | + const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3;17;rgb:00/11/22;255;rgb:01/ef/2d'); |
| 1714 | + |
| 1715 | + assert.isNotNull(event); |
| 1716 | + assert.equal(event!.colors.length, 3); |
| 1717 | + assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 }); |
| 1718 | + assert.deepEqual(event!.colors[1], { colorIndex: 17, red: 0x00, green: 0x11, blue: 0x22 }); |
| 1719 | + assert.deepEqual(event!.colors[2], { colorIndex: 255, red: 0x01, green: 0xef, blue: 0x2d }); |
| 1720 | + }); |
| 1721 | + it('4: should ignore incorrect colors in a list of Ansi color changes', () => { |
| 1722 | + // this is testing a private method |
| 1723 | + const event = inputHandler.parseAnsiColorChange('19;rgb:a1/b2/c3;17;rgb:WR/ON/G;255;rgb:01/ef/2d'); |
| 1724 | + |
| 1725 | + assert.equal(event!.colors.length, 2); |
| 1726 | + assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 }); |
| 1727 | + assert.deepEqual(event!.colors[1], { colorIndex: 255, red: 0x01, green: 0xef, blue: 0x2d }); |
| 1728 | + }); |
| 1729 | + it('4: should be case insensitive when parsing Ansi color changes', () => { |
| 1730 | + // this is testing a private method |
| 1731 | + const event = inputHandler.parseAnsiColorChange('19;rGb:A1/b2/C3'); |
| 1732 | + |
| 1733 | + assert.equal(event!.colors.length, 1); |
| 1734 | + assert.deepEqual(event!.colors[0], { colorIndex: 19, red: 0xa1, green: 0xb2, blue: 0xc3 }); |
| 1735 | + }); |
| 1736 | + it('4: should fire event on Ansi color change', (done) => { |
| 1737 | + inputHandler.onAnsiColorChange(e => { |
| 1738 | + assert.isNotNull(e); |
| 1739 | + assert.isNotNull(e!.colors); |
| 1740 | + assert.deepEqual(e!.colors[0], { colorIndex: 17, red: 0x1a, green: 0x2b, blue: 0x3c }); |
| 1741 | + assert.deepEqual(e!.colors[1], { colorIndex: 12, red: 0x11, green: 0x22, blue: 0x33 }); |
| 1742 | + done(); |
| 1743 | + }); |
| 1744 | + inputHandler.parse('\x1b]4;17;rgb:1a/2b/3c;12;rgb:11/22/33\x1b\\'); |
| 1745 | + }); |
| 1746 | + }); |
1695 | 1747 | }); |
0 commit comments