Skip to content

Commit

Permalink
Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
amorey committed Apr 6, 2024
1 parent 1977e45 commit 1eea7d7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"import": "./dist/main.js",
"require": "./dist/main.cjs"
},
"./colors": {
"import": "./dist/colors.js",
"require": "./dist/colors.cjs"
},
"./plugin": {
"import": "./dist/plugin.js",
"require": "./dist/plugin.cjs"
Expand Down
12 changes: 0 additions & 12 deletions src/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,3 @@ export const eclipse = {
[StandardColorKeys.BrightCyan]: '#00ffff',
[StandardColorKeys.BrightWhite]: '#ffffff',
};

export default {
xtermjs,
vga,
vscode,
windows10,
terminalapp,
putty,
xterm,
ubuntu,
eclipse,
};
12 changes: 12 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ describe('FancyAnsi', () => {
expect(output).toEqual('<span style="font-weight:var(--ansi-bold-font-weight, 600);">bold</span>');
});

it('treats missing code as reset', () => {
const fancyAnsi = new FancyAnsi();
const output = fancyAnsi.toHtml('\x1b[1mon\x1b[moff');
expect(output).toEqual('<span style="font-weight:var(--ansi-bold-font-weight, 600);">on</span>off');
});

it('treats missing codes as reset', () => {
const fancyAnsi = new FancyAnsi();
const output = fancyAnsi.toHtml('\x1b[1mon\x1b[;moff');
expect(output).toEqual('<span style="font-weight:var(--ansi-bold-font-weight, 600);">on</span>off');
});

it('ignores extra reset at start', () => {
const fancyAnsi = new FancyAnsi();
const output = fancyAnsi.toHtml('\x1b[0m\x1b[1mbold\x1b[0m');
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function processSGRPacket(packet: Packet, attrs: StyleAttrs) {
}

packet.text.split(';').forEach((codeStr) => {
const code = parseInt(codeStr, 10);
const code = parseInt(codeStr || '0', 10);

// handle reset
if (code === 0) {
Expand Down
14 changes: 14 additions & 0 deletions src/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ describe('parse', () => {
expect(packets[0].text).toEqual('0');
});

it('returns one packet of kind `SGR` for a string with no escape codes', () => {
const packets = parse('\x1b[m');
expect(packets.length).toEqual(1);
expect(packets[0].kind).toEqual(PacketKind.SGR);
expect(packets[0].text).toEqual('');
});

it('returns one packet of kind `SGR` for a string with semicolon but no codes', () => {
const packets = parse('\x1b[;m');
expect(packets.length).toEqual(1);
expect(packets[0].kind).toEqual(PacketKind.SGR);
expect(packets[0].text).toEqual(';');
});

it('returns packets of kind `OSCURL` for strings with non-SGR, non-OSCURL escape codes', () => {
const packets = parse('\x1b]8;;http://example.com\x07click me\x1b]8;;\x07');
expect(packets.length).toEqual(1);
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import plugin from 'tailwindcss/plugin';

import colors from './colors';
import * as colors from './colors';

/**
* Plugin
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default defineConfig({
lib: {
entry: [
resolve(__dirname, 'src/main.ts'),
resolve(__dirname, 'src/colors.ts'),
resolve(__dirname, 'src/plugin.ts'),
resolve(__dirname, 'src/react.tsx'),
],
Expand Down

0 comments on commit 1eea7d7

Please sign in to comment.