ansi-quantone 0.0.0-stage → 0.9.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +48 -2
  3. package/dst/ansi-quantone-api-color.d.ts +10 -0
  4. package/dst/ansi-quantone-api-color.js +44 -0
  5. package/dst/ansi-quantone-api-debug.d.ts +26 -0
  6. package/dst/ansi-quantone-api-debug.js +279 -0
  7. package/dst/ansi-quantone-api-mapping.d.ts +32 -0
  8. package/dst/ansi-quantone-api-mapping.js +55 -0
  9. package/dst/ansi-quantone-api-sgr.d.ts +30 -0
  10. package/dst/ansi-quantone-api-sgr.js +150 -0
  11. package/dst/ansi-quantone-api-stream.d.ts +7 -0
  12. package/dst/ansi-quantone-api-stream.js +194 -0
  13. package/dst/ansi-quantone-api-terminal.d.ts +12 -0
  14. package/dst/ansi-quantone-api-terminal.js +91 -0
  15. package/dst/ansi-quantone-api-types.d.ts +27 -0
  16. package/dst/ansi-quantone-api-types.js +6 -0
  17. package/dst/ansi-quantone-api.3 +85 -0
  18. package/dst/ansi-quantone-api.d.ts +11 -0
  19. package/dst/ansi-quantone-api.js +188 -0
  20. package/dst/ansi-quantone-cli.d.ts +7 -0
  21. package/dst/ansi-quantone-cli.js +256 -0
  22. package/dst/ansi-quantone.1 +123 -0
  23. package/etc/ansi-quantone.yaml +39 -0
  24. package/etc/eslint.mjs +81 -0
  25. package/etc/stx.conf +40 -0
  26. package/etc/tsc.json +25 -0
  27. package/package.json +57 -5
  28. package/src/ansi-quantone-api-color.ts +48 -0
  29. package/src/ansi-quantone-api-debug.ts +300 -0
  30. package/src/ansi-quantone-api-mapping.ts +77 -0
  31. package/src/ansi-quantone-api-sgr.ts +183 -0
  32. package/src/ansi-quantone-api-stream.ts +207 -0
  33. package/src/ansi-quantone-api-terminal.ts +102 -0
  34. package/src/ansi-quantone-api-types.ts +39 -0
  35. package/src/ansi-quantone-api.md +175 -0
  36. package/src/ansi-quantone-api.ts +214 -0
  37. package/src/ansi-quantone-cli.md +211 -0
  38. package/src/ansi-quantone-cli.ts +259 -0
