Skip to content

Commit

Permalink
fix: add missing ANSI style end code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanga-Ganapathy committed Mar 31, 2024
1 parent 094816f commit 865c532
Show file tree
Hide file tree
Showing 11 changed files with 517 additions and 696 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-phones-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opentf/cli-styles': minor
---

Fixed missing ANSI style end code.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ style('$g.bol{SALE! -} $blk.r.bol{50% OFFER}');
| o | Orange - rgb(255,133,27) |
| y | Yellow - rgb(255,220,0) |
| w | White - rgb(255,255,255) |
| m | Magenta - rgb(255,105,193) |
| bl | Black - rgb(17,17,17) |
| gr | Grey - rgb(170,170,170) |
| navy | Navy - rgb(0,31,63) |
Expand Down
6 changes: 5 additions & 1 deletion __tests__/cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('cases', () => {

it('renders styles with normal $ sign in a text', () => {
expect(style('Price: $8.00 $g.blk{OFFER!}')).toEqual(
'Price: $8.00 \x1B[38;2;46;204;64;5mOFFER!\x1B[0m'
'Price: $8.00 \x1B[38;2;46;204;64m\x1B[5mOFFER!\x1B[0m'
);
});

Expand All @@ -34,4 +34,8 @@ describe('cases', () => {
it('renders $ signs inbetween styles', () => {
expect(style('$$r{\\$}$')).toEqual('$\x1B[38;2;255;65;54m$\x1B[0m$');
});

it('renders dimmed green unicode symbol', () => {
expect(style('$g.dim{➜}')).toEqual('\x1B[38;2;46;204;64m\x1B[2m➜\x1B[0m');
});
});
14 changes: 13 additions & 1 deletion __tests__/colors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('colors', () => {
expect(style('$b{BLUE}')).toEqual('\x1B[38;2;0;116;217mBLUE\x1B[0m');
});

it('renders magenta fg color', () => {
expect(style('$m{Magenta}')).toEqual(
'\x1B[38;2;255;105;193mMagenta\x1B[0m'
);
});

it('renders orange fg color', () => {
expect(style('$o{ORANGE}')).toEqual('\x1B[38;2;255;133;27mORANGE\x1B[0m');
});
Expand Down Expand Up @@ -163,6 +169,12 @@ describe('colors', () => {
);
});

it('renders bg magenta fg color', () => {
expect(style('$bgm{Magenta}')).toEqual(
'\x1B[48;2;255;105;193mMagenta\x1B[0m'
);
});

it('renders multiple fg colors', () => {
expect(style('$r{RED}$g{GREEN}$b{BLUE}')).toEqual(
'\x1B[38;2;255;65;54mRED\x1B[0m\x1B[38;2;46;204;64mGREEN\x1B[0m\x1B[38;2;0;116;217mBLUE\x1B[0m'
Expand All @@ -175,7 +187,7 @@ describe('colors', () => {
"$bgbl.b{THE QUICK $g{BROWN $r{CAT} JUMPED} OVER THE LAZY $r{DOG}'S BACK}"
)
).toEqual(
"\x1B[48;2;17;17;17;38;2;0;116;217mTHE QUICK \x1B[0m\x1B[48;2;17;17;17;38;2;46;204;64mBROWN \x1B[0m\x1B[48;2;17;17;17;38;2;255;65;54mCAT\x1B[0m\x1B[48;2;17;17;17;38;2;46;204;64m JUMPED\x1B[0m\x1B[48;2;17;17;17;38;2;0;116;217m OVER THE LAZY \x1B[0m\x1B[48;2;17;17;17;38;2;255;65;54mDOG\x1B[0m\x1B[48;2;17;17;17;38;2;0;116;217m'S BACK\x1B[0m"
"\x1B[48;2;17;17;17m\x1B[38;2;0;116;217mTHE QUICK \x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;46;204;64mBROWN \x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;255;65;54mCAT\x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;46;204;64m JUMPED\x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;0;116;217m OVER THE LAZY \x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;255;65;54mDOG\x1B[0m\x1B[48;2;17;17;17m\x1B[38;2;0;116;217m'S BACK\x1B[0m"
);
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/modifiers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ afterAll(() => {
describe('Modifiers', () => {
it('renders default style', () => {
expect(style('$r{RED $res{Normal} RED}')).toEqual(
'\x1B[38;2;255;65;54mRED \x1B[0m\x1B[38;2;255;65;54;0mNormal\x1B[0m\x1B[38;2;255;65;54m RED\x1B[0m'
'\x1B[38;2;255;65;54mRED \x1B[0m\x1B[38;2;255;65;54m\x1B[0mNormal\x1B[0m\x1B[38;2;255;65;54m RED\x1B[0m'
);
});

it('renders normal style', () => {
expect(style('$bol{BOLD $nor{NORMAL} BOLD}')).toEqual(
'\x1B[1mBOLD \x1B[0m\x1B[1;22mNORMAL\x1B[0m\x1B[1m BOLD\x1B[0m'
'\x1B[1mBOLD \x1B[0m\x1B[1m\x1B[22mNORMAL\x1B[0m\x1B[1m BOLD\x1B[0m'
);
});

Expand Down
6 changes: 3 additions & 3 deletions demo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { style } from './dist/index.js';
import { style } from './src';
import hljs from 'highlight.js';
import { decode } from 'html-entities';

Expand Down Expand Up @@ -59,7 +59,7 @@ run(
run('$bol{foo $r.dun{bar} $ovl.o{hindi} baz} $und{UNDERLINE}');

run(
'This is a $o.bgbl{Hello World} example, This is a $r.bol{RED} $g.ita{GREEN} $b.str{BLUE} $gr.dim{GREY} $y.und{YELLOW} $w.bgbl.inv{INVERSE} $bol.rgb(57,204,204){TEAL} $bgrgb(133,20,75).w.bol{MAROON} text.'
'This is a $o.bgbl{Hello World} example, This is a $r.bol{RED} $g.ita{GREEN} $b.str{BLUE} $gr.dim{GREY} $y.und{YELLOW} $w.bgbl.inv{INVERSE} $bol.rgb(57,204,204){TEAL} $bgrgb(133,20,75).w.bol{MAROON} $m{Magenta} text.'
);

run(
Expand All @@ -76,7 +76,7 @@ run(

run('$bol.w.bgg{ PASS }');

run('$inv.r.bgw.bol{ FAILED }');
run('$r.bgw.bol.inv{ FAILED }');

run('Normal text | $bol{Bold text} | $dim{Dimmed text}');

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
],
"devDependencies": {
"@changesets/cli": "^2.27.1",
"@commitlint/cli": "^17.6.5",
"@commitlint/config-conventional": "^17.6.5",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@opentf/eslint-config-base": "^0.2.0",
"@swc/core": "^1.4.8",
"@swc/jest": "^0.2.24",
"@types/jest": "^29.5.2",
"@types/node": "^20.11.30",
"@types/node": "^20.12.2",
"eslint": "^8.57.0",
"highlight.js": "^11.9.0",
"html-entities": "^2.5.2",
"husky": "^8.0.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^13.2.2",
"lint-staged": "^15.2.2",
"tsup": "^8.0.2",
"turbo": "^1.13.0",
"typescript": "^5.4.3"
Expand All @@ -80,6 +80,6 @@
"provenance": true
},
"dependencies": {
"@opentf/std": "^0.1.0"
"@opentf/std": "^0.3.0"
}
}

0 comments on commit 865c532

Please sign in to comment.