@@ -37,12 +37,19 @@ for (const s in Styles) styles[s] = (t: string) => `\x1b[${Styles[s]}m${t}\x1b[0
37
37
let keywords = [ ] ;
38
38
for ( const k in Keywords ) keywords [ k ] = ( t : string ) => enabled ? rgb ( Keywords [ k ] , t ) : t ;
39
39
40
+ /**
41
+ * Change the background colour of the given text using CSS keywords (List: https://docs.davidjcralph.co.uk/#/leeks)
42
+ * @param {string } t The text to change the colour of
43
+ */
44
+ let bgKeywords = [ ] ;
45
+ for ( const k in Keywords ) bgKeywords [ k ] = ( t : string ) => enabled ? rgbBg ( Keywords [ k ] , t ) : t ;
46
+
40
47
/**
41
48
* Change the colour of the given text using 8-bit colours
42
49
* @param {string } i The 8-bit colour to use
43
50
* @param {string } t The text to show with the 8-bit colour
44
51
*/
45
- export function eightBit ( i : string , t : string ) {
52
+ export function eightBit ( i : string , t : string ) {
46
53
if ( ! enabled ) return t ;
47
54
return '\033' + `[38;5;${ i } m${ t } \x1b[0m` ;
48
55
}
@@ -52,7 +59,7 @@ export function eightBit (i: string, t: string) {
52
59
* @param {string } i The 8-bit colour to use
53
60
* @param {string } t The text to show with the 8-bit colour
54
61
*/
55
- export function eightBitBg ( i : string , t : string ) {
62
+ export function eightBitBg ( i : string , t : string ) {
56
63
if ( ! enabled ) return t ;
57
64
return '\033' + `[48;5;${ i } m${ t } \x1b[0m` ;
58
65
}
@@ -62,7 +69,7 @@ export function eightBitBg (i: string, t: string) {
62
69
* @param {[number, number, number] } rgb An array of the RGB to use
63
70
* @param {string } t The text to show with the RGB colour
64
71
*/
65
- export function rgb ( rgb : [ number , number , number ] , t : string ) {
72
+ export function rgb ( rgb : [ number , number , number ] , t : string ) {
66
73
if ( ! enabled ) return t ;
67
74
68
75
const [ r , g , b ] = rgb ;
@@ -74,7 +81,7 @@ export function rgb (rgb: [number, number, number], t: string) {
74
81
* @param {[number, number, number] } rgb An array of the RGB to use
75
82
* @param {string } t The text to show with the RGB colour
76
83
*/
77
- export function rgbBg ( rgb : [ number , number , number ] , t : string ) {
84
+ export function rgbBg ( rgb : [ number , number , number ] , t : string ) {
78
85
if ( ! enabled ) return t ;
79
86
80
87
const [ r , g , b ] = rgb ;
@@ -87,7 +94,7 @@ export function rgbBg (rgb: [number, number, number], t: string) {
87
94
* @param {string } t The text to show with the hexadecimal colour
88
95
* @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb)
89
96
*/
90
- export function hex ( hex : string , t : string ) {
97
+ export function hex ( hex : string , t : string ) {
91
98
const bigint = parseInt ( hex . replace ( '#' , '' ) , 16 ) ;
92
99
return rgb ( [ ( bigint >> 16 ) & 255 , ( bigint >> 8 ) & 255 , bigint & 255 ] , t ) ;
93
100
} ;
@@ -98,32 +105,33 @@ export function hex (hex: string, t: string) {
98
105
* @param {string } t The text to show with the hexadecimal colour
99
106
* @credit [Stack Overflow](https://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb)
100
107
*/
101
- export function hexBg ( hex : string , t : string ) {
108
+ export function hexBg ( hex : string , t : string ) {
102
109
const bigint = parseInt ( hex . replace ( '#' , '' ) , 16 ) ;
103
110
return rgbBg ( [ ( bigint >> 16 ) & 255 , ( bigint >> 8 ) & 255 , bigint & 255 ] , t ) ;
104
111
} ;
105
112
106
113
/**
107
114
* Enable colour support for leeks.js
108
115
*/
109
- export function enableColours ( ) {
116
+ export function enableColours ( ) {
110
117
enabled = true ;
111
118
}
112
119
113
120
/**
114
121
* Disable colour support for leeks.js
115
122
*/
116
- export function disableColours ( ) {
123
+ export function disableColours ( ) {
117
124
enabled = false ;
118
125
}
119
126
120
127
export {
121
- colours as colors ,
128
+ colours as colors ,
122
129
supports as supportsColor ,
123
130
supports as supportsColour ,
124
131
enableColours as enableColors ,
125
132
disableColours as disableColors ,
126
133
colours ,
127
134
keywords ,
135
+ bgKeywords ,
128
136
styles
129
137
} ;
0 commit comments