mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-15 05:06:48 +01:00
fdab4e3d84
Use our existing color palette to map to the 16 basic ansi colors. This is backwards-compatible because it aliases the existing color names. Side note: I think the colors in `console.css` for console file rendering are incomplete, but fixing those is out of scope here imo. Before and after: <img width="542" alt="Screenshot 2023-06-28 at 00 26 12" src="https://github.com/go-gitea/gitea/assets/115237/86d41884-bc47-4e85-8aec-621eb7320f0b"> <img width="546" alt="Screenshot 2023-06-28 at 00 28 24" src="https://github.com/go-gitea/gitea/assets/115237/39fa3b37-d49e-49b1-b6bc-390ac8ca24b2"> --------- Co-authored-by: Giteabot <teabot@gitea.io>
22 lines
1.3 KiB
JavaScript
22 lines
1.3 KiB
JavaScript
import {expect, test} from 'vitest';
|
|
import {renderAnsi} from './ansi.js';
|
|
|
|
test('renderAnsi', () => {
|
|
expect(renderAnsi('abc')).toEqual('abc');
|
|
expect(renderAnsi('abc\n')).toEqual('abc');
|
|
expect(renderAnsi('abc\r\n')).toEqual('abc');
|
|
expect(renderAnsi('\r')).toEqual('');
|
|
expect(renderAnsi('\rx\rabc')).toEqual('x\nabc');
|
|
expect(renderAnsi('\rabc\rx\r')).toEqual('abc\nx');
|
|
expect(renderAnsi('\x1b[30mblack\x1b[37mwhite')).toEqual('<span class="ansi-black-fg">black</span><span class="ansi-white-fg">white</span>'); // unclosed
|
|
expect(renderAnsi('<script>')).toEqual('<script>');
|
|
expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2Ktest\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
expect(renderAnsi('\x1b[1A\x1b[2K\rtest\r\x1b[1B\x1b[1A\x1b[2K')).toEqual('test');
|
|
|
|
// treat "\033[0K" and "\033[0J" (Erase display/line) as "\r", then it will be covered to "\n" finally.
|
|
expect(renderAnsi('a\x1b[Kb\x1b[2Jc')).toEqual('a\nb\nc');
|
|
expect(renderAnsi('\x1b[48;5;88ma\x1b[38;208;48;5;159mb\x1b[m')).toEqual(`<span style="background-color:rgb(135,0,0)">a</span><span style="background-color:rgb(175,255,255)">b</span>`);
|
|
});
|