Last active
November 22, 2018 11:16
-
-
Save elisherer/b76e4ea2671b42492edf74578477aaf0 to your computer and use it in GitHub Desktop.
Revisions
-
elisherer revised this gist
Nov 22, 2018 . No changes.There are no files selected for viewing
-
elisherer renamed this gist
Nov 22, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
elisherer created this gist
Nov 22, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ const c = ((t_mod, t_clr, t_clrm) => (key,txt) => (Array.isArray(key)?key[0]:key).split(' ').reduce((a,k,b,x)=>(x = k.split('.'))&& (a+"\x1b["+(t_mod.hasOwnProperty(x[0])?t_mod[x[0]]:t_clr.hasOwnProperty(x[0])?''+t_clrm[x[1]]+t_clr[x[0]]:'0')+'m'),'') + (txt ? txt + c`` : ''))( { '': 0, reset: 0, bold: 1, dim: 2, italic: 3, underline: 4, blink: 5, inverse: 7, hidden: 8 }, { black: 0, red: 1, green: 2, yellow: 3, blue: 4, magenta: 5, cyan: 6, white: 7 }, { [undefined]: 3, bg: 4, light: 9, bglight: 10 } ); console.log(c("black.light", 'some dim text')); console.log(c("yellow red.bg", 'yellow and red background')); console.log(c`red`+ 'template literals supports' + c``); console.log(`example: ${c`red`}red${c``} ${c`cyan`}cyan${c``}`);