-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: render dimmed text in all teminals & add full support for underl…
…ine text with colors
- Loading branch information
1 parent
27d8fb7
commit 0c179fb
Showing
14 changed files
with
682 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@opentf/cli-styles': minor | ||
--- | ||
|
||
Fixed dim issues in popular terminals & added full support for underline with colors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { style } from '../src/index'; | ||
|
||
beforeAll(() => { | ||
process.env.FORCE_COLOR = 3; | ||
}); | ||
|
||
afterAll(() => { | ||
delete process.env.FORCE_COLOR; | ||
}); | ||
|
||
describe('Dim', () => { | ||
it('renders dim text', () => { | ||
expect(style('$dim{text}')).toEqual('\x1B[2mtext\x1B[0m'); | ||
}); | ||
|
||
it('renders dim text with color', () => { | ||
expect(style('$dim.r{text}')).toEqual( | ||
'\u001B[38;2;127;32;27mtext\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders normal text inside dim', () => { | ||
expect(style('$dim{Some $nor{long} text}')).toEqual( | ||
'\u001B[2mSome \u001B[0m\u001B[2m\u001B[22mlong\u001B[0m\u001B[2m text\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders bold color text inside dim', () => { | ||
expect(style('$dim{Some $bol.y{long} text}')).toEqual( | ||
'\u001B[2mSome \u001B[0m\u001B[1m\u001B[38;2;127;110;0mlong\u001B[0m\u001B[2m text\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders nested dim text with color', () => { | ||
expect(style('$dim.r{Some $g{green} text}')).toEqual( | ||
'\u001B[38;2;127;32;27mSome \u001B[0m\u001B[38;2;23;102;32mgreen\u001B[0m\u001B[38;2;127;32;27m text\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders normal text nested within dim text with color', () => { | ||
expect( | ||
style('$dim.r{Some $g{green text $nor{inside} some text} text}') | ||
).toEqual( | ||
'\u001B[38;2;127;32;27mSome \u001B[0m\u001B[38;2;23;102;32mgreen text \u001B[0m\u001B[38;2;46;204;64m\u001B[22minside\u001B[0m\u001B[38;2;23;102;32m some text\u001B[0m\u001B[38;2;127;32;27m text\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders rgb colored dim text within normal text', () => { | ||
expect(style('Normal $rgb(255, 150, 0).dim{dim text} text')).toEqual( | ||
'Normal \u001B[38;2;127;75;0mdim text\u001B[0m text' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { style } from '../src/index'; | ||
|
||
beforeAll(() => { | ||
process.env.FORCE_COLOR = 3; | ||
}); | ||
|
||
afterAll(() => { | ||
delete process.env.FORCE_COLOR; | ||
}); | ||
|
||
describe('Underline', () => { | ||
it('renders straight underline text', () => { | ||
expect(style('$und{Straight Underline}')).toEqual( | ||
'\x1B[4mStraight Underline\x1B[0m' | ||
); | ||
}); | ||
|
||
it('renders straight underline text with no underline', () => { | ||
expect( | ||
style('$und{Straight $nou{(No underline here)} underline}') | ||
).toEqual( | ||
'\u001B[4mStraight \u001B[0m\u001B[24m(No underline here)\u001B[0m\u001B[4m underline\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders doubly underline text', () => { | ||
expect(style('$dbu{Double underline}')).toEqual( | ||
'\u001B[21mDouble underline\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders curly underline text', () => { | ||
expect(style('$cru{Curly underline}')).toEqual( | ||
'\u001B[4:3mCurly underline\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders dotted underline text', () => { | ||
expect(style('$dou{Dotted underline}')).toEqual( | ||
'\u001B[4:4mDotted underline\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders dashed underline text', () => { | ||
expect(style('$dau{Dashed underline}')).toEqual( | ||
'\u001B[4:5mDashed underline\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders straight colored underline text', () => { | ||
expect(style('$und.ug{Straight underline colored}')).toEqual( | ||
'\u001B[4m\u001B[58:2:0:46:204:64mStraight underline colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders doubly colored underline text', () => { | ||
expect(style('$dbu.uy{Double underline colored}')).toEqual( | ||
'\u001B[21m\u001B[58:2:0:255:220:0mDouble underline colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders curly colored underline text', () => { | ||
expect(style('$cru.ur{Curly underline colored}')).toEqual( | ||
'\u001B[4:3m\u001B[58:2:0:255:65:54mCurly underline colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders dotted colored underline text', () => { | ||
expect(style('$dou.ub{Dotted underline colored}')).toEqual( | ||
'\u001B[4:4m\u001B[58:2:0:0:116:217mDotted underline colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders dashed colored underline text', () => { | ||
expect(style('$dau.uo{Dashed underline colored}')).toEqual( | ||
'\u001B[4:5m\u001B[58:2:0:255:133:27mDashed underline colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders staight rgb colored', () => { | ||
expect( | ||
style('$und.urgb(100,200,255){Straight underline $ug{RGB} colored}') | ||
).toEqual( | ||
'\u001B[4m\u001B[58:2:0:100;200;255mStraight underline \u001B[0m\u001B[4m\u001B[58:2:0:46:204:64mRGB\u001B[0m\u001B[4m\u001B[58:2:0:100;200;255m colored\u001B[0m' | ||
); | ||
}); | ||
|
||
it('renders default colored underline between blue colored text', () => { | ||
expect(style('$und.ub{Straight $ruc{underline reset} colored}')).toEqual( | ||
'\u001B[4m\u001B[58:2:0:0:116:217mStraight \u001B[0m\u001B[4m\u001B[59munderline reset\u001B[0m\u001B[4m\u001B[58:2:0:0:116:217m colored\u001B[0m' | ||
); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.