Skip to content

Commit

Permalink
New: now term.color() and term.bgColor() accepts color names (cronvel#87
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Cédric Ronvel committed Apr 13, 2019
1 parent 14a46d4 commit e0a3ff6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

v1.28.0
-------

New: now term.color() and term.bgColor() accepts color names (#87)


v1.27.3
-------

Expand Down
4 changes: 2 additions & 2 deletions doc/low-level.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ See [the full style markup reference](https://github.com/cronvel/string-kit#ref.
* .brightMagenta(): ...
* .brightCyan(): ...
* .brightWhite(): ...
* .color(register): choose between 16 colors using an 0..15 integer
* .color(register): choose between 16 colors using an 0..15 integer, **it also accepts a color name**
* .darkColor(register): choose between 8 regular (dark) colors using an 0..7 integer
* .brightColor(register): choose between 8 bright colors using an 0..7 integer
* .color256(register): if the terminal support 256 colors, it chooses between them using an 0..255 integer
Expand Down Expand Up @@ -143,7 +143,7 @@ See [the full style markup reference](https://github.com/cronvel/string-kit#ref.
* .bgBrightBlue(): ...
* .bgBrightMagenta(): ...
* .bgBrightCyan(): ...
* .bgColor(register): choose between 16 colors using an 0..15 integer
* .bgColor(register): choose between 16 colors using an 0..15 integer, **it also accepts a color name**
* .bgBrightWhite(): choose between 8 regular (dark) colors using an 0..7 integer
* .bgBrightColor(): choose between 8 bright colors using an 0..7 integer
* .bgColor256(register): if the terminal support 256 colors, it choose between them using an 0..255 integer
Expand Down
2 changes: 2 additions & 0 deletions lib/Terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ var pseudoEsc = {
on: '%[color:%a]F' ,
off: function() { return this.root.esc.defaultColor.on ; } ,
handler: function color( c ) {
if ( typeof c === 'string' ) { c = termkit.colorNameToIndex( c ) ; }
if ( typeof c !== 'number' ) { return '' ; }

c = Math.floor( c ) ;
Expand All @@ -720,6 +721,7 @@ var pseudoEsc = {
on: '%[bgColor:%a]F' ,
off: function() { return this.root.esc.bgDefaultColor.on ; } ,
handler: function bgColor( c ) {
if ( typeof c === 'string' ) { c = termkit.colorNameToIndex( c ) ; }
if ( typeof c !== 'number' ) { return '' ; }

c = Math.floor( c ) ;
Expand Down
2 changes: 2 additions & 0 deletions lib/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const colorNameToIndexDict = {
yellow: 3 ,
blue: 4 ,
magenta: 5 ,
violet: 5 ,
cyan: 6 ,
white: 7 ,
grey: 8 ,
Expand All @@ -54,6 +55,7 @@ const colorNameToIndexDict = {
brightyellow: 11 ,
brightblue: 12 ,
brightmagenta: 13 ,
brightviolet: 13 ,
brightcyan: 14 ,
brightwhite: 15
} ;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "terminal-kit",
"version": "1.27.3",
"version": "1.28.0",
"description": "256 colors, keys and mouse, input field, progress bars, screen buffer (including 32-bit composition and image loading), text buffer, and many more... Whether you just need colors and styles, build a simple interactive command line tool or a complexe terminal app: this is the absolute terminal lib for Node.js!",
"main": "lib/termkit.js",
"directories": {
Expand All @@ -13,9 +13,9 @@
"@cronvel/get-pixels": "^3.3.1",
"lazyness": "^1.1.1",
"ndarray": "^1.0.18",
"nextgen-events": "^1.1.0",
"seventh": "^0.7.18",
"string-kit": "^0.9.2",
"nextgen-events": "^1.1.1",
"seventh": "^0.7.20",
"string-kit": "^0.9.3",
"tree-kit": "^0.6.1"
},
"devDependencies": {},
Expand Down
1 change: 1 addition & 0 deletions sample/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ term.restoreCursor() ;
var toto = term.str.red( 'toto' ) ;
console.log( '\nconsole.log(toto):' , toto ) ;

term.bgColor( 'red' , 'some red?' ) ;
term( '\n' ) ;

0 comments on commit e0a3ff6

Please sign in to comment.