@oxog/pigment 1.0.2 → 1.1.1
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 +90 -71
- package/dist/{index-ChElNHaA.d.cts → index-C_LwyWae.d.cts} +134 -3
- package/dist/{index-ChElNHaA.d.ts → index-C_LwyWae.d.ts} +134 -3
- package/dist/index.cjs +872 -309
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -131
- package/dist/index.d.ts +33 -131
- package/dist/index.js +872 -309
- package/dist/index.js.map +1 -1
- package/dist/plugins/index.cjs +930 -253
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.cts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +930 -253
- package/dist/plugins/index.js.map +1 -1
- package/package.json +37 -22
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @oxog/pigment
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Terminal styling with a micro-kernel plugin architecture and a Chalk-style chainable API.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@oxog/pigment)
|
|
6
6
|
[](https://github.com/ersinkoc/pigment)
|
|
@@ -10,15 +10,14 @@ Zero-dependency terminal styling with micro-kernel architecture and Chalk drop-i
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- **@oxog only** - Depends only on `@oxog/plugin` and `@oxog/types`
|
|
14
14
|
- **Universal Runtime** - Works in Node.js and browsers with same API
|
|
15
|
-
- **Micro-Kernel Architecture** -
|
|
16
|
-
- **Chalk
|
|
15
|
+
- **Micro-Kernel Architecture** - Plugin system for extensibility
|
|
16
|
+
- **Chalk-style API** - Chainable default export (`chalk.red.bold('x')`) with a settable `level`; close to Chalk v5, not a full drop-in
|
|
17
17
|
- **Multiple API Styles** - Proxy chaining, function composition, builder pattern
|
|
18
|
-
- **Full Color Support** - 16 base colors, 256 colors, true color (RGB/HEX/HSL)
|
|
19
|
-
- **Environment Aware** - Respects NO_COLOR, FORCE_COLOR, TTY detection
|
|
18
|
+
- **Full Color Support** - 16 base colors, 256 colors, true color (RGB/HEX/HSL), downsampled to what the terminal supports
|
|
19
|
+
- **Environment Aware** - Respects NO_COLOR, FORCE_COLOR, TTY detection; plain text at color level 0
|
|
20
20
|
- **TypeScript** - Strict mode with full type safety
|
|
21
|
-
- **Tree Shakeable** - Optimize bundle size with individual imports
|
|
22
21
|
|
|
23
22
|
## Installation
|
|
24
23
|
|
|
@@ -42,7 +41,7 @@ pigment.underline.yellow('Warning');
|
|
|
42
41
|
pigment.red(`Error: ${pigment.bold('critical')} issue`);
|
|
43
42
|
```
|
|
44
43
|
|
|
45
|
-
### Function Composition API
|
|
44
|
+
### Function Composition API
|
|
46
45
|
|
|
47
46
|
```typescript
|
|
48
47
|
import { bold, red, compose } from '@oxog/pigment';
|
|
@@ -61,7 +60,8 @@ console.log(highlight('IMPORTANT'));
|
|
|
61
60
|
```typescript
|
|
62
61
|
import { createPigment } from '@oxog/pigment';
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
// `builder` returns a new builder on every access
|
|
64
|
+
const styled = createPigment().builder
|
|
65
65
|
.bold()
|
|
66
66
|
.red()
|
|
67
67
|
.bgWhite()
|
|
@@ -70,18 +70,19 @@ const styled = createPigment()
|
|
|
70
70
|
console.log(styled);
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
### Chalk
|
|
73
|
+
### Chalk-Style Default Export
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
|
-
// Before (Chalk)
|
|
77
|
-
import chalk from 'chalk';
|
|
78
|
-
console.log(chalk.red.bold('Error'));
|
|
79
|
-
|
|
80
|
-
// After (Pigment) - just change import
|
|
81
76
|
import chalk from '@oxog/pigment';
|
|
77
|
+
|
|
82
78
|
console.log(chalk.red.bold('Error'));
|
|
79
|
+
console.log(chalk.hex('#FF8800').underline('Orange'));
|
|
80
|
+
chalk.level = 0; // plain text from now on, like chalk
|
|
83
81
|
```
|
|
84
82
|
|
|
83
|
+
Close to Chalk v5 for everyday use, but not a full drop-in: there are no `Chalk`,
|
|
84
|
+
`chalkStderr` or `modifierNames` exports and no tagged templates.
|
|
85
|
+
|
|
85
86
|
## Colors
|
|
86
87
|
|
|
87
88
|
### 16 Base Colors
|
|
@@ -167,14 +168,15 @@ pigment.bgHsl(210, 100, 50)('Blue background');
|
|
|
167
168
|
## Environment Detection
|
|
168
169
|
|
|
169
170
|
```typescript
|
|
170
|
-
import {
|
|
171
|
+
import { createPigment, supportsColor, resetColorSupportCache } from '@oxog/pigment';
|
|
171
172
|
|
|
172
173
|
// Check color support
|
|
173
|
-
console.log(supportsColor);
|
|
174
|
+
console.log(supportsColor());
|
|
174
175
|
// { level: 3, hasBasic: true, has256: true, has16m: true }
|
|
175
176
|
|
|
176
177
|
// Override level
|
|
177
|
-
const
|
|
178
|
+
const p = createPigment({ level: 2 });
|
|
179
|
+
p.hex('#FF8800')('Orange'); // downsampled to ANSI 256: \x1b[38;5;214m
|
|
178
180
|
|
|
179
181
|
// Reset cached detection (useful for testing)
|
|
180
182
|
resetColorSupportCache();
|
|
@@ -182,9 +184,24 @@ resetColorSupportCache();
|
|
|
182
184
|
|
|
183
185
|
### Environment Variables
|
|
184
186
|
|
|
185
|
-
- `
|
|
186
|
-
- `
|
|
187
|
-
- `TERM` -
|
|
187
|
+
- `FORCE_COLOR` - Forces the color level (`''`/`true` = 1, `false` = 0, or `0`-`3`); wins over `NO_COLOR`
|
|
188
|
+
- `NO_COLOR` - Disables colors (non-empty value)
|
|
189
|
+
- `TERM` / `COLORTERM` - `dumb` disables colors; `*256color` = level 2; `truecolor`/`24bit` = level 3
|
|
190
|
+
|
|
191
|
+
Without a TTY (piped output) colors are off unless `CI` is set.
|
|
192
|
+
|
|
193
|
+
### Color Levels
|
|
194
|
+
|
|
195
|
+
Output follows the level of the instance, like chalk:
|
|
196
|
+
|
|
197
|
+
| Level | Output |
|
|
198
|
+
|-------|--------|
|
|
199
|
+
| 0 | Plain text, no ANSI codes |
|
|
200
|
+
| 1 | 16 colors; rgb/hex/hsl/ansi256 become the closest basic color |
|
|
201
|
+
| 2 | 256 colors; rgb/hex/hsl become the closest ANSI 256 color |
|
|
202
|
+
| 3 | 24-bit true color |
|
|
203
|
+
|
|
204
|
+
Standalone stylers (`red`, `compose(...)`) use the detected level.
|
|
188
205
|
|
|
189
206
|
## Plugin System
|
|
190
207
|
|
|
@@ -212,6 +229,11 @@ environmentPlugin
|
|
|
212
229
|
|
|
213
230
|
### Optional Plugins (Opt-in)
|
|
214
231
|
|
|
232
|
+
Optional plugins add methods to an instance. Pass them to `createPigment({ plugins })` or
|
|
233
|
+
add them later with `pigment.use(plugin)` (returns the instance). Their output follows the
|
|
234
|
+
instance's color level. Calling a method whose plugin is not installed throws a
|
|
235
|
+
`PluginError` naming the plugin.
|
|
236
|
+
|
|
215
237
|
#### Gradient Plugin
|
|
216
238
|
|
|
217
239
|
```typescript
|
|
@@ -220,12 +242,11 @@ import { gradientPlugin } from '@oxog/pigment/plugins';
|
|
|
220
242
|
|
|
221
243
|
const pigment = createPigment({ plugins: [gradientPlugin({ steps: 10 })] });
|
|
222
244
|
|
|
223
|
-
// Linear gradient
|
|
224
|
-
pigment.gradient('red', 'blue')('Gradient text');
|
|
245
|
+
// Linear gradient: '#hex', 'rgb(r, g, b)' or [r, g, b]
|
|
225
246
|
pigment.gradient('#FF0000', '#0000FF')('Hex gradient');
|
|
226
|
-
pigment.gradient([255, 0, 0],
|
|
247
|
+
pigment.gradient([255, 0, 0], 'rgb(0, 0, 255)')('RGB gradient');
|
|
227
248
|
|
|
228
|
-
// Rainbow
|
|
249
|
+
// Rainbow
|
|
229
250
|
pigment.rainbow('Rainbow text');
|
|
230
251
|
```
|
|
231
252
|
|
|
@@ -236,13 +257,14 @@ import { themePlugin } from '@oxog/pigment/plugins';
|
|
|
236
257
|
|
|
237
258
|
const pigment = createPigment({ plugins: [themePlugin({ preset: 'monokai' })] });
|
|
238
259
|
|
|
239
|
-
|
|
240
|
-
pigment.theme.
|
|
241
|
-
pigment.theme.
|
|
242
|
-
pigment.theme.
|
|
243
|
-
pigment.theme.
|
|
244
|
-
pigment.theme.
|
|
245
|
-
pigment.theme.
|
|
260
|
+
pigment.theme.keyword('const');
|
|
261
|
+
pigment.theme.string('"hello"');
|
|
262
|
+
pigment.theme.number('42');
|
|
263
|
+
pigment.theme.comment('// note');
|
|
264
|
+
pigment.theme.error('Error!');
|
|
265
|
+
pigment.theme.success('Done!');
|
|
266
|
+
pigment.theme.warning('Careful');
|
|
267
|
+
pigment.theme.info('Note');
|
|
246
268
|
```
|
|
247
269
|
|
|
248
270
|
**Available Presets**: monokai, dracula, nord, github, vscode, tokyo-night, catppuccin, one-dark, solarized
|
|
@@ -254,20 +276,14 @@ import { semanticPlugin } from '@oxog/pigment/plugins';
|
|
|
254
276
|
|
|
255
277
|
const pigment = createPigment({ plugins: [semanticPlugin()] });
|
|
256
278
|
|
|
257
|
-
pigment.success('✓ Task completed');
|
|
258
|
-
pigment.error('✗ Task failed');
|
|
259
|
-
pigment.warning('⚠ Check this');
|
|
260
|
-
pigment.info('ℹ Note');
|
|
261
|
-
pigment.debug('[DEBUG] value');
|
|
262
|
-
|
|
263
|
-
// Custom colors
|
|
264
|
-
semanticPlugin({
|
|
265
|
-
success: '#00FF00',
|
|
266
|
-
error: '#FF0000',
|
|
267
|
-
warning: '#FFAA00',
|
|
268
|
-
info: '#00AAFF',
|
|
269
|
-
debug: '#888888'
|
|
270
|
-
})
|
|
279
|
+
pigment.success('✓ Task completed');
|
|
280
|
+
pigment.error('✗ Task failed');
|
|
281
|
+
pigment.warning('⚠ Check this');
|
|
282
|
+
pigment.info('ℹ Note');
|
|
283
|
+
pigment.debug('[DEBUG] value');
|
|
284
|
+
|
|
285
|
+
// Custom colors (hex)
|
|
286
|
+
semanticPlugin({ success: '#00FF00', error: '#FF0000', warning: '#FFAA00', info: '#00AAFF', debug: '#888888' });
|
|
271
287
|
```
|
|
272
288
|
|
|
273
289
|
#### Box Plugin
|
|
@@ -277,19 +293,15 @@ import { boxPlugin } from '@oxog/pigment/plugins';
|
|
|
277
293
|
|
|
278
294
|
const pigment = createPigment({ plugins: [boxPlugin()] });
|
|
279
295
|
|
|
280
|
-
// Simple box
|
|
281
296
|
pigment.box('Hello World');
|
|
282
297
|
// ┌─────────────┐
|
|
283
298
|
// │ Hello World │
|
|
284
299
|
// └─────────────┘
|
|
285
300
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
// ║ Error! ║
|
|
291
|
-
// ║ ║
|
|
292
|
-
// ╚═════════════╝
|
|
301
|
+
pigment.box('Error!', { border: 'double', padding: 0, bgColor: '#300000' });
|
|
302
|
+
// ╔══════╗
|
|
303
|
+
// ║Error!║
|
|
304
|
+
// ╚══════╝
|
|
293
305
|
```
|
|
294
306
|
|
|
295
307
|
**Border Styles**: single, double, rounded, bold, classic
|
|
@@ -301,20 +313,23 @@ import { templatePlugin } from '@oxog/pigment/plugins';
|
|
|
301
313
|
|
|
302
314
|
const pigment = createPigment({ plugins: [templatePlugin()] });
|
|
303
315
|
|
|
304
|
-
//
|
|
305
|
-
console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
306
|
-
|
|
307
|
-
// Nested styles
|
|
308
|
-
console.log(pigment`{bold.red CRITICAL:} {dim system failure}`);
|
|
316
|
+
// {style text} blocks, style chains with dots; blocks nest
|
|
317
|
+
console.log(pigment.template`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
318
|
+
console.log(pigment.template`{bold.red CRITICAL:} {dim system {underline failure}}`);
|
|
309
319
|
```
|
|
310
320
|
|
|
321
|
+
Interpolated values are inserted as-is and never parsed as blocks.
|
|
322
|
+
|
|
311
323
|
### Ecosystem Plugin
|
|
312
324
|
|
|
313
325
|
```typescript
|
|
314
326
|
import { pigmentPlugin } from '@oxog/pigment/plugins';
|
|
315
327
|
|
|
316
|
-
//
|
|
317
|
-
|
|
328
|
+
// On any @oxog/plugin kernel: adds kernel.pigment (a pigment instance)
|
|
329
|
+
import { createKernel } from '@oxog/pigment';
|
|
330
|
+
|
|
331
|
+
const kernel = createKernel();
|
|
332
|
+
kernel.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
|
|
318
333
|
```
|
|
319
334
|
|
|
320
335
|
## API Reference
|
|
@@ -325,11 +340,15 @@ log.use(pigmentPlugin({ theme: 'monokai', level: 3 }));
|
|
|
325
340
|
import { createPigment } from '@oxog/pigment';
|
|
326
341
|
|
|
327
342
|
const pigment = createPigment({
|
|
328
|
-
level: 3, //
|
|
329
|
-
forceColor: false, //
|
|
330
|
-
noColor: false, //
|
|
331
|
-
plugins: [] //
|
|
343
|
+
level: 3, // Color level 0-3 (default: detected)
|
|
344
|
+
forceColor: false, // Use options.level, or 3, even without color support
|
|
345
|
+
noColor: false, // Level 0: plain text
|
|
346
|
+
plugins: [] // Plugins to install
|
|
332
347
|
});
|
|
348
|
+
|
|
349
|
+
pigment.level; // 0-3
|
|
350
|
+
pigment.builder; // new BuilderPigment on every access
|
|
351
|
+
pigment.use(plugin); // install a plugin, returns the instance
|
|
333
352
|
```
|
|
334
353
|
|
|
335
354
|
### Type Definitions
|
|
@@ -369,7 +388,7 @@ interface Pigment {
|
|
|
369
388
|
| Platform | Output | Auto-Detection |
|
|
370
389
|
|----------|---------|---------------|
|
|
371
390
|
| Node.js | ANSI escape codes | ✅ TTY, TERM, CI |
|
|
372
|
-
| Browser |
|
|
391
|
+
| Browser | ANSI escape codes (level 1 by default) | Fixed level 1 |
|
|
373
392
|
|
|
374
393
|
## Technical Specifications
|
|
375
394
|
|
|
@@ -379,17 +398,17 @@ interface Pigment {
|
|
|
379
398
|
| Module Format | ESM + CJS |
|
|
380
399
|
| Node.js | >= 18 |
|
|
381
400
|
| TypeScript | >= 5.0 |
|
|
382
|
-
|
|
|
383
|
-
|
|
|
384
|
-
| Test Coverage | 100%
|
|
401
|
+
| `dist/index.js` | ~70 KB, ~15 KB gzipped (bundles `@oxog/plugin`) |
|
|
402
|
+
| `dist/plugins/index.js` | ~62 KB, ~14 KB gzipped |
|
|
403
|
+
| Test Coverage | 100% (enforced) |
|
|
385
404
|
|
|
386
405
|
## Dependencies
|
|
387
406
|
|
|
388
407
|
```json
|
|
389
408
|
{
|
|
390
409
|
"dependencies": {
|
|
391
|
-
"@oxog/
|
|
392
|
-
"@oxog/
|
|
410
|
+
"@oxog/plugin": "^1.1.0",
|
|
411
|
+
"@oxog/types": "^1.1.2"
|
|
393
412
|
}
|
|
394
413
|
}
|
|
395
414
|
```
|
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
import { Plugin as Plugin$1, Kernel as Kernel$1 } from '@oxog/types';
|
|
2
2
|
import { KernelInstance } from '@oxog/plugin';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Builder-pattern Pigment for explicit composition.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const builder = new BuilderPigment(kernel);
|
|
10
|
+
* const styled = builder.bold().red().paint('Error!');
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare class BuilderPigment {
|
|
14
|
+
private styles;
|
|
15
|
+
private readonly kernel;
|
|
16
|
+
constructor(kernel?: PigmentKernel);
|
|
17
|
+
/** The instance's color level (true color when there is no kernel). */
|
|
18
|
+
private get level();
|
|
19
|
+
bold(): this;
|
|
20
|
+
dim(): this;
|
|
21
|
+
italic(): this;
|
|
22
|
+
underline(): this;
|
|
23
|
+
strikethrough(): this;
|
|
24
|
+
inverse(): this;
|
|
25
|
+
hidden(): this;
|
|
26
|
+
reset(): this;
|
|
27
|
+
black(): this;
|
|
28
|
+
red(): this;
|
|
29
|
+
green(): this;
|
|
30
|
+
yellow(): this;
|
|
31
|
+
blue(): this;
|
|
32
|
+
magenta(): this;
|
|
33
|
+
cyan(): this;
|
|
34
|
+
white(): this;
|
|
35
|
+
blackBright(): this;
|
|
36
|
+
redBright(): this;
|
|
37
|
+
greenBright(): this;
|
|
38
|
+
yellowBright(): this;
|
|
39
|
+
blueBright(): this;
|
|
40
|
+
magentaBright(): this;
|
|
41
|
+
cyanBright(): this;
|
|
42
|
+
whiteBright(): this;
|
|
43
|
+
gray(): this;
|
|
44
|
+
grey(): this;
|
|
45
|
+
bgBlack(): this;
|
|
46
|
+
bgRed(): this;
|
|
47
|
+
bgGreen(): this;
|
|
48
|
+
bgYellow(): this;
|
|
49
|
+
bgBlue(): this;
|
|
50
|
+
bgMagenta(): this;
|
|
51
|
+
bgCyan(): this;
|
|
52
|
+
bgWhite(): this;
|
|
53
|
+
bgBlackBright(): this;
|
|
54
|
+
bgRedBright(): this;
|
|
55
|
+
bgGreenBright(): this;
|
|
56
|
+
bgYellowBright(): this;
|
|
57
|
+
bgBlueBright(): this;
|
|
58
|
+
bgMagentaBright(): this;
|
|
59
|
+
bgCyanBright(): this;
|
|
60
|
+
bgWhiteBright(): this;
|
|
61
|
+
bgGray(): this;
|
|
62
|
+
bgGrey(): this;
|
|
63
|
+
ansi256(code: number): this;
|
|
64
|
+
bgAnsi256(code: number): this;
|
|
65
|
+
rgb(r: number, g: number, b: number): this;
|
|
66
|
+
bgRgb(r: number, g: number, b: number): this;
|
|
67
|
+
hex(color: string): this;
|
|
68
|
+
bgHex(color: string): this;
|
|
69
|
+
hsl(h: number, s: number, l: number): this;
|
|
70
|
+
bgHsl(h: number, s: number, l: number): this;
|
|
71
|
+
paint(text: string): string;
|
|
72
|
+
}
|
|
73
|
+
|
|
4
74
|
type PigmentOptions = {
|
|
5
75
|
level?: 0 | 1 | 2 | 3;
|
|
6
76
|
forceColor?: boolean;
|
|
@@ -23,6 +93,8 @@ type Style = {
|
|
|
23
93
|
background?: boolean;
|
|
24
94
|
};
|
|
25
95
|
type Pigment = {
|
|
96
|
+
/** Returns the (styled) text when colors are supported, otherwise an empty string */
|
|
97
|
+
visible: (text: string) => string;
|
|
26
98
|
bold: Pigment;
|
|
27
99
|
dim: Pigment;
|
|
28
100
|
italic: Pigment;
|
|
@@ -77,6 +149,58 @@ type Pigment = {
|
|
|
77
149
|
bgHsl(h: number, s: number, l: number): Pigment;
|
|
78
150
|
(text: string): string;
|
|
79
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* A color accepted by plugin methods: `'#rrggbb'` / `'#rgb'`, `'rgb(r, g, b)'`
|
|
154
|
+
* or `[r, g, b]`.
|
|
155
|
+
*/
|
|
156
|
+
type ColorInput = string | readonly [number, number, number];
|
|
157
|
+
/** Theme color roles used by `themePlugin`. */
|
|
158
|
+
type ThemeColorType = 'keyword' | 'string' | 'number' | 'comment' | 'error' | 'success' | 'warning' | 'info';
|
|
159
|
+
/** Options for `pigment.box()` (`boxPlugin`). */
|
|
160
|
+
type BoxOptions = {
|
|
161
|
+
border?: BoxBorder;
|
|
162
|
+
padding?: number;
|
|
163
|
+
/** Background color for the whole box. */
|
|
164
|
+
bgColor?: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Methods added to an instance by the optional plugins. Each one throws a
|
|
168
|
+
* `PluginError` naming the plugin to install when it is missing.
|
|
169
|
+
*/
|
|
170
|
+
type PigmentPluginApi = {
|
|
171
|
+
/** gradientPlugin: color each character along a gradient. */
|
|
172
|
+
gradient(start: ColorInput, end: ColorInput): (text: string) => string;
|
|
173
|
+
/** gradientPlugin: rainbow-colored text. */
|
|
174
|
+
rainbow(text: string): string;
|
|
175
|
+
/** themePlugin: style text with a theme role color. */
|
|
176
|
+
theme: Record<ThemeColorType, (text: string) => string>;
|
|
177
|
+
/** semanticPlugin */
|
|
178
|
+
success(text: string): string;
|
|
179
|
+
/** semanticPlugin */
|
|
180
|
+
error(text: string): string;
|
|
181
|
+
/** semanticPlugin */
|
|
182
|
+
warning(text: string): string;
|
|
183
|
+
/** semanticPlugin */
|
|
184
|
+
info(text: string): string;
|
|
185
|
+
/** semanticPlugin */
|
|
186
|
+
debug(text: string): string;
|
|
187
|
+
/** boxPlugin: draw a box around text. */
|
|
188
|
+
box(text: string, options?: BoxOptions): string;
|
|
189
|
+
/** templatePlugin: tagged template with `{style.chain text}` blocks. */
|
|
190
|
+
template(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* What `createPigment()` returns (and the `pigment` export): the chainable
|
|
194
|
+
* styler plus instance members.
|
|
195
|
+
*/
|
|
196
|
+
type PigmentInstance = Pigment & PigmentPluginApi & {
|
|
197
|
+
/** A new builder on every access. */
|
|
198
|
+
readonly builder: BuilderPigment;
|
|
199
|
+
readonly level: number;
|
|
200
|
+
readonly supportsColor: ColorSupport;
|
|
201
|
+
/** Install a plugin on this instance; returns the instance. */
|
|
202
|
+
use(plugin: Plugin<PigmentContext>): PigmentInstance;
|
|
203
|
+
};
|
|
80
204
|
/**
|
|
81
205
|
* Plugin interface - re-exported from @oxog/types.
|
|
82
206
|
* Use this for creating Pigment-compatible plugins.
|
|
@@ -102,6 +226,12 @@ interface PigmentContext {
|
|
|
102
226
|
colorSupport: ColorSupport;
|
|
103
227
|
/** Registered styles map */
|
|
104
228
|
styles?: Map<string, StyleFunction>;
|
|
229
|
+
environment?: {
|
|
230
|
+
isCI: boolean;
|
|
231
|
+
noColor: boolean;
|
|
232
|
+
forceColor: boolean;
|
|
233
|
+
term: string;
|
|
234
|
+
};
|
|
105
235
|
/** Colors map */
|
|
106
236
|
colors?: {
|
|
107
237
|
foreground: Record<string, number>;
|
|
@@ -374,7 +504,7 @@ declare function semanticPlugin(options?: SemanticPluginOptions): Plugin<Pigment
|
|
|
374
504
|
* // │ Hello World │
|
|
375
505
|
* // └─────────────┘
|
|
376
506
|
*
|
|
377
|
-
* pigment.box('Error!', { border: 'double',
|
|
507
|
+
* pigment.box('Error!', { border: 'double', padding: 2 });
|
|
378
508
|
* ```
|
|
379
509
|
*/
|
|
380
510
|
declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
|
|
@@ -391,7 +521,8 @@ declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
|
|
|
391
521
|
* plugins: [templatePlugin()]
|
|
392
522
|
* });
|
|
393
523
|
*
|
|
394
|
-
* console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
524
|
+
* console.log(pigment.template`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
525
|
+
* console.log(pigment.template`{bold.red CRITICAL:} {dim system {underline failure}}`);
|
|
395
526
|
* ```
|
|
396
527
|
*/
|
|
397
528
|
declare function templatePlugin(): Plugin<PigmentContext>;
|
|
@@ -430,4 +561,4 @@ declare namespace index {
|
|
|
430
561
|
export { index_ansi256Plugin as ansi256Plugin, index_baseColorsPlugin as baseColorsPlugin, index_boxPlugin as boxPlugin, index_environmentPlugin as environmentPlugin, index_gradientPlugin as gradientPlugin, index_modifiersPlugin as modifiersPlugin, index_nestingPlugin as nestingPlugin, index_pigmentPlugin as pigmentPlugin, index_semanticPlugin as semanticPlugin, index_templatePlugin as templatePlugin, index_themePlugin as themePlugin, index_trueColorPlugin as trueColorPlugin };
|
|
431
562
|
}
|
|
432
563
|
|
|
433
|
-
export {
|
|
564
|
+
export { nestingPlugin as A, BuilderPigment as B, type ColorSupport as C, environmentPlugin as D, type EventHandler as E, gradientPlugin as F, type GradientPluginOptions as G, themePlugin as H, semanticPlugin as I, boxPlugin as J, type Kernel as K, templatePlugin as L, pigmentPlugin as M, type PigmentOptions as P, type Styler as S, type ThemePreset as T, type PigmentInstance as a, type Pigment as b, type Platform as c, type Plugin as d, type PigmentKernel as e, type PigmentContext as f, type PigmentEvents as g, type Style as h, index as i, type StyleFunction as j, type BoxBorder as k, type ThemePluginOptions as l, type BoxPluginOptions as m, type PigmentPluginOptions as n, type SemanticPluginOptions as o, type ThemePresetColors as p, type BoxChars as q, type KernelOptions as r, type PigmentPluginApi as s, type ColorInput as t, type ThemeColorType as u, type BoxOptions as v, baseColorsPlugin as w, modifiersPlugin as x, ansi256Plugin as y, trueColorPlugin as z };
|
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
import { Plugin as Plugin$1, Kernel as Kernel$1 } from '@oxog/types';
|
|
2
2
|
import { KernelInstance } from '@oxog/plugin';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Builder-pattern Pigment for explicit composition.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const builder = new BuilderPigment(kernel);
|
|
10
|
+
* const styled = builder.bold().red().paint('Error!');
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare class BuilderPigment {
|
|
14
|
+
private styles;
|
|
15
|
+
private readonly kernel;
|
|
16
|
+
constructor(kernel?: PigmentKernel);
|
|
17
|
+
/** The instance's color level (true color when there is no kernel). */
|
|
18
|
+
private get level();
|
|
19
|
+
bold(): this;
|
|
20
|
+
dim(): this;
|
|
21
|
+
italic(): this;
|
|
22
|
+
underline(): this;
|
|
23
|
+
strikethrough(): this;
|
|
24
|
+
inverse(): this;
|
|
25
|
+
hidden(): this;
|
|
26
|
+
reset(): this;
|
|
27
|
+
black(): this;
|
|
28
|
+
red(): this;
|
|
29
|
+
green(): this;
|
|
30
|
+
yellow(): this;
|
|
31
|
+
blue(): this;
|
|
32
|
+
magenta(): this;
|
|
33
|
+
cyan(): this;
|
|
34
|
+
white(): this;
|
|
35
|
+
blackBright(): this;
|
|
36
|
+
redBright(): this;
|
|
37
|
+
greenBright(): this;
|
|
38
|
+
yellowBright(): this;
|
|
39
|
+
blueBright(): this;
|
|
40
|
+
magentaBright(): this;
|
|
41
|
+
cyanBright(): this;
|
|
42
|
+
whiteBright(): this;
|
|
43
|
+
gray(): this;
|
|
44
|
+
grey(): this;
|
|
45
|
+
bgBlack(): this;
|
|
46
|
+
bgRed(): this;
|
|
47
|
+
bgGreen(): this;
|
|
48
|
+
bgYellow(): this;
|
|
49
|
+
bgBlue(): this;
|
|
50
|
+
bgMagenta(): this;
|
|
51
|
+
bgCyan(): this;
|
|
52
|
+
bgWhite(): this;
|
|
53
|
+
bgBlackBright(): this;
|
|
54
|
+
bgRedBright(): this;
|
|
55
|
+
bgGreenBright(): this;
|
|
56
|
+
bgYellowBright(): this;
|
|
57
|
+
bgBlueBright(): this;
|
|
58
|
+
bgMagentaBright(): this;
|
|
59
|
+
bgCyanBright(): this;
|
|
60
|
+
bgWhiteBright(): this;
|
|
61
|
+
bgGray(): this;
|
|
62
|
+
bgGrey(): this;
|
|
63
|
+
ansi256(code: number): this;
|
|
64
|
+
bgAnsi256(code: number): this;
|
|
65
|
+
rgb(r: number, g: number, b: number): this;
|
|
66
|
+
bgRgb(r: number, g: number, b: number): this;
|
|
67
|
+
hex(color: string): this;
|
|
68
|
+
bgHex(color: string): this;
|
|
69
|
+
hsl(h: number, s: number, l: number): this;
|
|
70
|
+
bgHsl(h: number, s: number, l: number): this;
|
|
71
|
+
paint(text: string): string;
|
|
72
|
+
}
|
|
73
|
+
|
|
4
74
|
type PigmentOptions = {
|
|
5
75
|
level?: 0 | 1 | 2 | 3;
|
|
6
76
|
forceColor?: boolean;
|
|
@@ -23,6 +93,8 @@ type Style = {
|
|
|
23
93
|
background?: boolean;
|
|
24
94
|
};
|
|
25
95
|
type Pigment = {
|
|
96
|
+
/** Returns the (styled) text when colors are supported, otherwise an empty string */
|
|
97
|
+
visible: (text: string) => string;
|
|
26
98
|
bold: Pigment;
|
|
27
99
|
dim: Pigment;
|
|
28
100
|
italic: Pigment;
|
|
@@ -77,6 +149,58 @@ type Pigment = {
|
|
|
77
149
|
bgHsl(h: number, s: number, l: number): Pigment;
|
|
78
150
|
(text: string): string;
|
|
79
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* A color accepted by plugin methods: `'#rrggbb'` / `'#rgb'`, `'rgb(r, g, b)'`
|
|
154
|
+
* or `[r, g, b]`.
|
|
155
|
+
*/
|
|
156
|
+
type ColorInput = string | readonly [number, number, number];
|
|
157
|
+
/** Theme color roles used by `themePlugin`. */
|
|
158
|
+
type ThemeColorType = 'keyword' | 'string' | 'number' | 'comment' | 'error' | 'success' | 'warning' | 'info';
|
|
159
|
+
/** Options for `pigment.box()` (`boxPlugin`). */
|
|
160
|
+
type BoxOptions = {
|
|
161
|
+
border?: BoxBorder;
|
|
162
|
+
padding?: number;
|
|
163
|
+
/** Background color for the whole box. */
|
|
164
|
+
bgColor?: string;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Methods added to an instance by the optional plugins. Each one throws a
|
|
168
|
+
* `PluginError` naming the plugin to install when it is missing.
|
|
169
|
+
*/
|
|
170
|
+
type PigmentPluginApi = {
|
|
171
|
+
/** gradientPlugin: color each character along a gradient. */
|
|
172
|
+
gradient(start: ColorInput, end: ColorInput): (text: string) => string;
|
|
173
|
+
/** gradientPlugin: rainbow-colored text. */
|
|
174
|
+
rainbow(text: string): string;
|
|
175
|
+
/** themePlugin: style text with a theme role color. */
|
|
176
|
+
theme: Record<ThemeColorType, (text: string) => string>;
|
|
177
|
+
/** semanticPlugin */
|
|
178
|
+
success(text: string): string;
|
|
179
|
+
/** semanticPlugin */
|
|
180
|
+
error(text: string): string;
|
|
181
|
+
/** semanticPlugin */
|
|
182
|
+
warning(text: string): string;
|
|
183
|
+
/** semanticPlugin */
|
|
184
|
+
info(text: string): string;
|
|
185
|
+
/** semanticPlugin */
|
|
186
|
+
debug(text: string): string;
|
|
187
|
+
/** boxPlugin: draw a box around text. */
|
|
188
|
+
box(text: string, options?: BoxOptions): string;
|
|
189
|
+
/** templatePlugin: tagged template with `{style.chain text}` blocks. */
|
|
190
|
+
template(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* What `createPigment()` returns (and the `pigment` export): the chainable
|
|
194
|
+
* styler plus instance members.
|
|
195
|
+
*/
|
|
196
|
+
type PigmentInstance = Pigment & PigmentPluginApi & {
|
|
197
|
+
/** A new builder on every access. */
|
|
198
|
+
readonly builder: BuilderPigment;
|
|
199
|
+
readonly level: number;
|
|
200
|
+
readonly supportsColor: ColorSupport;
|
|
201
|
+
/** Install a plugin on this instance; returns the instance. */
|
|
202
|
+
use(plugin: Plugin<PigmentContext>): PigmentInstance;
|
|
203
|
+
};
|
|
80
204
|
/**
|
|
81
205
|
* Plugin interface - re-exported from @oxog/types.
|
|
82
206
|
* Use this for creating Pigment-compatible plugins.
|
|
@@ -102,6 +226,12 @@ interface PigmentContext {
|
|
|
102
226
|
colorSupport: ColorSupport;
|
|
103
227
|
/** Registered styles map */
|
|
104
228
|
styles?: Map<string, StyleFunction>;
|
|
229
|
+
environment?: {
|
|
230
|
+
isCI: boolean;
|
|
231
|
+
noColor: boolean;
|
|
232
|
+
forceColor: boolean;
|
|
233
|
+
term: string;
|
|
234
|
+
};
|
|
105
235
|
/** Colors map */
|
|
106
236
|
colors?: {
|
|
107
237
|
foreground: Record<string, number>;
|
|
@@ -374,7 +504,7 @@ declare function semanticPlugin(options?: SemanticPluginOptions): Plugin<Pigment
|
|
|
374
504
|
* // │ Hello World │
|
|
375
505
|
* // └─────────────┘
|
|
376
506
|
*
|
|
377
|
-
* pigment.box('Error!', { border: 'double',
|
|
507
|
+
* pigment.box('Error!', { border: 'double', padding: 2 });
|
|
378
508
|
* ```
|
|
379
509
|
*/
|
|
380
510
|
declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
|
|
@@ -391,7 +521,8 @@ declare function boxPlugin(options?: BoxPluginOptions): Plugin<PigmentContext>;
|
|
|
391
521
|
* plugins: [templatePlugin()]
|
|
392
522
|
* });
|
|
393
523
|
*
|
|
394
|
-
* console.log(pigment`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
524
|
+
* console.log(pigment.template`{red Error:} {bold ${name}} has {yellow ${count}} issues`);
|
|
525
|
+
* console.log(pigment.template`{bold.red CRITICAL:} {dim system {underline failure}}`);
|
|
395
526
|
* ```
|
|
396
527
|
*/
|
|
397
528
|
declare function templatePlugin(): Plugin<PigmentContext>;
|
|
@@ -430,4 +561,4 @@ declare namespace index {
|
|
|
430
561
|
export { index_ansi256Plugin as ansi256Plugin, index_baseColorsPlugin as baseColorsPlugin, index_boxPlugin as boxPlugin, index_environmentPlugin as environmentPlugin, index_gradientPlugin as gradientPlugin, index_modifiersPlugin as modifiersPlugin, index_nestingPlugin as nestingPlugin, index_pigmentPlugin as pigmentPlugin, index_semanticPlugin as semanticPlugin, index_templatePlugin as templatePlugin, index_themePlugin as themePlugin, index_trueColorPlugin as trueColorPlugin };
|
|
431
562
|
}
|
|
432
563
|
|
|
433
|
-
export {
|
|
564
|
+
export { nestingPlugin as A, BuilderPigment as B, type ColorSupport as C, environmentPlugin as D, type EventHandler as E, gradientPlugin as F, type GradientPluginOptions as G, themePlugin as H, semanticPlugin as I, boxPlugin as J, type Kernel as K, templatePlugin as L, pigmentPlugin as M, type PigmentOptions as P, type Styler as S, type ThemePreset as T, type PigmentInstance as a, type Pigment as b, type Platform as c, type Plugin as d, type PigmentKernel as e, type PigmentContext as f, type PigmentEvents as g, type Style as h, index as i, type StyleFunction as j, type BoxBorder as k, type ThemePluginOptions as l, type BoxPluginOptions as m, type PigmentPluginOptions as n, type SemanticPluginOptions as o, type ThemePresetColors as p, type BoxChars as q, type KernelOptions as r, type PigmentPluginApi as s, type ColorInput as t, type ThemeColorType as u, type BoxOptions as v, baseColorsPlugin as w, modifiersPlugin as x, ansi256Plugin as y, trueColorPlugin as z };
|