@@ -0,0 +1,175 @@
1
+
2
+ # ansi-quantone-api(3) -- Recolor ANSI Color Sequences of CLI Commands onto a Toned Palette
3
+
4
+ ## SYNOPSIS
5
+
6
+ ```ts
7
+ import { run, stdioTerminal, type Config, type TerminalIO } from "ansi-quantone"
8
+
9
+ run(config: Config, command: string, args?: string[], terminal?: TerminalIO): Promise<number>
10
+ stdioTerminal(): TerminalIO
11
+ ```
12
+
13
+ ## DESCRIPTION
14
+
15
+ `ansi-quantone-api`, the API of *Recolor ANSI Color Sequences of CLI
16
+ Commands onto a Toned Palette*, runs an arbitrary command-line or
17
+ Terminal User Interface (TUI) application inside a Pseudo-Terminal
18
+ (PTY) on a terminal, intercepts the ANSI Select Graphic Rendition (SGR)
19
+ color escape sequences of its output, and maps every foreground and
20
+ background color onto a toned palette with the color quantizer
21
+ **Quantone**. It is used by the command-line tool `ansi-quantone`(1).
22
+
23
+ All explicit colors are recolored: the ANSI basic 8 colors, the bright
24
+ 8 colors, the 256-color palette, and RGB/truecolor. The RGB values of
25
+ the ANSI colors are queried from the terminal (via **OSC 4**), so the
26
+ actual color theme of the terminal is honored, with the canonical
27
+ **xterm** RGB values as the fallback for all colors not reported. The
28
+ recolored colors are always emitted as RGB/truecolor.
29
+
30
+ The terminal default colors carry no color value of their own. Hence,
31
+ their input colors are either given explicitly or queried from the
32
+ terminal (via **OSC 10** / **OSC 11**), and then mapped onto the palette
33
+ as well. The default foreground is established as an explicit
34
+ foreground color at startup and after every SGR 39 (default
35
+ foreground), SGR 0 (reset), RIS (full reset), and DECSTR (soft reset).
36
+ The default background instead is changed in the terminal itself (via
37
+ **OSC 11**), as only this also covers all never written screen cells.
38
+ On exit, it is restored to its originally queried color (via **OSC
39
+ 11**) and then reset (via **OSC 111**), and any default background
40
+ changes of the *command* itself are suppressed meanwhile.
41
+
42
+ ## API
43
+
44
+ - `run(`*config*`,` *command*`,` *args*`,` *terminal*`)`:
45
+ Spawns the *command* with its arguments *args* (default: none) in a
46
+ PTY, with the current working directory and environment of the
47
+ process, and recolors its output onto the *terminal* (default:
48
+ `stdioTerminal()`) according to the *config*. It resolves to the
49
+ exit code of the *command*, once it exited and the *terminal* is
50
+ restored again. It rejects with an `Error` on an invalid *config* or
51
+ if the *command* cannot be spawned.
52
+
53
+ - `stdioTerminal()`:
54
+ Returns the terminal I/O of the process stdio: output is written to
55
+ standard output, input is read from standard input, which is switched
56
+ into raw mode, and the signals `SIGTERM` and `SIGHUP` are forwarded
57
+ to the *command*.
58
+
59
+ - `Config`:
60
+ The configuration of `run()`, with the following fields:
61
+ `palette` (the palette options `neutral`, `accent`, `shades`,
62
+ `chromatic`, `floor`, `ceiling`, `threshold`, and `shift` of
63
+ **Quantone**), `foreground` and `background` (the input colors of the
64
+ terminal default colors: a color, `"auto"` to query them from the
65
+ terminal, falling back to ANSI color `7` resp. `0`, or `"none"` to
66
+ not recolor them), `reduce` (whether to reduce RGB/truecolor input
67
+ colors onto the perceptually nearest, by **OKLab** distance, of the
68
+ 256 ANSI colors before the color mappings), `mappings` (the list of
69
+ color mapping rules, see **COLOR MAPPINGS**), and `debug` (whether to
70
+ enable the debug mode, see **DEBUG MODE**).
71
+
72
+ - `TerminalIO`:
73
+ The terminal I/O of a run, e.g. the process stdio or a bridge to the
74
+ terminal of a Web UI, with the following fields: `query` (whether the
75
+ terminal answers color queries), `columns()` and `rows()` (its current
76
+ size), `write(`*data*`,` *cb*`)` (write output, returning `false` on
77
+ back-pressure), `onDrain(`*cb*`)` (once the output is drained again),
78
+ `onData(`*cb*`)` (on input data), `onResize(`*cb*`)` (on size
79
+ changes), `onSignal(`*cb*`)` (on the termination requests `SIGTERM`
80
+ and `SIGHUP`), `setup()` (switch into raw mode), and `restore()`
81
+ (restore the original mode). The `onData`, `onResize`, and `onSignal`
82
+ functions return a function to unregister the callback again.
83
+
84
+ A *color* is given in the hex notation `#RRGGBB` or `#RGB`, as an ANSI
85
+ color index `0`-`255`, or as an ANSI color name like `blue` or
86
+ `brightBlue`. All palette options not given take the defaults of
87
+ **Quantone**.
88
+
89
+ ## COLOR MAPPINGS
90
+
91
+ A color mapping rule has the form `<fg>/<bg> : <fg>/<bg>`, where the
92
+ left side is the source foreground/background color pair to match and
93
+ the right side is the replacement color pair. The colors are tracked
94
+ across all SGR sequences, so a rule always matches the current color
95
+ pair. The replacement colors are still mapped onto the palette. All
96
+ matching rules are applied in order, so later rules override earlier
97
+ ones. The processing order is: reducing (`reduce`), mapping, and
98
+ palette mapping.
99
+
100
+ A color of a rule is one of the following:
101
+
102
+ - `*`: On the source side, matches any color. On the target side,
103
+ keeps the current color.
104
+
105
+ - `default`: The terminal default color (SGR 39 / SGR 49).
106
+
107
+ - An ANSI color index `0`-`255` or an ANSI color name like `blue` or
108
+ `brightBlue`. It matches the ANSI color in all its forms, i.e.,
109
+ `blue`, `4`, SGR 34, and SGR 38;5;4 are the same color.
110
+
111
+ - A hex color `#RRGGBB` or `#RGB`. It matches RGB/truecolor input
112
+ colors with exactly this value only.
113
+
114
+ - A range `<from>..<to>` of ANSI color indices (e.g. `232..243`).
115
+ Allowed on the source side only.
116
+
117
+ - A class `@<family>`, `@<tone>`, or `@<family>.<tone>` (e.g. `@warm`,
118
+ `@light`, or `@cool.dark`), matching all colors except `default` by
119
+ their RGB value (for ANSI colors, as queried from the terminal). The
120
+ family is `grey` (alias `gray`) for colors with a chroma (max minus
121
+ min channel) below 48, `warm` for the hues from 280° to 60°, and
122
+ `cool` for the hues from 60° to 280°. The tone is `dark` for a luma
123
+ (Rec. 709) below 64, `light` for one above 180, and `mid` otherwise.
124
+ Allowed on the source side only.
125
+
126
+ ## DEBUG MODE
127
+
128
+ In debug mode (`debug`), the source and target output are additionally
129
+ emulated on two virtual screens. The key sequence `CTRL+a d` toggles a
130
+ debug overlay, consisting of a debug cursor and an info box. The debug
131
+ cursor is a red 3x3 frame with rounded corners around the observed
132
+ character, initially in the center of the screen.
133
+
134
+ The info box in the top-right corner (or in the top-left corner, if the
135
+ debug cursor is in the upper-right quadrant of the screen) shows the
136
+ position and code point of the observed character, plus its source and
137
+ target foreground and background colors, each with a color swatch. For
138
+ a source ANSI color, its RGB value as the input of the recoloring is
139
+ shown, too.
140
+
141
+ While the overlay is displayed, the cursor keys move the debug cursor,
142
+ a left mouse click positions it, and all other input is discarded. For
143
+ this, the mouse click reporting of the terminal is enabled meanwhile,
144
+ and the mouse modes of the *command* are restored afterwards. The key
145
+ sequences `CTRL+a a` and `CTRL+a CTRL+a` send a literal `CTRL+a` to the
146
+ *command*.
147
+
148
+ The keys are recognized in their legacy encoding as well as in the
149
+ encodings of the xterm *modifyOtherKeys* and the *kitty keyboard
150
+ protocol*, as enabled by some applications. Inside **tmux**(1) or
151
+ **screen**(1) with `CTRL+a` as their prefix key, press `CTRL+a a d`.
152
+
153
+ ## EXAMPLE
154
+
155
+ ```ts
156
+ import { run } from "ansi-quantone"
157
+
158
+ const exitCode = await run({
159
+ palette: { neutral: "#999999", accent: "#336699", shades: 16 },
160
+ foreground: "auto",
161
+ background: "none",
162
+ reduce: true,
163
+ mappings: [ "*/blue : */black" ],
164
+ debug: false
165
+ }, "htop")
166
+ ```
167
+
168
+ ## SEE ALSO
169
+
170
+ `ansi-quantone`(1), `quantone`(1), `ansi-recolor`(1)
171
+
172
+ ## AUTHOR
173
+
174
+ Dr. Ralf S. Engelschall <rse@engelschall.com>
175
+
@@ -0,0 +1,214 @@
1
+ /*!
2
+ ** ansi-quantone -- Recolor ANSI Color Sequences of CLI Commands onto a Toned Palette
3
+ ** Copyright (c) 2026 Dr. Ralf S. Engelschall <rse@engelschall.com>
4
+ ** Licensed under MIT license
5
+ */
6
+
7
+ import process from "node:process"
8
+
9
+ import * as pty from "node-pty"
10
+ import { quantone, type QuantoneOptions, type QuantoneColor } from "quantone"
11
+
12
+ import type { DefaultColor, Config, TerminalIO } from "./ansi-quantone-api-types.js"
13
+ import { xtermColors, queryColors, stdioTerminal } from "./ansi-quantone-api-terminal.js"
14
+ import { type ColorMapping, parseMapping } from "./ansi-quantone-api-mapping.js"
15
+ import { rgbToOKLab } from "./ansi-quantone-api-color.js"
16
+ import { type Recolor, mapColor } from "./ansi-quantone-api-sgr.js"
17
+ import { processChunk } from "./ansi-quantone-api-stream.js"
18
+ import { type Debug, mouseModes, debugFeed, debugInput } from "./ansi-quantone-api-debug.js"
19
+
20
+ export type { QuantoneOptions, QuantoneColor, DefaultColor, Config, TerminalIO }
21
+ export { stdioTerminal }
22
+
23
+ /* ==== API entry point ==== */
24
+
25
+ /* run a command in a PTY on a terminal and recolor its output according to a configuration,
26
+ and resolve to the exit code of the command once it exited */
27
+ export const run = async (config: Config, command: string, args: string[] = [],
28
+ terminal: TerminalIO = stdioTerminal()): Promise<number> => {
29
+ const options = config.palette
30
+
31
+ /* validate the palette options and explicit default colors once upfront */
32
+ try {
33
+ quantone(options, 0)
34
+ for (const color of [ config.foreground, config.background ])
35
+ if (color !== "auto" && color !== "none")
36
+ quantone(options, color)
37
+ }
38
+ catch (err: unknown) {
39
+ throw new Error(`invalid palette options: ${err instanceof Error ? err.message : String(err)}`)
40
+ }
41
+
42
+ /* parse the color mappings */
43
+ const mappings: ColorMapping[] = []
44
+ for (const text of config.mappings) {
45
+ try {
46
+ mappings.push(parseMapping(text))
47
+ }
48
+ catch (err: unknown) {
49
+ throw new Error(`invalid color mapping "${text}": ${err instanceof Error ? err.message : String(err)}`)
50
+ }
51
+ }
52
+
53
+ /* switch the terminal into raw mode */
54
+ terminal.setup()
55
+
56
+ /* query the terminal for its ANSI colors and the default colors which are determined
57
+ automatically (the default background always, to explicitly restore it on exit) */
58
+ const codes = [
59
+ ...Array.from({ length: 256 }, (_, i) => `4;${i}`),
60
+ ...(config.foreground === "auto" ? [ "10" ] : []),
61
+ ...(config.background !== "none" ? [ "11" ] : [])
62
+ ]
63
+ const answer = terminal.query ?
64
+ await queryColors(terminal, codes) : { colors: new Map<string, string>(), rest: Buffer.alloc(0) }
65
+
66
+ /* determine the recoloring context (with the canonical xterm values as the fallbacks
67
+ of the ANSI colors, and the ANSI colors 7/0 as the fallbacks of the default colors) */
68
+ const ansi = xtermColors.map((hex, i) => answer.colors.get(`4;${i}`) ?? hex)
69
+ const resolveColor = (color: DefaultColor, code: string, fallback: number): QuantoneColor | null =>
70
+ color === "none" ? null : color === "auto" ? (answer.colors.get(code) ?? ansi[fallback]) : color
71
+ const fg = resolveColor(config.foreground, "10", 7)
72
+ const bg = resolveColor(config.background, "11", 0)
73
+ const fgSGR = fg !== null ? mapColor(options, fg, "fg") : null
74
+ const bgOSC = bg !== null ?
75
+ `\x1b]11;${quantone(options, bg).replace(/^#(..)(..)(..)$/, "rgb:$1/$2/$3")}\x1b\\` : null
76
+ const rc: Recolor = {
77
+ options,
78
+ fgSGR,
79
+ bgOSC,
80
+ defaults: Buffer.from((bgOSC ?? "") + (fgSGR !== null ? `\x1b[${fgSGR.join(";")}m` : "")),
81
+ ansi,
82
+ lab: config.reduce ? ansi.map((hex) => rgbToOKLab(parseInt(hex.substring(1), 16))) : null,
83
+ reduced: new Map<number, number>(),
84
+ mappings,
85
+ src: { fg: { type: "default" }, bg: { type: "default" } },
86
+ dst: { fg: { type: "default" }, bg: { type: "default" } },
87
+ buf: Buffer.alloc(0)
88
+ }
89
+
90
+ /* establish the mapped default colors and reset them again on exit
91
+ (the background is explicitly restored, as not all terminals support OSC 111) */
92
+ const bgOrig = answer.colors.get("11")
93
+ const bgReset = (bgOrig !== undefined ?
94
+ `\x1b]11;${bgOrig.replace(/^#(..)(..)(..)$/, "rgb:$1/$2/$3")}\x1b\\` : "") + "\x1b]111\x1b\\"
95
+ const reset = (fgSGR !== null ? "\x1b[39m" : "") + (bgOSC !== null ? bgReset : "")
96
+ terminal.write(rc.defaults)
97
+
98
+ /* create the debug mode context with the emulated source and target screens
99
+ (where the target screen starts with the mapped default colors, too, and
100
+ where the terminal emulator is loaded in debug mode only) */
101
+ const xterm = config.debug ? (await import("@xterm/headless")).default : null
102
+ const screen = (xt: NonNullable<typeof xterm>) => new xt.Terminal({
103
+ cols: terminal.columns(),
104
+ rows: terminal.rows(),
105
+ scrollback: 0,
106
+ allowProposedApi: true
107
+ })
108
+ const dbg: Debug | null = xterm === null ? null : {
109
+ src: screen(xterm),
110
+ dst: screen(xterm),
111
+ pending: 0,
112
+ prefix: null,
113
+ active: false,
114
+ x: 0,
115
+ y: 0,
116
+ covered: new Set<number>(),
117
+ full: false,
118
+ ansi,
119
+ hints: {
120
+ srcfg: fg !== null ? String(fg) : "",
121
+ srcbg: bg !== null ? String(bg) : "",
122
+ dstfg: "",
123
+ dstbg: bg !== null ? quantone(options, bg) : ""
124
+ },
125
+ mouse: new Map<number, boolean>(),
126
+ mouseOn: false,
127
+ output: terminal
128
+ }
129
+ if (dbg !== null) {
130
+ debugFeed(dbg, Buffer.alloc(0), rc.defaults)
131
+
132
+ /* track the mouse modes of the command (for restoring them after the debug overlay) */
133
+ for (const final of [ "h", "l" ]) {
134
+ dbg.dst.parser.registerCsiHandler({ prefix: "?", final }, (params) => {
135
+ for (const param of params)
136
+ if (typeof param === "number" && mouseModes.includes(param))
137
+ dbg.mouse.set(param, final === "h")
138
+ return false
139
+ })
140
+ }
141
+ }
142
+
143
+ /* spawn the command in a PTY
144
+ (on failure, reset the mapped default colors and restore the terminal again) */
145
+ let term: pty.IPty
146
+ try {
147
+ term = pty.spawn(command, args, {
148
+ name: process.env["TERM"] ?? "xterm-color",
149
+ cols: terminal.columns(),
150
+ rows: terminal.rows(),
151
+ cwd: process.cwd(),
152
+ env: Object.fromEntries(
153
+ Object.entries(process.env)
154
+ .filter((e): e is [ string, string ] => e[1] !== undefined)),
155
+ encoding: null
156
+ })
157
+ }
158
+ catch (err: unknown) {
159
+ terminal.write(reset)
160
+ terminal.restore()
161
+ throw new Error(`failed to spawn command "${command}": ${err instanceof Error ? err.message : String(err)}`)
162
+ }
163
+
164
+ /* pipe PTY output through color transformation to the terminal
165
+ (honoring back-pressure by pausing the PTY until the terminal drained) */
166
+ term.onData((data: Buffer | string) => {
167
+ const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data)
168
+ const transformed = processChunk(chunk, rc)
169
+ if (dbg !== null)
170
+ debugFeed(dbg, chunk, transformed)
171
+ if (transformed.length > 0 && !terminal.write(transformed)) {
172
+ term.pause()
173
+ terminal.onDrain(() => { term.resume() })
174
+ }
175
+ })
176
+
177
+ /* forward termination signals to the command
178
+ (for a regular exit which resets the mapped default colors) */
179
+ const offSignal = terminal.onSignal((signal) => { term.kill(signal) })
180
+
181
+ /* pipe the terminal input to the PTY (starting with the type-ahead received during the color query) */
182
+ if (answer.rest.length > 0)
183
+ term.write(answer.rest)
184
+ const offData = terminal.onData((data: Buffer) => {
185
+ if (dbg !== null)
186
+ debugInput(dbg, data, (bytes) => { term.write(bytes) })
187
+ else
188
+ term.write(data)
189
+ })
190
+
191
+ /* handle terminal resize (of the emulated screens in debug mode, too) */
192
+ const offResize = terminal.onResize(() => {
193
+ const cols = terminal.columns()
194
+ const rows = terminal.rows()
195
+ term.resize(cols, rows)
196
+ if (dbg !== null) {
197
+ dbg.src.resize(cols, rows)
198
+ dbg.dst.resize(cols, rows)
199
+ }
200
+ })
201
+
202
+ /* handle command exit: restore the terminal, reset the mapped default colors
203
+ (and the debug mouse mode), and resolve once all pending output is flushed */
204
+ return new Promise((resolve) => {
205
+ term.onExit(({ exitCode }: { exitCode: number }) => {
206
+ offData()
207
+ offResize()
208
+ offSignal()
209
+ terminal.restore()
210
+ terminal.write((dbg?.mouseOn ? "\x1b[?1000l\x1b[?1006l" : "") + reset, () => { resolve(exitCode) })
211
+ })
212
+ })
213
+ }
214
+
@@ -0,0 +1,211 @@
1
+
2
+ # ansi-quantone(1) -- Recolor ANSI Color Sequences of CLI Commands onto a Toned Palette
3
+
4
+ ## SYNOPSIS
5
+
6
+ `ansi-quantone`
7
+ \[`-h`|`--help`\]
8
+ \[`-V`|`--version`\]
9
+ \[`-C`|`--config` *config-file*\]
10
+ \[`-p`|`--profile` *name*\]
11
+ \[`-n`|`--neutral` *color*\]
12
+ \[`-a`|`--accent` *color*\]
13
+ \[`-s`|`--shades` *count*\]
14
+ \[`-c`|`--chromatic` *count*\]
15
+ \[`-l`|`--floor` *percent*\]
16
+ \[`-u`|`--ceiling` *percent*\]
17
+ \[`-t`|`--threshold` *chroma*\]
18
+ \[`-S`|`--shift` *degrees*\]
19
+ \[`-F`|`--foreground` *color*|`auto`|`none`\]
20
+ \[`-B`|`--background` *color*|`auto`|`none`\]
21
+ \[`-r`|`--reduce`\]
22
+ \[`-m`|`--map` *mapping*\[`,`...\]\]
23
+ \[`-d`|`--debug`\]
24
+ \[`--`\]
25
+ *command* \[*args* \[...\]\]
26
+
27
+ ## DESCRIPTION
28
+
29
+ `ansi-quantone`, *Recolor ANSI Color Sequences of CLI Commands onto a
30
+ Toned Palette*, is a small command-line tool to recolor the output of an
31
+ arbitrary command-line or Terminal User Interface (TUI) application. It
32
+ spawns the target *command* inside a Pseudo-Terminal (PTY), intercepts
33
+ the ANSI Select Graphic Rendition (SGR) color escape sequences of its
34
+ output, and maps every foreground and background color onto a toned
35
+ palette with the color quantizer **Quantone**.
36
+
37
+ The palette consists of one *neutral* ramp and *N* chromatic ramps, each
38
+ with the same number of *shades*. This way, the colors of any terminal
39
+ application are reduced to an unobtrusive and uniform color scheme,
40
+ without modifying the application itself.
41
+
42
+ The command-line tool is a thin wrapper around the `ansi-quantone-api`(3)
43
+ API: it determines the configuration from the configuration file and the
44
+ command-line options, and then runs the *command* on the terminal of the
45
+ process. See `ansi-quantone-api`(3) for the details of the recoloring,
46
+ the color mapping rules, and the debug mode. If standard output is not a
47
+ terminal (e.g. a pipe), the *command* is run directly, without a PTY and
48
+ without any recoloring.
49
+
50
+ ## OPTIONS
51
+
52
+ The following command-line options and arguments exist:
53
+
54
+ - \[`-h`|`--help`\]:
55
+ Show program usage information only.
56
+
57
+ - \[`-V`|`--version`\]:
58
+ Show program version information only.
59
+
60
+ - \[`-C`|`--config` *config-file*\]:
61
+ Read the palette options from the YAML *config-file*, which then has
62
+ to exist. The default is `~/.ansi-quantone.yaml` (in the user's home
63
+ directory), which is read only if it exists.
64
+
65
+ - \[`-p`|`--profile` *name*\]:
66
+ Use the profile section *name* of the configuration file, merged
67
+ after the sections `default` and `*`. If no such section exists, only
68
+ `default` and `*` are used (default: `default`).
69
+
70
+ - \[`-n`|`--neutral` *color*\]:
71
+ The base color of the neutral ramp (default: `#999999`).
72
+
73
+ - \[`-a`|`--accent` *color*\]:
74
+ The base color of the chromatic ramps (default: `#336699`).
75
+
76
+ - \[`-s`|`--shades` *count*\]:
77
+ The number of shades per ramp (minimum: 2, default: 16).
78
+
79
+ - \[`-c`|`--chromatic` *count*\]:
80
+ The number of chromatic hue segments (minimum: 1, default: 2).
81
+
82
+ - \[`-l`|`--floor` *percent*\]:
83
+ The **OKLCH** lightness floor of the chromatic ramps
84
+ (minimum: 0, default: 20).
85
+
86
+ - \[`-u`|`--ceiling` *percent*\]:
87
+ The **OKLCH** lightness inset below white of the chromatic ramps
88
+ (minimum: 0, default: 10, with floor plus ceiling below 100).
89
+
90
+ - \[`-t`|`--threshold` *chroma*\]:
91
+ The **OKLCH** chroma below which a color maps onto the neutral ramp
92
+ (minimum: 0, default: 0.04).
93
+
94
+ - \[`-S`|`--shift` *degrees*\]:
95
+ The **OKLCH** hue rotation of the input colors
96
+ (range: -180...180, default: 34).
97
+
98
+ - \[`-F`|`--foreground` *color*|`auto`|`none`\]:
99
+ The input color of the terminal default foreground, which is
100
+ mapped onto the palette. With `auto`, it is queried from the
101
+ terminal, falling back to ANSI color `7`. With `none`, the default
102
+ foreground is not recolored at all (default: `auto`).
103
+
104
+ - \[`-B`|`--background` *color*|`auto`|`none`\]:
105
+ The input color of the terminal default background, which is
106
+ mapped onto the palette. With `auto`, it is queried from the
107
+ terminal, falling back to ANSI color `0`. With `none`, the default
108
+ background is not recolored at all (default: `none`).
109
+
110
+ - \[`-r`|`--reduce`\]:
111
+ Reduce all RGB/truecolor input colors onto the perceptually nearest
112
+ of the 256 ANSI colors, before applying the color mappings.
113
+
114
+ - \[`-m`|`--map` *mapping*\[`,`...\]\]:
115
+ Remap input colors with one or more color *mapping* rules of the form
116
+ `<fg>/<bg> : <fg>/<bg>`. The option can be given multiple times, each
117
+ time with a comma-separated list of rules.
118
+
119
+ - \[`-d`|`--debug`\]:
120
+ Enable the debug mode, in which the key sequence `CTRL+a d` toggles
121
+ a debug overlay.
122
+
123
+ - *command* \[*args* \[...\]\]:
124
+ The target application to spawn inside the PTY, followed by its
125
+ optional arguments. Use `--` to separate `ansi-quantone` options
126
+ from the target command if the command starts with a hyphen.
127
+
128
+ A *color* is given in the hex notation `#RRGGBB` or `#RGB`, as an ANSI
129
+ color index `0`-`255`, or as an ANSI color name like `blue` or
130
+ `brightBlue`. The palette options given on the command-line override the
131
+ ones of the configuration file, and all options not given at all take
132
+ the defaults of **Quantone**.
133
+
134
+ ## CONFIGURATION
135
+
136
+ The configuration file of `ansi-quantone` is a YAML file with a mapping
137
+ of profile sections. The effective configuration is created by merging
138
+ the sections `default`, `*`, and the profile selected with option `-p`
139
+ (if it exists), in this order: later options override earlier ones,
140
+ while the color mapping rules `mappings` are accumulated in this order.
141
+ All sections are optional.
142
+
143
+ Each profile section is a mapping of the optional palette options
144
+ `neutral`, `accent`, `shades`, `chromatic`, `floor`, `ceiling`,
145
+ `threshold`, and `shift`, the optional default color options
146
+ `foreground` and `background`, the optional boolean `reduce`, and the
147
+ optional list of color mapping rules `mappings`, which correspond to the
148
+ command-line options of the same name (resp. `--map`). Other keys are
149
+ rejected. The color mapping rules of the command-line are appended to
150
+ the ones of the configuration file.
151
+
152
+ ## EXAMPLE
153
+
154
+ An example configuration file `~/.ansi-quantone.yaml`:
155
+
156
+ ```yaml
157
+ default:
158
+ neutral: "#999999"
159
+ accent: "#336699"
160
+ shades: 16
161
+ chromatic: 2
162
+ floor: 20
163
+ ceiling: 10
164
+ threshold: 0.04
165
+ shift: 34
166
+ foreground: auto
167
+ background: none
168
+ "*":
169
+ reduce: true
170
+ mappings:
171
+ - "@warm/* : red/*"
172
+ - "232..243/* : default/*"
173
+ mc:
174
+ background: auto
175
+ mappings:
176
+ - "*/blue : */black"
177
+ ```
178
+
179
+ Example invocations:
180
+
181
+ ```sh
182
+ # run "mc" (Midnight Commander) with the default configuration file
183
+ $ ansi-quantone -- mc
184
+
185
+ # run "mc" with the "mc" profile of the default configuration file
186
+ $ ansi-quantone -p mc -- mc
187
+
188
+ # run "ls" with an explicit configuration file
189
+ $ ansi-quantone -C ~/.ansi-quantone-dark.yaml -- ls -l --color=always
190
+
191
+ # run "htop" with a palette of 8 shades of grey, blue, red, and green
192
+ $ ansi-quantone -n "#888" -a "#336699" -s 8 -c 3 -- htop
193
+
194
+ # run "vim" with recolored default foreground and background colors
195
+ $ ansi-quantone -F auto -B auto -- vim
196
+
197
+ # run "lazygit" with reduced RGB colors and remapped blue backgrounds
198
+ $ ansi-quantone -r -m "*/blue : */black" -m "yellow/* : white/*" -- lazygit
199
+
200
+ # run "htop" in debug mode to inspect the colors with "CTRL+a d"
201
+ $ ansi-quantone -d -- htop
202
+ ```
203
+
204
+ ## SEE ALSO
205
+
206
+ `ansi-quantone-api`(3), `quantone`(1), `ansi-recolor`(1)
207
+
208
+ ## AUTHOR
209
+
210
+ Dr. Ralf S. Engelschall <rse@engelschall.com>
211
+