termark 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -20
- package/dist/index.cjs +1 -181
- package/dist/index.d.ts +97 -273
- package/dist/index.mjs +1 -179
- package/dist/util.d.ts +3 -1
- package/package.json +2 -2
package/README.md
CHANGED
@@ -4,9 +4,10 @@ Termark is a basic library to format console output to the standard non-browser
|
|
4
4
|
|
5
5
|
## Features & Highlights
|
6
6
|
|
7
|
-
-
|
7
|
+
- Zero dependencies
|
8
8
|
- [ESM & CJS compatible](#esm--cjs-compatibility)
|
9
9
|
- [NO_COLOR](https://no-color.org/)-friendly
|
10
|
+
- [Default and named imports]
|
10
11
|
- [Basic ANSI styling](#basic-ansi-styling) (`dim`, `bold`, `italic`, …)
|
11
12
|
- [4-bit](#4-bit-colours) ($2^4 = 16$) colours (`red`, `cyan`, `blueBright`, …)
|
12
13
|
- [8-bit](#8-bit-colours) ($2^8 = 256$) colours (`ansi256()`)
|
@@ -15,6 +16,7 @@ Termark is a basic library to format console output to the standard non-browser
|
|
15
16
|
- Built-in [terminal logging methods](#built-in-terminal-logging-methods) (`success()`, `info()`, `warn()`, `error()`)
|
16
17
|
- [Template strings](#template-strings) & [nested styles](#nested-styles) (``` green`Success: File ${cyan`plans.txt`} created successfully!` ```)
|
17
18
|
- [Colour-detection utilities](#colour-detection-utilities) (`areColorsEnabled`, `is8bitEnabled`, `is24bitEnabled`)
|
19
|
+
- [Usage as an object or as a class](#class-v-object)
|
18
20
|
|
19
21
|
## Installation
|
20
22
|
|
@@ -34,6 +36,24 @@ const termark = require('termark');
|
|
34
36
|
import termark from 'termark';
|
35
37
|
```
|
36
38
|
|
39
|
+
## Default & named imports
|
40
|
+
|
41
|
+
Termark offers both a default import that has access to all properties and methods, or you can import each one individually:
|
42
|
+
|
43
|
+
```ts
|
44
|
+
// Default import:
|
45
|
+
import termark from 'termark';
|
46
|
+
|
47
|
+
termark.info('This is the default import, where all properties and methods are accessible.');
|
48
|
+
|
49
|
+
// Named imports:
|
50
|
+
import { success, inverse } from 'termark';
|
51
|
+
|
52
|
+
success(
|
53
|
+
inverse('This text with a green background is achieved with named imports!')
|
54
|
+
)
|
55
|
+
```
|
56
|
+
|
37
57
|
## Usage
|
38
58
|
|
39
59
|
Here's a quick reference for every feature Termark provides:
|
@@ -140,6 +160,8 @@ termark.rgb('text', convert.hex.rgb('008330'))('...');
|
|
140
160
|
|
141
161
|
### Gradients
|
142
162
|
|
163
|
+
**Please note that gradients do not support nested styling.**
|
164
|
+
|
143
165
|
```ts
|
144
166
|
import termark from 'termark';
|
145
167
|
|
@@ -147,25 +169,6 @@ termark.gradient('text', [[200, 123, 0], [0, 255, 255], [177, 209, 10]])('...');
|
|
147
169
|
termark.gradient('background', [[123, 75, 204], [255, 255, 255], [0, 44, 55]])('...');
|
148
170
|
```
|
149
171
|
|
150
|
-
The way this works is as follows:
|
151
|
-
|
152
|
-
We have two colours $C_1 = (R_1,G_1,B_1)$ and $C_2 = (R_2,G_2,B_2)$, and we need to generate a gradient over a string of length $L$.
|
153
|
-
For each character at index $i$ (from 0 to $L-1$), we need to find an interpolated colour $C_i$.
|
154
|
-
For that, we can do the following:
|
155
|
-
|
156
|
-
$$
|
157
|
-
\begin{align*}
|
158
|
-
t &= \frac{i}{L-1} \\\\
|
159
|
-
R_i &= R_1 + t \times (R_2 - R_1) \\
|
160
|
-
G_i &= G_1 + t \times (G_2 - G_1) \\
|
161
|
-
B_i &= B_1 + t \times (B_2 - B_1)
|
162
|
-
\end{align*}
|
163
|
-
$$
|
164
|
-
|
165
|
-
We then apply $C_i$ to each character $i$ to get our (mostly) smooth gradient.
|
166
|
-
|
167
|
-
**Please note that gradients do not support nested styling.**
|
168
|
-
|
169
172
|
### Built-in terminal logging methods
|
170
173
|
|
171
174
|
```ts
|
@@ -217,6 +220,22 @@ termark.is8bitEnabled; // Check whether 8-bit (256) colours are enabled.
|
|
217
220
|
termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled.
|
218
221
|
```
|
219
222
|
|
223
|
+
### Class v. Object
|
224
|
+
|
225
|
+
You can use Termark by importing the object, or you can import the class:
|
226
|
+
|
227
|
+
```ts
|
228
|
+
import { Termark } from 'termark';
|
229
|
+
|
230
|
+
const termark = new Termark(); // This is the same as importing the `termark` object.
|
231
|
+
termark.success('Termark is working!');
|
232
|
+
|
233
|
+
// Alternatively, you could do this:
|
234
|
+
Termark.init.success('This work, too!');
|
235
|
+
```
|
236
|
+
|
237
|
+
`Termark.init` enables using the `Termark` class as the default `termark` object.
|
238
|
+
|
220
239
|
## Licence
|
221
240
|
|
222
241
|
Termark's code is licenced under the [Apache licence version 2](https://www.apache.org/licenses/LICENSE-2.0).
|
package/dist/index.cjs
CHANGED
@@ -1,181 +1 @@
|
|
1
|
-
|
2
|
-
Copyright 2025 Q
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
'use strict';
|
18
|
-
|
19
|
-
const areColoursEnabled = () => {
|
20
|
-
const noColour = process.env.NO_COLOR;
|
21
|
-
return noColour ? false : true;
|
22
|
-
};
|
23
|
-
const getColourSupport = () => {
|
24
|
-
const colourTerm = process.env.COLORTERM;
|
25
|
-
const is16bit = colourTerm ? (colourTerm.includes('ansi') && !(colourTerm.includes('256'))) : false;
|
26
|
-
const is256 = colourTerm ? colourTerm.includes('ansi256') : false;
|
27
|
-
const isTrueColor = colourTerm ? (colourTerm.includes('truecolor') || colourTerm.includes('24bit')) : false;
|
28
|
-
return {
|
29
|
-
is16bit,
|
30
|
-
is256,
|
31
|
-
isTrueColor
|
32
|
-
};
|
33
|
-
};
|
34
|
-
function format(open, close, type) {
|
35
|
-
if (type === 'color' && !areColoursEnabled())
|
36
|
-
return (input) => input.toString();
|
37
|
-
const opener = `\x1b[${open}m`;
|
38
|
-
const closer = `\x1b[${close}m`;
|
39
|
-
return (input$1) => {
|
40
|
-
const input = input$1.toString().trim();
|
41
|
-
const index = input.indexOf(closer);
|
42
|
-
if (index === -1)
|
43
|
-
return `${opener}${input}${closer}`;
|
44
|
-
return `${opener}${input.replaceAll(closer, closer + opener)}${closer}`;
|
45
|
-
};
|
46
|
-
}
|
47
|
-
function interpolate(color1, color2, factor) {
|
48
|
-
return [
|
49
|
-
Math.round(color1[0] + factor * (color2[0] - color1[0])),
|
50
|
-
Math.round(color1[1] + factor * (color2[1] - color1[1])),
|
51
|
-
Math.round(color1[2] + factor * (color2[2] - color1[2])),
|
52
|
-
];
|
53
|
-
}
|
54
|
-
|
55
|
-
const termark = {
|
56
|
-
areColorsEnabled: areColoursEnabled(),
|
57
|
-
is8bitEnabled: getColourSupport().is256,
|
58
|
-
is24bitEnabled: getColourSupport().isTrueColor,
|
59
|
-
reset: format(0, 0, 'format'),
|
60
|
-
bold: format(1, 22, 'format'),
|
61
|
-
dim: format(2, 22, 'format'),
|
62
|
-
italic: format(3, 23, 'format'),
|
63
|
-
underline: format(4, 24, 'format'),
|
64
|
-
blink: format(5, 25, 'format'),
|
65
|
-
inverse: format(7, 27, 'format'),
|
66
|
-
overline: format(53, 55, 'format'),
|
67
|
-
hidden: format(8, 28, 'format'),
|
68
|
-
strike: format(9, 29, 'format'),
|
69
|
-
black: format(30, 39, 'color'),
|
70
|
-
red: format(31, 39, 'color'),
|
71
|
-
green: format(32, 39, 'color'),
|
72
|
-
yellow: format(33, 39, 'color'),
|
73
|
-
blue: format(34, 39, 'color'),
|
74
|
-
magenta: format(35, 39, 'color'),
|
75
|
-
cyan: format(36, 39, 'color'),
|
76
|
-
white: format(37, 39, 'color'),
|
77
|
-
blackBright: format(90, 39, 'color'),
|
78
|
-
redBright: format(91, 39, 'color'),
|
79
|
-
greenBright: format(92, 39, 'color'),
|
80
|
-
yellowBright: format(93, 39, 'color'),
|
81
|
-
blueBright: format(94, 39, 'color'),
|
82
|
-
magentaBright: format(95, 39, 'color'),
|
83
|
-
cyanBright: format(96, 39, 'color'),
|
84
|
-
whiteBright: format(97, 39, 'color'),
|
85
|
-
bgBlack: format(40, 49, 'color'),
|
86
|
-
bgRed: format(41, 49, 'color'),
|
87
|
-
bgGreen: format(42, 49, 'color'),
|
88
|
-
bgYellow: format(43, 49, 'color'),
|
89
|
-
bgBlue: format(44, 49, 'color'),
|
90
|
-
bgMagenta: format(45, 49, 'color'),
|
91
|
-
bgCyan: format(46, 49, 'color'),
|
92
|
-
bgWhite: format(47, 49, 'color'),
|
93
|
-
bgBlackBright: format(100, 49, 'color'),
|
94
|
-
bgRedBright: format(101, 49, 'color'),
|
95
|
-
bgGreenBright: format(102, 49, 'color'),
|
96
|
-
bgYellowBright: format(103, 49, 'color'),
|
97
|
-
bgBlueBright: format(104, 49, 'color'),
|
98
|
-
bgMagentaBright: format(105, 49, 'color'),
|
99
|
-
bgCyanBright: format(106, 49, 'color'),
|
100
|
-
bgWhiteBright: format(107, 49, 'color'),
|
101
|
-
ansi256(type, color) {
|
102
|
-
if (color < 0 || color > 255)
|
103
|
-
throw new Error(termark.red('Value `color` is out of range! The value must be a number between 0 and 255!'));
|
104
|
-
if (!getColourSupport().is256 || !areColoursEnabled())
|
105
|
-
return (input) => input.toString();
|
106
|
-
const textFormat = `38;5;${color}`;
|
107
|
-
const bgFormat = `48;5;${color}`;
|
108
|
-
const opener = type === 'text' ? textFormat : bgFormat;
|
109
|
-
const closer = type === 'text' ? 39 : 49;
|
110
|
-
return format(opener, closer, 'color');
|
111
|
-
},
|
112
|
-
rgb(type, ...rgb) {
|
113
|
-
let red;
|
114
|
-
let green;
|
115
|
-
let blue;
|
116
|
-
if (Array.isArray(rgb[0])) {
|
117
|
-
red = rgb[0][0];
|
118
|
-
green = rgb[0][1];
|
119
|
-
blue = rgb[0][2];
|
120
|
-
}
|
121
|
-
else {
|
122
|
-
red = rgb[0];
|
123
|
-
green = rgb[1];
|
124
|
-
blue = rgb[2];
|
125
|
-
}
|
126
|
-
if (((typeof red === 'number') && (red < 0 || red > 255)) ||
|
127
|
-
((typeof green === 'number') && (green < 0 || green > 255)) ||
|
128
|
-
((typeof blue === 'number') && (blue < 0 || blue > 255)))
|
129
|
-
throw new Error(termark.red('One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!'));
|
130
|
-
if (!getColourSupport().isTrueColor)
|
131
|
-
return (input) => input.toString();
|
132
|
-
const textFormat = `38;2;${red};${green};${blue}`;
|
133
|
-
const bgFormat = `48;2;${red};${green};${blue}`;
|
134
|
-
const opener = type === 'text' ? textFormat : bgFormat;
|
135
|
-
const closer = type === 'text' ? 39 : 49;
|
136
|
-
return format(opener, closer, 'color');
|
137
|
-
},
|
138
|
-
gradient(type, colors) {
|
139
|
-
if (!areColoursEnabled() || !getColourSupport().isTrueColor)
|
140
|
-
return (input) => input.toString();
|
141
|
-
const textFormat = `38;2;`;
|
142
|
-
const bgFormat = `48;2;`;
|
143
|
-
const opener = type === 'text' ? `\x1b[${textFormat}` : `\x1b[${bgFormat}`;
|
144
|
-
const closer = type === 'text' ? `\x1b[${39}m` : `\x1b[${49}m`;
|
145
|
-
return (input$1) => {
|
146
|
-
const input = input$1.toString().trim();
|
147
|
-
const colourCount = colors.length;
|
148
|
-
const step = Math.min(input.length / (colourCount - 1));
|
149
|
-
let result = '';
|
150
|
-
for (let character = 0; character < input.length; character++) {
|
151
|
-
const colourIndex = Math.min(Math.floor(character / step), colourCount - 2);
|
152
|
-
const factor = (character % step) / step;
|
153
|
-
const startColour = colors[colourIndex];
|
154
|
-
const endColour = colors[colourIndex + 1];
|
155
|
-
const interpolatedColour = interpolate(startColour, endColour, factor);
|
156
|
-
result += `${opener}${interpolatedColour[0]};${interpolatedColour[1]};${interpolatedColour[2]}m${input[character]}${closer}`;
|
157
|
-
}
|
158
|
-
return result;
|
159
|
-
};
|
160
|
-
},
|
161
|
-
success(message, prefix = '') {
|
162
|
-
console.info(`${prefix}${termark.green(message)}`);
|
163
|
-
},
|
164
|
-
info(message, prefix = '') {
|
165
|
-
console.info(`${prefix}${termark.blue(message)}`);
|
166
|
-
},
|
167
|
-
warn(message, prefix = '') {
|
168
|
-
console.warn(`${prefix}${termark.yellow(message)}`);
|
169
|
-
},
|
170
|
-
error(message, prefix = '') {
|
171
|
-
console.error(`${prefix}${termark.red(message)}`);
|
172
|
-
},
|
173
|
-
custom(opener, closer, type) {
|
174
|
-
const formatType = type === 'asColor' ? 'color' : 'format';
|
175
|
-
return format(opener, closer, formatType);
|
176
|
-
},
|
177
|
-
};
|
178
|
-
|
179
|
-
module.exports = termark;
|
180
|
-
|
181
|
-
// Copyright (C) 2025 Q
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const r=()=>!process.env.NO_COLOR,t=()=>{const r=process.env.COLORTERM;return{is16bit:!!r&&(r.includes("ansi")&&!r.includes("256")),is256:!!r&&r.includes("ansi256"),isTrueColor:!!r&&(r.includes("truecolor")||r.includes("24bit"))}};function e(t,e,o){if("color"===o&&!r())return r=>r.toString();const i=`[${t}m`,s=`[${e}m`;return r=>{const t=r.toString().trim();return-1===t.indexOf(s)?`${i}${t}${s}`:`${i}${t.replaceAll(s,s+i)}${s}`}}function o(r,t,e){return[Math.round(r[0]+e*(t[0]-r[0])),Math.round(r[1]+e*(t[1]-r[1])),Math.round(r[2]+e*(t[2]-r[2]))]}class i{constructor(){this.areColorsEnabled=r(),this.is8bitEnabled=t().is256,this.is24bitEnabled=t().isTrueColor,this.reset=e(0,0,"format"),this.bold=e(1,22,"format"),this.dim=e(2,22,"format"),this.italic=e(3,23,"format"),this.underline=e(4,24,"format"),this.blink=e(5,25,"format"),this.inverse=e(7,27,"format"),this.overline=e(53,55,"format"),this.hidden=e(8,28,"format"),this.strike=e(9,29,"format"),this.black=e(30,39,"color"),this.red=e(31,39,"color"),this.green=e(32,39,"color"),this.yellow=e(33,39,"color"),this.blue=e(34,39,"color"),this.magenta=e(35,39,"color"),this.cyan=e(36,39,"color"),this.white=e(37,39,"color"),this.blackBright=e(90,39,"color"),this.redBright=e(91,39,"color"),this.greenBright=e(92,39,"color"),this.yellowBright=e(93,39,"color"),this.blueBright=e(94,39,"color"),this.magentaBright=e(95,39,"color"),this.cyanBright=e(96,39,"color"),this.whiteBright=e(97,39,"color"),this.bgBlack=e(40,49,"color"),this.bgRed=e(41,49,"color"),this.bgGreen=e(42,49,"color"),this.bgYellow=e(43,49,"color"),this.bgBlue=e(44,49,"color"),this.bgMagenta=e(45,49,"color"),this.bgCyan=e(46,49,"color"),this.bgWhite=e(47,49,"color"),this.bgBlackBright=e(100,49,"color"),this.bgRedBright=e(101,49,"color"),this.bgGreenBright=e(102,49,"color"),this.bgYellowBright=e(103,49,"color"),this.bgBlueBright=e(104,49,"color"),this.bgMagentaBright=e(105,49,"color"),this.bgCyanBright=e(106,49,"color"),this.bgWhiteBright=e(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(o,s){if(s<0||s>255)throw new Error(i.init.red("Value `color` is out of range! The value must be a number between 0 and 255!"));if(!t().is256||!r())return r=>r.toString();return e("text"===o?`38;5;${s}`:`48;5;${s}`,"text"===o?39:49,"color")}rgb(r,...o){let s,n,l;if(Array.isArray(o[0])?(s=o[0][0],n=o[0][1],l=o[0][2]):(s=o[0],n=o[1],l=o[2]),"number"==typeof s&&(s<0||s>255)||"number"==typeof n&&(n<0||n>255)||"number"==typeof l&&(l<0||l>255))throw new Error(i.init.red("One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!"));if(!t().isTrueColor)return r=>r.toString();return e("text"===r?`38;2;${s};${n};${l}`:`48;2;${s};${n};${l}`,"text"===r?39:49,"color")}gradient(e,i){if(!r()||!t().isTrueColor)return r=>r.toString();const s="text"===e?"[38;2;":"[48;2;",n="text"===e?"[39m":"[49m";return r=>{const t=r.toString().trim(),e=i.length,l=Math.min(t.length/(e-1));let g="";for(let r=0;r<t.length;r++){const h=Math.min(Math.floor(r/l),e-2),a=r%l/l,c=o(i[h],i[h+1],a);g+=`${s}${c[0]};${c[1]};${c[2]}m${t[r]}${n}`}return g}}success(r,t=""){console.info(`${t}${i.init.green(r)}`)}info(r,t=""){console.info(`${t}${i.init.blue(r)}`)}warn(r,t=""){console.warn(`${t}${i.init.yellow(r)}`)}error(r,t=""){console.error(`${t}${i.init.red(r)}`)}custom(r,t,o){return e(r,t,"asColor"===o?"color":"format")}}i.termarkInstance=i;const s=new i,{areColorsEnabled:n,is8bitEnabled:l,is24bitEnabled:g,reset:h,bold:a,dim:c,italic:b,underline:u,blink:p,inverse:x,overline:B,hidden:d,strike:m,black:f,red:w,green:$,yellow:y,blue:k,magenta:C,cyan:M,white:E,blackBright:v,redBright:R,greenBright:O,yellowBright:T,blueBright:G,magentaBright:S,cyanBright:W,whiteBright:Y,bgBlack:A,bgRed:_,bgGreen:I,bgYellow:L,bgBlue:j,bgMagenta:N,bgCyan:P,bgWhite:V,bgBlackBright:q,bgRedBright:z,bgGreenBright:D,bgYellowBright:F,bgBlueBright:H,bgMagentaBright:J,bgCyanBright:K,bgWhiteBright:Q,ansi256:U,rgb:X,gradient:Z,success:rr,info:tr,warn:er,error:or,custom:ir}=s;exports.Termark=i,exports.ansi256=U,exports.areColorsEnabled=n,exports.bgBlack=A,exports.bgBlackBright=q,exports.bgBlue=j,exports.bgBlueBright=H,exports.bgCyan=P,exports.bgCyanBright=K,exports.bgGreen=I,exports.bgGreenBright=D,exports.bgMagenta=N,exports.bgMagentaBright=J,exports.bgRed=_,exports.bgRedBright=z,exports.bgWhite=V,exports.bgWhiteBright=Q,exports.bgYellow=L,exports.bgYellowBright=F,exports.black=f,exports.blackBright=v,exports.blink=p,exports.blue=k,exports.blueBright=G,exports.bold=a,exports.custom=ir,exports.cyan=M,exports.cyanBright=W,exports.default=s,exports.dim=c,exports.error=or,exports.gradient=Z,exports.green=$,exports.greenBright=O,exports.hidden=d,exports.info=tr,exports.inverse=x,exports.is24bitEnabled=g,exports.is8bitEnabled=l,exports.italic=b,exports.magenta=C,exports.magentaBright=S,exports.overline=B,exports.red=w,exports.redBright=R,exports.reset=h,exports.rgb=X,exports.strike=m,exports.success=rr,exports.underline=u,exports.warn=er,exports.white=E,exports.whiteBright=Y,exports.yellow=y,exports.yellowBright=T;
|
package/dist/index.d.ts
CHANGED
@@ -1,318 +1,137 @@
|
|
1
|
+
import { ANSIStyleType, RGB } from './util';
|
1
2
|
/**
|
2
|
-
*
|
3
|
+
* The `Termark` class is almost the same as the {@linkcode termark} object and by using `Termark.init`, it effectively does become the same.
|
4
|
+
*
|
5
|
+
* However, it is nonetheless useful as it enables type-safety,
|
6
|
+
*
|
7
|
+
* You use this class the same way as you would the {@linkcode termark} object.
|
8
|
+
*
|
9
|
+
* @example
|
10
|
+
* ```typescript
|
11
|
+
* import { Termark } from 'termark';
|
12
|
+
*
|
13
|
+
* const termark = new Termark(); // This is the same as if you'd import the `termark` object.
|
14
|
+
* termark.success('Termark is working!');
|
15
|
+
*
|
16
|
+
* // Alternatively, you could do:
|
17
|
+
* Termark.init.success('This works, too!');
|
18
|
+
* ```
|
19
|
+
*
|
20
|
+
* @see The {@linkcode termark} object.
|
3
21
|
*/
|
4
|
-
|
22
|
+
export declare class Termark {
|
5
23
|
/**
|
6
|
-
*
|
24
|
+
* A reference to a Termark instance.
|
7
25
|
*
|
8
|
-
*
|
26
|
+
* This is an object that holds the properties defined below.
|
9
27
|
*/
|
10
|
-
|
28
|
+
private static termarkInstance;
|
11
29
|
/**
|
12
|
-
*
|
30
|
+
* A static getter function that returns a Termark reference object.
|
13
31
|
*
|
14
|
-
*
|
15
|
-
*/
|
16
|
-
is8bitEnabled: boolean;
|
17
|
-
/**
|
18
|
-
* Check whether 24-bit colours (truecolor) are enabled.
|
32
|
+
* With this method, it's possible to use the `Termark` class like an object.
|
19
33
|
*
|
20
|
-
* @
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
* Reset all formatting of some text.
|
34
|
+
* @example
|
35
|
+
* ```typescript
|
36
|
+
* import { Termark } from 'termark';
|
37
|
+
* Termark.init.success('...');
|
25
38
|
*
|
26
|
-
*
|
27
|
-
* @returns The formatted text.
|
28
|
-
*/
|
29
|
-
reset: (input: string | TemplateStringsArray) => string;
|
30
|
-
/**
|
31
|
-
* Make some text bold.
|
39
|
+
* // ...is the same as:
|
32
40
|
*
|
33
|
-
*
|
34
|
-
*
|
41
|
+
* import termark from 'termark';
|
42
|
+
* termark.success('...');
|
43
|
+
* ```
|
35
44
|
*/
|
45
|
+
static get init(): Termark;
|
46
|
+
/** Check whether terminal colours are enabled. */
|
47
|
+
areColorsEnabled: boolean;
|
48
|
+
/** Check whether 8-bit colours are enabled. */
|
49
|
+
is8bitEnabled: boolean;
|
50
|
+
/** Check whether 24-bit colours are enabled. */
|
51
|
+
is24bitEnabled: boolean;
|
52
|
+
/** Reset all styles. */
|
53
|
+
reset: (input: string | TemplateStringsArray) => string;
|
54
|
+
/** Make some text bold. */
|
36
55
|
bold: (input: string | TemplateStringsArray) => string;
|
37
|
-
/**
|
38
|
-
* Make some text thinner.
|
39
|
-
*
|
40
|
-
* @param input The text to format.
|
41
|
-
* @returns The text in thinner letters.
|
42
|
-
*/
|
56
|
+
/** Make some text thin. */
|
43
57
|
dim: (input: string | TemplateStringsArray) => string;
|
44
|
-
/**
|
45
|
-
* Make some text italic. May not be widely supported.
|
46
|
-
*
|
47
|
-
* @param input The text to format.
|
48
|
-
* @returns The text with italicized (usually slanted) letters.
|
49
|
-
*/
|
58
|
+
/** Make some text italic. May not be widely supported. */
|
50
59
|
italic: (input: string | TemplateStringsArray) => string;
|
51
|
-
/**
|
52
|
-
* Underline some text.
|
53
|
-
*
|
54
|
-
* @param input The text to format.
|
55
|
-
* @returns The underlined text.
|
56
|
-
*/
|
60
|
+
/** Underline some text. */
|
57
61
|
underline: (input: string | TemplateStringsArray) => string;
|
58
|
-
/**
|
59
|
-
* Make some text blink slowly.
|
60
|
-
*
|
61
|
-
* @param input The text to format.
|
62
|
-
* @returns The blinking text.
|
63
|
-
*/
|
62
|
+
/** Make some text blink slowly. */
|
64
63
|
blink: (input: string | TemplateStringsArray) => string;
|
65
|
-
/**
|
66
|
-
* Invert some text (foreground colour becomes background colour, background colour becomes foreground colour).
|
67
|
-
*
|
68
|
-
* @param input The text to format.
|
69
|
-
* @returns The inverted text.
|
70
|
-
*/
|
64
|
+
/** Invert some text (foreground colour becomes background colour, background colour becomes foreground colour). */
|
71
65
|
inverse: (input: string | TemplateStringsArray) => string;
|
72
|
-
/**
|
73
|
-
* Add a line above some text (may not be widely supported).
|
74
|
-
*
|
75
|
-
* @param input The text to format.
|
76
|
-
* @returns The text with a line above it.
|
77
|
-
*/
|
66
|
+
/** Add a line above some text. May not be widely supported. */
|
78
67
|
overline: (input: string | TemplateStringsArray) => string;
|
79
|
-
/**
|
80
|
-
* Hide some text (may not be widely supported).
|
81
|
-
*
|
82
|
-
* @param input The text to format.
|
83
|
-
* @returns The hidden text.
|
84
|
-
*/
|
68
|
+
/** Visually hide some text. */
|
85
69
|
hidden: (input: string | TemplateStringsArray) => string;
|
86
|
-
/**
|
87
|
-
* Add a line through (strike) some text.
|
88
|
-
*
|
89
|
-
* @param input The text to format.
|
90
|
-
* @returns The striked text.
|
91
|
-
*/
|
70
|
+
/** Add a line through (strike) some text. */
|
92
71
|
strike: (input: string | TemplateStringsArray) => string;
|
93
|
-
/**
|
94
|
-
* Make some text black.
|
95
|
-
*
|
96
|
-
* @param input The text to colour.
|
97
|
-
* @returns If colours are enabled, `input` coloured black.
|
98
|
-
*/
|
72
|
+
/** Colour some text black. */
|
99
73
|
black: (input: string | TemplateStringsArray) => string;
|
100
|
-
/**
|
101
|
-
* Make some text red.
|
102
|
-
*
|
103
|
-
* @param input The text to colour.
|
104
|
-
* @returns If colours are enabled, `input` coloured red.
|
105
|
-
*/
|
74
|
+
/** Colour some text red. */
|
106
75
|
red: (input: string | TemplateStringsArray) => string;
|
107
|
-
/**
|
108
|
-
* Make some text green.
|
109
|
-
*
|
110
|
-
* @param input The text to colour.
|
111
|
-
* @returns If colours are enabled, `input` coloured green.
|
112
|
-
*/
|
76
|
+
/** Colour some text green. */
|
113
77
|
green: (input: string | TemplateStringsArray) => string;
|
114
|
-
/**
|
115
|
-
* Make some text yellow.
|
116
|
-
*
|
117
|
-
* @param input The text to colour.
|
118
|
-
* @returns If colours are enabled, `input` coloured yellow.
|
119
|
-
*/
|
78
|
+
/** Colour some text yellow. */
|
120
79
|
yellow: (input: string | TemplateStringsArray) => string;
|
121
|
-
/**
|
122
|
-
* Make some text blue.
|
123
|
-
*
|
124
|
-
* @param input The text to colour.
|
125
|
-
* @returns If colours are enabled, `input` coloured blue.
|
126
|
-
*/
|
80
|
+
/** Colour some text blue. */
|
127
81
|
blue: (input: string | TemplateStringsArray) => string;
|
128
|
-
/**
|
129
|
-
* Make some text magenta.
|
130
|
-
*
|
131
|
-
* @param input The text to colour.
|
132
|
-
* @returns If colours are enabled, `input` coloured magenta.
|
133
|
-
*/
|
82
|
+
/** Colour some text magenta. */
|
134
83
|
magenta: (input: string | TemplateStringsArray) => string;
|
135
|
-
/**
|
136
|
-
* Make some text cyan.
|
137
|
-
*
|
138
|
-
* @param input The text to colour.
|
139
|
-
* @returns If colours are enabled, `input` coloured cyan.
|
140
|
-
*/
|
84
|
+
/** Colour some text cyan. */
|
141
85
|
cyan: (input: string | TemplateStringsArray) => string;
|
142
|
-
/**
|
143
|
-
* Make some text white.
|
144
|
-
*
|
145
|
-
* @param input The text to colour.
|
146
|
-
* @returns If colours are enabled, `input` coloured white.
|
147
|
-
*/
|
86
|
+
/** Colour some text white. */
|
148
87
|
white: (input: string | TemplateStringsArray) => string;
|
149
|
-
/**
|
150
|
-
* Make some text bright black (grey).
|
151
|
-
*
|
152
|
-
* @param input The text to colour.
|
153
|
-
* @returns If colours are enabled, `input` coloured bright black (grey).
|
154
|
-
*/
|
88
|
+
/** Colour some text bright black (grey). */
|
155
89
|
blackBright: (input: string | TemplateStringsArray) => string;
|
156
|
-
/**
|
157
|
-
* Make some text bright red.
|
158
|
-
*
|
159
|
-
* @param input The text to colour.
|
160
|
-
* @returns If colours are enabled, `input` coloured bright red.
|
161
|
-
*/
|
90
|
+
/** Colour some text bright red. */
|
162
91
|
redBright: (input: string | TemplateStringsArray) => string;
|
163
|
-
/**
|
164
|
-
* Make some text bright green.
|
165
|
-
*
|
166
|
-
* @param input The text to colour.
|
167
|
-
* @returns If colours are enabled, `input` coloured bright green.
|
168
|
-
*/
|
92
|
+
/** Colour some text bright green. */
|
169
93
|
greenBright: (input: string | TemplateStringsArray) => string;
|
170
|
-
/**
|
171
|
-
* Make some text bright yellow.
|
172
|
-
*
|
173
|
-
* @param input The text to colour.
|
174
|
-
* @returns If colours are enabled, `input` coloured bright yellow.
|
175
|
-
*/
|
94
|
+
/** Colour some text bright yellow. */
|
176
95
|
yellowBright: (input: string | TemplateStringsArray) => string;
|
177
|
-
/**
|
178
|
-
* Make some text bright blue.
|
179
|
-
*
|
180
|
-
* @param input The text to colour.
|
181
|
-
* @returns If colours are enabled, `input` coloured bright blue.
|
182
|
-
*/
|
96
|
+
/** Colour some text bright blue. */
|
183
97
|
blueBright: (input: string | TemplateStringsArray) => string;
|
184
|
-
/**
|
185
|
-
* Make some text bright magenta.
|
186
|
-
*
|
187
|
-
* @param input The text to colour.
|
188
|
-
* @returns If colours are enabled, `input` coloured bright magenta.
|
189
|
-
*/
|
98
|
+
/** Colour some text bright magenta. */
|
190
99
|
magentaBright: (input: string | TemplateStringsArray) => string;
|
191
|
-
/**
|
192
|
-
* Make some text bright cyran.
|
193
|
-
*
|
194
|
-
* @param input The text to colour.
|
195
|
-
* @returns If colours are enabled, `input` coloured bright cyan.
|
196
|
-
*/
|
100
|
+
/** Colour some text bright cyan. */
|
197
101
|
cyanBright: (input: string | TemplateStringsArray) => string;
|
198
|
-
/**
|
199
|
-
* Make some text bright white.
|
200
|
-
*
|
201
|
-
* @param input The text to colour.
|
202
|
-
* @returns If colours are enabled, `input` coloured bright white.
|
203
|
-
*/
|
102
|
+
/** Colour some text bright white. */
|
204
103
|
whiteBright: (input: string | TemplateStringsArray) => string;
|
205
|
-
/**
|
206
|
-
* Make the background of some text black.
|
207
|
-
*
|
208
|
-
* @param input The text whose background to colour.
|
209
|
-
* @returns If colours are enabled, `input` with a black background.
|
210
|
-
*/
|
104
|
+
/** Colour the background of some text black. */
|
211
105
|
bgBlack: (input: string | TemplateStringsArray) => string;
|
212
|
-
/**
|
213
|
-
* Make the background of some text red.
|
214
|
-
*
|
215
|
-
* @param input The text whose background to colour.
|
216
|
-
* @returns If colours are enabled, `input` with a red background.
|
217
|
-
*/
|
106
|
+
/** Colour the background of some text red. */
|
218
107
|
bgRed: (input: string | TemplateStringsArray) => string;
|
219
|
-
/**
|
220
|
-
* Make the background of some text green.
|
221
|
-
*
|
222
|
-
* @param input The text whose background to colour.
|
223
|
-
* @returns If colours are enabled, `input` with a green background.
|
224
|
-
*/
|
108
|
+
/** Colour the background of some text green. */
|
225
109
|
bgGreen: (input: string | TemplateStringsArray) => string;
|
226
|
-
/**
|
227
|
-
* Make the background of some text yellow.
|
228
|
-
*
|
229
|
-
* @param input The text whose background to colour.
|
230
|
-
* @returns If colours are enabled, `input` with a yellow background.
|
231
|
-
*/
|
110
|
+
/** Colour the background of some text yellow. */
|
232
111
|
bgYellow: (input: string | TemplateStringsArray) => string;
|
233
|
-
/**
|
234
|
-
* Make the background of some text blue.
|
235
|
-
*
|
236
|
-
* @param input The text whose background to colour.
|
237
|
-
* @returns If colours are enabled, `input` with a blue background.
|
238
|
-
*/
|
112
|
+
/** Colour the background of some text blue. */
|
239
113
|
bgBlue: (input: string | TemplateStringsArray) => string;
|
240
|
-
/**
|
241
|
-
* Make the background of some text magenta.
|
242
|
-
*
|
243
|
-
* @param input The text whose background to colour.
|
244
|
-
* @returns If colours are enabled, `input` with a magenta background.
|
245
|
-
*/
|
114
|
+
/** Colour the background of some text magenta. */
|
246
115
|
bgMagenta: (input: string | TemplateStringsArray) => string;
|
247
|
-
/**
|
248
|
-
* Make the background of some text cyan.
|
249
|
-
*
|
250
|
-
* @param input The text whose background to colour.
|
251
|
-
* @returns If colours are enabled, `input` with a cyan background.
|
252
|
-
*/
|
116
|
+
/** Colour the background of some text cyan. */
|
253
117
|
bgCyan: (input: string | TemplateStringsArray) => string;
|
254
|
-
/**
|
255
|
-
* Make the background of some text white.
|
256
|
-
*
|
257
|
-
* @param input The text whose background to colour.
|
258
|
-
* @returns If colours are enabled, `input` with a white background.
|
259
|
-
*/
|
118
|
+
/** Colour the background of some text white. */
|
260
119
|
bgWhite: (input: string | TemplateStringsArray) => string;
|
261
|
-
/**
|
262
|
-
* Make the background of some text bright black (grey).
|
263
|
-
*
|
264
|
-
* @param input The text whose background to colour.
|
265
|
-
* @returns If colours are enabled, `input` with a bright black (grey) background.
|
266
|
-
*/
|
120
|
+
/** Colour the background of some text bright black (grey). */
|
267
121
|
bgBlackBright: (input: string | TemplateStringsArray) => string;
|
268
|
-
/**
|
269
|
-
* Make the background of some text bright red.
|
270
|
-
*
|
271
|
-
* @param input The text whose background to colour.
|
272
|
-
* @returns If colours are enabled, `input` with a bright re backgroundd.
|
273
|
-
*/
|
122
|
+
/** Colour the background of some text bright red. */
|
274
123
|
bgRedBright: (input: string | TemplateStringsArray) => string;
|
275
|
-
/**
|
276
|
-
* Make the background of some text bright green.
|
277
|
-
*
|
278
|
-
* @param input The text whose background to colour.
|
279
|
-
* @returns If colours are enabled, `input` with a bright gree backgroundn.
|
280
|
-
*/
|
124
|
+
/** Colour the background of some text bright green. */
|
281
125
|
bgGreenBright: (input: string | TemplateStringsArray) => string;
|
282
|
-
/**
|
283
|
-
* Make the background of some text bright yellow.
|
284
|
-
*
|
285
|
-
* @param input The text whose background to colour.
|
286
|
-
* @returns If colours are enabled, `input` with a bright yello backgroundw.
|
287
|
-
*/
|
126
|
+
/** Colour the background of some text bright yellow. */
|
288
127
|
bgYellowBright: (input: string | TemplateStringsArray) => string;
|
289
|
-
/**
|
290
|
-
* Make the background of some text bright blue.
|
291
|
-
*
|
292
|
-
* @param input The text whose background to colour.
|
293
|
-
* @returns If colours are enabled, `input` with a bright blu backgrounde.
|
294
|
-
*/
|
128
|
+
/** Colour the background of some text bright blue. */
|
295
129
|
bgBlueBright: (input: string | TemplateStringsArray) => string;
|
296
|
-
/**
|
297
|
-
* Make the background of some text bright magenta.
|
298
|
-
*
|
299
|
-
* @param input The text whose background to colour.
|
300
|
-
* @returns If colours are enabled, `input` with a bright magent backgrounda.
|
301
|
-
*/
|
130
|
+
/** Colour the background of some text bright magenta. */
|
302
131
|
bgMagentaBright: (input: string | TemplateStringsArray) => string;
|
303
|
-
/**
|
304
|
-
* Make the background of some text bright cyan.
|
305
|
-
*
|
306
|
-
* @param input The desired text to be styled.
|
307
|
-
* @returns If colours are enabled, `input` with a bright cyan background.
|
308
|
-
*/
|
132
|
+
/** Colour the background of some text bright cyan. */
|
309
133
|
bgCyanBright: (input: string | TemplateStringsArray) => string;
|
310
|
-
/**
|
311
|
-
* Make the background of some text bright white.
|
312
|
-
*
|
313
|
-
* @param input The desired text to be styled.
|
314
|
-
* @returns If colours are enabled, `input` with a bright white background.
|
315
|
-
*/
|
134
|
+
/** Colour the background of some text bright white. */
|
316
135
|
bgWhiteBright: (input: string | TemplateStringsArray) => string;
|
317
136
|
/**
|
318
137
|
* Make some text or its background one of 256 colours.
|
@@ -324,7 +143,7 @@ interface Termark {
|
|
324
143
|
* @returns If terminal colours are enabled and [8-bit colours](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) are supported, the stylized text. If either is false, it returns the plain string.
|
325
144
|
* @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
|
326
145
|
*/
|
327
|
-
ansi256
|
146
|
+
ansi256(type: ANSIStyleType, color: number): (input: string | TemplateStringsArray) => string;
|
328
147
|
/**
|
329
148
|
* Make some text or its background using custom RGB values.
|
330
149
|
*
|
@@ -340,7 +159,7 @@ interface Termark {
|
|
340
159
|
* termark.rgb('text', [85, 222, 124])('...');
|
341
160
|
* ```
|
342
161
|
*/
|
343
|
-
rgb
|
162
|
+
rgb(type: ANSIStyleType, ...rgb: RGB | [RGB]): (input: string | TemplateStringsArray) => string;
|
344
163
|
/**
|
345
164
|
* Apply a gradient to some text or its background.
|
346
165
|
*
|
@@ -357,7 +176,7 @@ interface Termark {
|
|
357
176
|
* termark.gradient('background', [[222, 111, 0], [93, 255, 68], [0, 224, 110]])('...');
|
358
177
|
* ```
|
359
178
|
*/
|
360
|
-
gradient
|
179
|
+
gradient(type: ANSIStyleType, colors: RGB[]): (input: string | TemplateStringsArray) => string;
|
361
180
|
/**
|
362
181
|
* Logs a `message` to the console on the `info` level.
|
363
182
|
*
|
@@ -374,7 +193,7 @@ interface Termark {
|
|
374
193
|
* termark.success('...'); // Logs "..." in green as a success (info).
|
375
194
|
* ```
|
376
195
|
*/
|
377
|
-
success
|
196
|
+
success(message: string, prefix?: string): void;
|
378
197
|
/**
|
379
198
|
* Logs a `message` to the console on the `info` level.
|
380
199
|
*
|
@@ -388,7 +207,7 @@ interface Termark {
|
|
388
207
|
* termark.info('...'); // Logs "..." in blue as an info.
|
389
208
|
* ```
|
390
209
|
*/
|
391
|
-
info
|
210
|
+
info(message: string, prefix?: string): void;
|
392
211
|
/**
|
393
212
|
* Logs a `message` to the console on the `error` level.
|
394
213
|
*
|
@@ -406,7 +225,7 @@ interface Termark {
|
|
406
225
|
* termark.warn('...'); // Logs "..." in yellow as a warning (error).
|
407
226
|
* ```
|
408
227
|
*/
|
409
|
-
warn
|
228
|
+
warn(message: string, prefix?: string): void;
|
410
229
|
/**
|
411
230
|
* Logs a `message` to the console on the `error` level.
|
412
231
|
*
|
@@ -420,7 +239,7 @@ interface Termark {
|
|
420
239
|
* termark.error('...'); // Logs "..." in red as an error.
|
421
240
|
* ```
|
422
241
|
*/
|
423
|
-
error
|
242
|
+
error(message: string, prefix?: string): void;
|
424
243
|
/**
|
425
244
|
* Style some text using entirely custom settings.
|
426
245
|
*
|
@@ -442,7 +261,7 @@ interface Termark {
|
|
442
261
|
* termark.custom('58;2;33', 59)('...'); // This should result in a string with a blue underline.
|
443
262
|
* ```
|
444
263
|
*/
|
445
|
-
custom
|
264
|
+
custom(opener: string | number, closer: string | number, type: 'asColor' | 'asFormat'): (input: string | TemplateStringsArray) => string;
|
446
265
|
}
|
447
266
|
/**
|
448
267
|
* The `termark` object enables accessing all features of Termark:
|
@@ -470,7 +289,7 @@ interface Termark {
|
|
470
289
|
* termark.is24bitEnabled; // Check whether 24-bit (truecolor) colours are enabled
|
471
290
|
* ```
|
472
291
|
*
|
473
|
-
* In addition, properties on the `
|
292
|
+
* In addition, properties on the `Termark` class are static-ish, i.e., they only do one thing, and you have no input on it.
|
474
293
|
*
|
475
294
|
* ---
|
476
295
|
*
|
@@ -491,6 +310,8 @@ interface Termark {
|
|
491
310
|
*
|
492
311
|
* @example
|
493
312
|
* ```typescript
|
313
|
+
* import termark from 'termark';
|
314
|
+
*
|
494
315
|
* termark.ansi256('text', 33)('This is blue text');
|
495
316
|
* termark.ansi256('text', 33)`This is also blue text`;
|
496
317
|
* ```
|
@@ -501,6 +322,8 @@ interface Termark {
|
|
501
322
|
* a function to specify your input. These ones are:
|
502
323
|
*
|
503
324
|
* ```typescript
|
325
|
+
* import termark from 'termark';
|
326
|
+
*
|
504
327
|
* termark.success('...');
|
505
328
|
* termark.info('...');
|
506
329
|
* termark.warn('...');
|
@@ -512,3 +335,4 @@ interface Termark {
|
|
512
335
|
*/
|
513
336
|
declare const termark: Termark;
|
514
337
|
export default termark;
|
338
|
+
export declare const areColorsEnabled: boolean, is8bitEnabled: boolean, is24bitEnabled: boolean, reset: (input: string | TemplateStringsArray) => string, bold: (input: string | TemplateStringsArray) => string, dim: (input: string | TemplateStringsArray) => string, italic: (input: string | TemplateStringsArray) => string, underline: (input: string | TemplateStringsArray) => string, blink: (input: string | TemplateStringsArray) => string, inverse: (input: string | TemplateStringsArray) => string, overline: (input: string | TemplateStringsArray) => string, hidden: (input: string | TemplateStringsArray) => string, strike: (input: string | TemplateStringsArray) => string, black: (input: string | TemplateStringsArray) => string, red: (input: string | TemplateStringsArray) => string, green: (input: string | TemplateStringsArray) => string, yellow: (input: string | TemplateStringsArray) => string, blue: (input: string | TemplateStringsArray) => string, magenta: (input: string | TemplateStringsArray) => string, cyan: (input: string | TemplateStringsArray) => string, white: (input: string | TemplateStringsArray) => string, blackBright: (input: string | TemplateStringsArray) => string, redBright: (input: string | TemplateStringsArray) => string, greenBright: (input: string | TemplateStringsArray) => string, yellowBright: (input: string | TemplateStringsArray) => string, blueBright: (input: string | TemplateStringsArray) => string, magentaBright: (input: string | TemplateStringsArray) => string, cyanBright: (input: string | TemplateStringsArray) => string, whiteBright: (input: string | TemplateStringsArray) => string, bgBlack: (input: string | TemplateStringsArray) => string, bgRed: (input: string | TemplateStringsArray) => string, bgGreen: (input: string | TemplateStringsArray) => string, bgYellow: (input: string | TemplateStringsArray) => string, bgBlue: (input: string | TemplateStringsArray) => string, bgMagenta: (input: string | TemplateStringsArray) => string, bgCyan: (input: string | TemplateStringsArray) => string, bgWhite: (input: string | TemplateStringsArray) => string, bgBlackBright: (input: string | TemplateStringsArray) => string, bgRedBright: (input: string | TemplateStringsArray) => string, bgGreenBright: (input: string | TemplateStringsArray) => string, bgYellowBright: (input: string | TemplateStringsArray) => string, bgBlueBright: (input: string | TemplateStringsArray) => string, bgMagentaBright: (input: string | TemplateStringsArray) => string, bgCyanBright: (input: string | TemplateStringsArray) => string, bgWhiteBright: (input: string | TemplateStringsArray) => string, ansi256: (type: ANSIStyleType, color: number) => (input: string | TemplateStringsArray) => string, rgb: (type: ANSIStyleType, ...rgb: RGB | [RGB]) => (input: string | TemplateStringsArray) => string, gradient: (type: ANSIStyleType, colors: RGB[]) => (input: string | TemplateStringsArray) => string, success: (message: string, prefix?: string) => void, info: (message: string, prefix?: string) => void, warn: (message: string, prefix?: string) => void, error: (message: string, prefix?: string) => void, custom: (opener: string | number, closer: string | number, type: "asColor" | "asFormat") => (input: string | TemplateStringsArray) => string;
|
package/dist/index.mjs
CHANGED
@@ -1,179 +1 @@
|
|
1
|
-
|
2
|
-
Copyright 2025 Q
|
3
|
-
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
you may not use this file except in compliance with the License.
|
6
|
-
You may obtain a copy of the License at
|
7
|
-
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
See the License for the specific language governing permissions and
|
14
|
-
limitations under the License.
|
15
|
-
*/
|
16
|
-
|
17
|
-
const areColoursEnabled = () => {
|
18
|
-
const noColour = process.env.NO_COLOR;
|
19
|
-
return noColour ? false : true;
|
20
|
-
};
|
21
|
-
const getColourSupport = () => {
|
22
|
-
const colourTerm = process.env.COLORTERM;
|
23
|
-
const is16bit = colourTerm ? (colourTerm.includes('ansi') && !(colourTerm.includes('256'))) : false;
|
24
|
-
const is256 = colourTerm ? colourTerm.includes('ansi256') : false;
|
25
|
-
const isTrueColor = colourTerm ? (colourTerm.includes('truecolor') || colourTerm.includes('24bit')) : false;
|
26
|
-
return {
|
27
|
-
is16bit,
|
28
|
-
is256,
|
29
|
-
isTrueColor
|
30
|
-
};
|
31
|
-
};
|
32
|
-
function format(open, close, type) {
|
33
|
-
if (type === 'color' && !areColoursEnabled())
|
34
|
-
return (input) => input.toString();
|
35
|
-
const opener = `\x1b[${open}m`;
|
36
|
-
const closer = `\x1b[${close}m`;
|
37
|
-
return (input$1) => {
|
38
|
-
const input = input$1.toString().trim();
|
39
|
-
const index = input.indexOf(closer);
|
40
|
-
if (index === -1)
|
41
|
-
return `${opener}${input}${closer}`;
|
42
|
-
return `${opener}${input.replaceAll(closer, closer + opener)}${closer}`;
|
43
|
-
};
|
44
|
-
}
|
45
|
-
function interpolate(color1, color2, factor) {
|
46
|
-
return [
|
47
|
-
Math.round(color1[0] + factor * (color2[0] - color1[0])),
|
48
|
-
Math.round(color1[1] + factor * (color2[1] - color1[1])),
|
49
|
-
Math.round(color1[2] + factor * (color2[2] - color1[2])),
|
50
|
-
];
|
51
|
-
}
|
52
|
-
|
53
|
-
const termark = {
|
54
|
-
areColorsEnabled: areColoursEnabled(),
|
55
|
-
is8bitEnabled: getColourSupport().is256,
|
56
|
-
is24bitEnabled: getColourSupport().isTrueColor,
|
57
|
-
reset: format(0, 0, 'format'),
|
58
|
-
bold: format(1, 22, 'format'),
|
59
|
-
dim: format(2, 22, 'format'),
|
60
|
-
italic: format(3, 23, 'format'),
|
61
|
-
underline: format(4, 24, 'format'),
|
62
|
-
blink: format(5, 25, 'format'),
|
63
|
-
inverse: format(7, 27, 'format'),
|
64
|
-
overline: format(53, 55, 'format'),
|
65
|
-
hidden: format(8, 28, 'format'),
|
66
|
-
strike: format(9, 29, 'format'),
|
67
|
-
black: format(30, 39, 'color'),
|
68
|
-
red: format(31, 39, 'color'),
|
69
|
-
green: format(32, 39, 'color'),
|
70
|
-
yellow: format(33, 39, 'color'),
|
71
|
-
blue: format(34, 39, 'color'),
|
72
|
-
magenta: format(35, 39, 'color'),
|
73
|
-
cyan: format(36, 39, 'color'),
|
74
|
-
white: format(37, 39, 'color'),
|
75
|
-
blackBright: format(90, 39, 'color'),
|
76
|
-
redBright: format(91, 39, 'color'),
|
77
|
-
greenBright: format(92, 39, 'color'),
|
78
|
-
yellowBright: format(93, 39, 'color'),
|
79
|
-
blueBright: format(94, 39, 'color'),
|
80
|
-
magentaBright: format(95, 39, 'color'),
|
81
|
-
cyanBright: format(96, 39, 'color'),
|
82
|
-
whiteBright: format(97, 39, 'color'),
|
83
|
-
bgBlack: format(40, 49, 'color'),
|
84
|
-
bgRed: format(41, 49, 'color'),
|
85
|
-
bgGreen: format(42, 49, 'color'),
|
86
|
-
bgYellow: format(43, 49, 'color'),
|
87
|
-
bgBlue: format(44, 49, 'color'),
|
88
|
-
bgMagenta: format(45, 49, 'color'),
|
89
|
-
bgCyan: format(46, 49, 'color'),
|
90
|
-
bgWhite: format(47, 49, 'color'),
|
91
|
-
bgBlackBright: format(100, 49, 'color'),
|
92
|
-
bgRedBright: format(101, 49, 'color'),
|
93
|
-
bgGreenBright: format(102, 49, 'color'),
|
94
|
-
bgYellowBright: format(103, 49, 'color'),
|
95
|
-
bgBlueBright: format(104, 49, 'color'),
|
96
|
-
bgMagentaBright: format(105, 49, 'color'),
|
97
|
-
bgCyanBright: format(106, 49, 'color'),
|
98
|
-
bgWhiteBright: format(107, 49, 'color'),
|
99
|
-
ansi256(type, color) {
|
100
|
-
if (color < 0 || color > 255)
|
101
|
-
throw new Error(termark.red('Value `color` is out of range! The value must be a number between 0 and 255!'));
|
102
|
-
if (!getColourSupport().is256 || !areColoursEnabled())
|
103
|
-
return (input) => input.toString();
|
104
|
-
const textFormat = `38;5;${color}`;
|
105
|
-
const bgFormat = `48;5;${color}`;
|
106
|
-
const opener = type === 'text' ? textFormat : bgFormat;
|
107
|
-
const closer = type === 'text' ? 39 : 49;
|
108
|
-
return format(opener, closer, 'color');
|
109
|
-
},
|
110
|
-
rgb(type, ...rgb) {
|
111
|
-
let red;
|
112
|
-
let green;
|
113
|
-
let blue;
|
114
|
-
if (Array.isArray(rgb[0])) {
|
115
|
-
red = rgb[0][0];
|
116
|
-
green = rgb[0][1];
|
117
|
-
blue = rgb[0][2];
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
red = rgb[0];
|
121
|
-
green = rgb[1];
|
122
|
-
blue = rgb[2];
|
123
|
-
}
|
124
|
-
if (((typeof red === 'number') && (red < 0 || red > 255)) ||
|
125
|
-
((typeof green === 'number') && (green < 0 || green > 255)) ||
|
126
|
-
((typeof blue === 'number') && (blue < 0 || blue > 255)))
|
127
|
-
throw new Error(termark.red('One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!'));
|
128
|
-
if (!getColourSupport().isTrueColor)
|
129
|
-
return (input) => input.toString();
|
130
|
-
const textFormat = `38;2;${red};${green};${blue}`;
|
131
|
-
const bgFormat = `48;2;${red};${green};${blue}`;
|
132
|
-
const opener = type === 'text' ? textFormat : bgFormat;
|
133
|
-
const closer = type === 'text' ? 39 : 49;
|
134
|
-
return format(opener, closer, 'color');
|
135
|
-
},
|
136
|
-
gradient(type, colors) {
|
137
|
-
if (!areColoursEnabled() || !getColourSupport().isTrueColor)
|
138
|
-
return (input) => input.toString();
|
139
|
-
const textFormat = `38;2;`;
|
140
|
-
const bgFormat = `48;2;`;
|
141
|
-
const opener = type === 'text' ? `\x1b[${textFormat}` : `\x1b[${bgFormat}`;
|
142
|
-
const closer = type === 'text' ? `\x1b[${39}m` : `\x1b[${49}m`;
|
143
|
-
return (input$1) => {
|
144
|
-
const input = input$1.toString().trim();
|
145
|
-
const colourCount = colors.length;
|
146
|
-
const step = Math.min(input.length / (colourCount - 1));
|
147
|
-
let result = '';
|
148
|
-
for (let character = 0; character < input.length; character++) {
|
149
|
-
const colourIndex = Math.min(Math.floor(character / step), colourCount - 2);
|
150
|
-
const factor = (character % step) / step;
|
151
|
-
const startColour = colors[colourIndex];
|
152
|
-
const endColour = colors[colourIndex + 1];
|
153
|
-
const interpolatedColour = interpolate(startColour, endColour, factor);
|
154
|
-
result += `${opener}${interpolatedColour[0]};${interpolatedColour[1]};${interpolatedColour[2]}m${input[character]}${closer}`;
|
155
|
-
}
|
156
|
-
return result;
|
157
|
-
};
|
158
|
-
},
|
159
|
-
success(message, prefix = '') {
|
160
|
-
console.info(`${prefix}${termark.green(message)}`);
|
161
|
-
},
|
162
|
-
info(message, prefix = '') {
|
163
|
-
console.info(`${prefix}${termark.blue(message)}`);
|
164
|
-
},
|
165
|
-
warn(message, prefix = '') {
|
166
|
-
console.warn(`${prefix}${termark.yellow(message)}`);
|
167
|
-
},
|
168
|
-
error(message, prefix = '') {
|
169
|
-
console.error(`${prefix}${termark.red(message)}`);
|
170
|
-
},
|
171
|
-
custom(opener, closer, type) {
|
172
|
-
const formatType = type === 'asColor' ? 'color' : 'format';
|
173
|
-
return format(opener, closer, formatType);
|
174
|
-
},
|
175
|
-
};
|
176
|
-
|
177
|
-
export { termark as default };
|
178
|
-
|
179
|
-
// Copyright (C) 2025 Q
|
1
|
+
const t=()=>!process.env.NO_COLOR,r=()=>{const t=process.env.COLORTERM;return{is16bit:!!t&&(t.includes("ansi")&&!t.includes("256")),is256:!!t&&t.includes("ansi256"),isTrueColor:!!t&&(t.includes("truecolor")||t.includes("24bit"))}};function e(r,e,i){if("color"===i&&!t())return t=>t.toString();const o=`[${r}m`,n=`[${e}m`;return t=>{const r=t.toString().trim();return-1===r.indexOf(n)?`${o}${r}${n}`:`${o}${r.replaceAll(n,n+o)}${n}`}}function i(t,r,e){return[Math.round(t[0]+e*(r[0]-t[0])),Math.round(t[1]+e*(r[1]-t[1])),Math.round(t[2]+e*(r[2]-t[2]))]}class o{constructor(){this.areColorsEnabled=t(),this.is8bitEnabled=r().is256,this.is24bitEnabled=r().isTrueColor,this.reset=e(0,0,"format"),this.bold=e(1,22,"format"),this.dim=e(2,22,"format"),this.italic=e(3,23,"format"),this.underline=e(4,24,"format"),this.blink=e(5,25,"format"),this.inverse=e(7,27,"format"),this.overline=e(53,55,"format"),this.hidden=e(8,28,"format"),this.strike=e(9,29,"format"),this.black=e(30,39,"color"),this.red=e(31,39,"color"),this.green=e(32,39,"color"),this.yellow=e(33,39,"color"),this.blue=e(34,39,"color"),this.magenta=e(35,39,"color"),this.cyan=e(36,39,"color"),this.white=e(37,39,"color"),this.blackBright=e(90,39,"color"),this.redBright=e(91,39,"color"),this.greenBright=e(92,39,"color"),this.yellowBright=e(93,39,"color"),this.blueBright=e(94,39,"color"),this.magentaBright=e(95,39,"color"),this.cyanBright=e(96,39,"color"),this.whiteBright=e(97,39,"color"),this.bgBlack=e(40,49,"color"),this.bgRed=e(41,49,"color"),this.bgGreen=e(42,49,"color"),this.bgYellow=e(43,49,"color"),this.bgBlue=e(44,49,"color"),this.bgMagenta=e(45,49,"color"),this.bgCyan=e(46,49,"color"),this.bgWhite=e(47,49,"color"),this.bgBlackBright=e(100,49,"color"),this.bgRedBright=e(101,49,"color"),this.bgGreenBright=e(102,49,"color"),this.bgYellowBright=e(103,49,"color"),this.bgBlueBright=e(104,49,"color"),this.bgMagentaBright=e(105,49,"color"),this.bgCyanBright=e(106,49,"color"),this.bgWhiteBright=e(107,49,"color")}static get init(){return new this.termarkInstance}ansi256(i,n){if(n<0||n>255)throw new Error(o.init.red("Value `color` is out of range! The value must be a number between 0 and 255!"));if(!r().is256||!t())return t=>t.toString();return e("text"===i?`38;5;${n}`:`48;5;${n}`,"text"===i?39:49,"color")}rgb(t,...i){let n,l,s;if(Array.isArray(i[0])?(n=i[0][0],l=i[0][1],s=i[0][2]):(n=i[0],l=i[1],s=i[2]),"number"==typeof n&&(n<0||n>255)||"number"==typeof l&&(l<0||l>255)||"number"==typeof s&&(s<0||s>255))throw new Error(o.init.red("One or multiple of the colours specified is out of range! Each colour can have a value only between 0 and 255!"));if(!r().isTrueColor)return t=>t.toString();return e("text"===t?`38;2;${n};${l};${s}`:`48;2;${n};${l};${s}`,"text"===t?39:49,"color")}gradient(e,o){if(!t()||!r().isTrueColor)return t=>t.toString();const n="text"===e?"[38;2;":"[48;2;",l="text"===e?"[39m":"[49m";return t=>{const r=t.toString().trim(),e=o.length,s=Math.min(r.length/(e-1));let h="";for(let t=0;t<r.length;t++){const g=Math.min(Math.floor(t/s),e-2),a=t%s/s,c=i(o[g],o[g+1],a);h+=`${n}${c[0]};${c[1]};${c[2]}m${r[t]}${l}`}return h}}success(t,r=""){console.info(`${r}${o.init.green(t)}`)}info(t,r=""){console.info(`${r}${o.init.blue(t)}`)}warn(t,r=""){console.warn(`${r}${o.init.yellow(t)}`)}error(t,r=""){console.error(`${r}${o.init.red(t)}`)}custom(t,r,i){return e(t,r,"asColor"===i?"color":"format")}}o.termarkInstance=o;const n=new o,{areColorsEnabled:l,is8bitEnabled:s,is24bitEnabled:h,reset:g,bold:a,dim:c,italic:b,underline:u,blink:d,inverse:B,overline:m,hidden:f,strike:$,black:w,red:y,green:k,yellow:C,blue:M,magenta:E,cyan:p,white:v,blackBright:x,redBright:O,greenBright:R,yellowBright:S,blueBright:T,magentaBright:G,cyanBright:W,whiteBright:Y,bgBlack:A,bgRed:I,bgGreen:L,bgYellow:N,bgBlue:V,bgMagenta:_,bgCyan:j,bgWhite:q,bgBlackBright:z,bgRedBright:D,bgGreenBright:F,bgYellowBright:H,bgBlueBright:J,bgMagentaBright:K,bgCyanBright:P,bgWhiteBright:Q,ansi256:U,rgb:X,gradient:Z,success:tt,info:rt,warn:et,error:it,custom:ot}=n;export{o as Termark,U as ansi256,l as areColorsEnabled,A as bgBlack,z as bgBlackBright,V as bgBlue,J as bgBlueBright,j as bgCyan,P as bgCyanBright,L as bgGreen,F as bgGreenBright,_ as bgMagenta,K as bgMagentaBright,I as bgRed,D as bgRedBright,q as bgWhite,Q as bgWhiteBright,N as bgYellow,H as bgYellowBright,w as black,x as blackBright,d as blink,M as blue,T as blueBright,a as bold,ot as custom,p as cyan,W as cyanBright,n as default,c as dim,it as error,Z as gradient,k as green,R as greenBright,f as hidden,rt as info,B as inverse,h as is24bitEnabled,s as is8bitEnabled,b as italic,E as magenta,G as magentaBright,m as overline,y as red,O as redBright,g as reset,X as rgb,$ as strike,tt as success,u as underline,et as warn,v as white,Y as whiteBright,C as yellow,S as yellowBright};
|
package/dist/util.d.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
export type ANSIStyleType = 'text' | 'background';
|
2
|
+
export type RGB = [number, number, number];
|
1
3
|
/**
|
2
4
|
* Check whether terminal colours are supported/enabled.
|
3
5
|
*
|
@@ -46,4 +48,4 @@ export declare function format(open: number | string, close: number | string, ty
|
|
46
48
|
* @param factor How to calculate the colour.
|
47
49
|
* @returns An RGB value that is the colour between `color1` and `color2` at `factor`.
|
48
50
|
*/
|
49
|
-
export declare function interpolate(color1:
|
51
|
+
export declare function interpolate(color1: RGB, color2: RGB, factor: number): RGB;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "termark",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"main": "./dist/index.cjs",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"exports": {
|
@@ -30,9 +30,9 @@
|
|
30
30
|
"url": "https://codeberg.org/Genesis_Software/termark.git"
|
31
31
|
},
|
32
32
|
"devDependencies": {
|
33
|
+
"@rollup/plugin-terser": "^0.4.4",
|
33
34
|
"@types/node": "^24.3.0",
|
34
35
|
"rollup": "^4.49.0",
|
35
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
36
36
|
"rollup-plugin-typescript2": "^0.36.0",
|
37
37
|
"typescript": "^5.9.2"
|
38
38
|
}
|