@hncode/hncode 0.7.6 → 0.7.8
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/package.json +1 -1
- package/src/colors.js +586 -556
- package/src/tools/bash.js +427 -420
- package/src/tools/ptc.js +2 -2
- package/src/tools/read.js +3 -0
- package/src/tui.js +174 -52
package/src/colors.js
CHANGED
|
@@ -1,556 +1,586 @@
|
|
|
1
|
-
// Cyan-blue visual theme for hncode. Adapts to the terminal's color depth:
|
|
2
|
-
// uses true-color when available, 256/16-color fallbacks otherwise.
|
|
3
|
-
|
|
4
|
-
function colorDepth() {
|
|
5
|
-
try { return process.stdout.getColorDepth?.() || 0; } catch { return 0; }
|
|
6
|
-
}
|
|
7
|
-
const DEPTH = colorDepth();
|
|
8
|
-
export const TRUECOLOR = DEPTH >= 24 || process.env.COLORTERM === 'truecolor' || /^xterm.*-256color$|.*-truecolor$/.test(process.env.TERM || '');
|
|
9
|
-
|
|
10
|
-
function rgb(r, g, b) { return TRUECOLOR ? `\x1b[38;2;${r};${g};${b}m` : `\x1b[38;5;${ansi256(r, g, b)}m`; }
|
|
11
|
-
function brgb(r, g, b) { return TRUECOLOR ? `\x1b[48;2;${r};${g};${b}m` : `\x1b[48;5;${ansi256(r, g, b)}m`; }
|
|
12
|
-
|
|
13
|
-
// Quantize a truecolor triple to the nearest 256-colour xterm index.
|
|
14
|
-
//
|
|
15
|
-
// Two different palettes live in xterm-256 and they must not be confused:
|
|
16
|
-
// * the 6x6x6 COLOUR CUBE (16..231): each channel has 6 levels — 0, then
|
|
17
|
-
// 95,135,175,215,255 — so the step is 40 above a floor of 35, not 51;
|
|
18
|
-
// * the GREY RAMP (232..255): 24 levels from rgb(8) to rgb(238), steps of 10.
|
|
19
|
-
//
|
|
20
|
-
// The grey case used to be `232 + Math.round(v / 51)`, which collapses a whole range of
|
|
21
|
-
// greys onto a few ramp entries: rgb(46,46,46) — the panel surface — quantised to 233,
|
|
22
|
-
// i.e. rgb(18,18,18), three steps darker than asked for. The panel then read as a
|
|
23
|
-
// near-black hole instead of a raised surface. Quantising against the ramp's own step
|
|
24
|
-
// fixes that.
|
|
25
|
-
function ansi256(r, g, b) {
|
|
26
|
-
const cube = (v) => (v < 48 ? 0 : v < 115 ? 1 : Math.min(5, Math.round((v - 35) / 40)));
|
|
27
|
-
// A triple that is (nearly) neutral belongs on the grey ramp, which has finer steps
|
|
28
|
-
// than the cube's 6 levels: rgb(46,46,46) is not representable in the cube at all.
|
|
29
|
-
const max = Math.max(r, g, b);
|
|
30
|
-
const min = Math.min(r, g, b);
|
|
31
|
-
if (max - min <= 8) {
|
|
32
|
-
const v = (r + g + b) / 3;
|
|
33
|
-
const n = Math.max(0, Math.min(23, Math.round((v - 8) / 10)));
|
|
34
|
-
return 232 + n;
|
|
35
|
-
}
|
|
36
|
-
return 16 + 36 * cube(r) + 6 * cube(g) + cube(b);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Brand accent: cyan-blue.
|
|
40
|
-
// A BACKGROUND escape at the terminal's own colour depth: the exact triple under
|
|
41
|
-
// truecolor, the nearest palette index otherwise.
|
|
42
|
-
//
|
|
43
|
-
// Exported because a caller computing a NEW colour at paint time — the backdrop dimming
|
|
44
|
-
// does, when it pulls a fill toward the page — has to state its result in the same notation
|
|
45
|
-
// the untouched fills use. Emitting `48;2;…` unconditionally loses the fill entirely on a
|
|
46
|
-
// 256-colour terminal, which silently ignores what it does not implement.
|
|
47
|
-
export const bgRgb = brgb;
|
|
48
|
-
|
|
49
|
-
export const TEAL = rgb(0, 184, 219);
|
|
50
|
-
export const CYAN = rgb(0, 215, 255);
|
|
51
|
-
export const BLUE = rgb(66, 135, 245);
|
|
52
|
-
export const FG = TEAL; // primary fg
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
export
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
269
|
-
|
|
270
|
-
//
|
|
271
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
// yellow
|
|
297
|
-
|
|
298
|
-
//
|
|
299
|
-
//
|
|
300
|
-
//
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
//
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
//
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
//
|
|
320
|
-
//
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
//
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
*
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
//
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
// not
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
//
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
C.
|
|
414
|
-
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
//
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
C.
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
//
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
//
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
//
|
|
496
|
-
|
|
497
|
-
//
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
//
|
|
504
|
-
//
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
//
|
|
516
|
-
|
|
517
|
-
//
|
|
518
|
-
|
|
519
|
-
//
|
|
520
|
-
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
export function
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
1
|
+
// Cyan-blue visual theme for hncode. Adapts to the terminal's color depth:
|
|
2
|
+
// uses true-color when available, 256/16-color fallbacks otherwise.
|
|
3
|
+
|
|
4
|
+
function colorDepth() {
|
|
5
|
+
try { return process.stdout.getColorDepth?.() || 0; } catch { return 0; }
|
|
6
|
+
}
|
|
7
|
+
const DEPTH = colorDepth();
|
|
8
|
+
export const TRUECOLOR = DEPTH >= 24 || process.env.COLORTERM === 'truecolor' || /^xterm.*-256color$|.*-truecolor$/.test(process.env.TERM || '');
|
|
9
|
+
|
|
10
|
+
function rgb(r, g, b) { return TRUECOLOR ? `\x1b[38;2;${r};${g};${b}m` : `\x1b[38;5;${ansi256(r, g, b)}m`; }
|
|
11
|
+
function brgb(r, g, b) { return TRUECOLOR ? `\x1b[48;2;${r};${g};${b}m` : `\x1b[48;5;${ansi256(r, g, b)}m`; }
|
|
12
|
+
|
|
13
|
+
// Quantize a truecolor triple to the nearest 256-colour xterm index.
|
|
14
|
+
//
|
|
15
|
+
// Two different palettes live in xterm-256 and they must not be confused:
|
|
16
|
+
// * the 6x6x6 COLOUR CUBE (16..231): each channel has 6 levels — 0, then
|
|
17
|
+
// 95,135,175,215,255 — so the step is 40 above a floor of 35, not 51;
|
|
18
|
+
// * the GREY RAMP (232..255): 24 levels from rgb(8) to rgb(238), steps of 10.
|
|
19
|
+
//
|
|
20
|
+
// The grey case used to be `232 + Math.round(v / 51)`, which collapses a whole range of
|
|
21
|
+
// greys onto a few ramp entries: rgb(46,46,46) — the panel surface — quantised to 233,
|
|
22
|
+
// i.e. rgb(18,18,18), three steps darker than asked for. The panel then read as a
|
|
23
|
+
// near-black hole instead of a raised surface. Quantising against the ramp's own step
|
|
24
|
+
// fixes that.
|
|
25
|
+
function ansi256(r, g, b) {
|
|
26
|
+
const cube = (v) => (v < 48 ? 0 : v < 115 ? 1 : Math.min(5, Math.round((v - 35) / 40)));
|
|
27
|
+
// A triple that is (nearly) neutral belongs on the grey ramp, which has finer steps
|
|
28
|
+
// than the cube's 6 levels: rgb(46,46,46) is not representable in the cube at all.
|
|
29
|
+
const max = Math.max(r, g, b);
|
|
30
|
+
const min = Math.min(r, g, b);
|
|
31
|
+
if (max - min <= 8) {
|
|
32
|
+
const v = (r + g + b) / 3;
|
|
33
|
+
const n = Math.max(0, Math.min(23, Math.round((v - 8) / 10)));
|
|
34
|
+
return 232 + n;
|
|
35
|
+
}
|
|
36
|
+
return 16 + 36 * cube(r) + 6 * cube(g) + cube(b);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Brand accent: cyan-blue.
|
|
40
|
+
// A BACKGROUND escape at the terminal's own colour depth: the exact triple under
|
|
41
|
+
// truecolor, the nearest palette index otherwise.
|
|
42
|
+
//
|
|
43
|
+
// Exported because a caller computing a NEW colour at paint time — the backdrop dimming
|
|
44
|
+
// does, when it pulls a fill toward the page — has to state its result in the same notation
|
|
45
|
+
// the untouched fills use. Emitting `48;2;…` unconditionally loses the fill entirely on a
|
|
46
|
+
// 256-colour terminal, which silently ignores what it does not implement.
|
|
47
|
+
export const bgRgb = brgb;
|
|
48
|
+
|
|
49
|
+
export const TEAL = rgb(0, 184, 219);
|
|
50
|
+
export const CYAN = rgb(0, 215, 255);
|
|
51
|
+
export const BLUE = rgb(66, 135, 245);
|
|
52
|
+
export const FG = TEAL; // primary fg
|
|
53
|
+
// `brgb`, not `rgb`: this constant is used as a BACKGROUND (`C.bg`), and a foreground sequence in a background
|
|
54
|
+
// slot is silently ignored — the cell keeps whatever background was already in force. It only ever looked correct
|
|
55
|
+
// because `setTheme` overwrites `C.bg` on startup, so the wrong escape survived in the initial value where nothing
|
|
56
|
+
// exercised it.
|
|
57
|
+
export const BG = brgb(0, 18, 26);
|
|
58
|
+
export const BORDER = rgb(70, 130, 180);
|
|
59
|
+
|
|
60
|
+
// Named accent colours per theme. `auto` keeps the brand cyan-blue and lets the
|
|
61
|
+
// terminal's own palette show through for everything else; `dark`/`light` pick
|
|
62
|
+
// accent triples that stay readable on that background.
|
|
63
|
+
const THEMES = {
|
|
64
|
+
// `auto` is deliberately NOT a table here: it is a CHOICE, resolved by `setTheme` into
|
|
65
|
+
// `light` or `dark` from the terminal's background. A table named `auto` shadows that,
|
|
66
|
+
// and did — it was a fixed dark palette with brand-cyan text, while its own label claimed
|
|
67
|
+
// it followed the terminal.
|
|
68
|
+
dark: {
|
|
69
|
+
fg: [255, 255, 255], bg: [0, 18, 26], // White foreground for normal text
|
|
70
|
+
fg: [255, 255, 255], bg: [0, 18, 26], // White foreground for normal text
|
|
71
|
+
teal: [0, 184, 219], cyan: [0, 215, 255], blue: [66, 135, 245], border: [70, 130, 180],
|
|
72
|
+
// The semantic colours. They were missing, and `setTheme` guards each assignment, so
|
|
73
|
+
// they kept the previous theme's values — a theme that only looks right after a
|
|
74
|
+
// particular one was applied.
|
|
75
|
+
red: [230, 80, 80], green: [120, 200, 120], yellow: [230, 200, 100], orange: [240, 160, 80],
|
|
76
|
+
white: [255, 255, 255], gray: [130, 140, 150],
|
|
77
|
+
hover: [190, 245, 255], selBg: [0, 70, 84],
|
|
78
|
+
surface: [46, 46, 46],
|
|
79
|
+
},
|
|
80
|
+
light: {
|
|
81
|
+
fg: [26, 26, 26], bg: [250, 250, 250],
|
|
82
|
+
teal: [0, 102, 128], cyan: [0, 122, 153], blue: [10, 77, 158], border: [138, 155, 176],
|
|
83
|
+
hover: [0, 78, 102], selBg: [200, 230, 239],
|
|
84
|
+
red: [179, 38, 30], green: [30, 122, 60], yellow: [160, 120, 0], orange: [178, 90, 0],
|
|
85
|
+
white: [26, 26, 26], gray: [85, 85, 85],
|
|
86
|
+
// A LIGHT surface is a grey that is darker than the white page but far lighter than
|
|
87
|
+
// the dark themes' — a panel has to read as raised in whichever direction the theme
|
|
88
|
+
// goes, and reusing #2e2e2e on white would be a black box.
|
|
89
|
+
surface: [232, 232, 232],
|
|
90
|
+
},
|
|
91
|
+
// The four below are the same SHAPE as `dark` with the accent hue moved, so every
|
|
92
|
+
// derived colour in `setTheme` (the scrollbar shades, hover, and the light/dark branch
|
|
93
|
+
// test) keeps working with no special case. Each keeps ONE accent family varying only in
|
|
94
|
+
// lightness, because the context bar's five fills read as a gradient and a second hue in
|
|
95
|
+
// that ramp makes the bar look broken.
|
|
96
|
+
nord: {
|
|
97
|
+
fg: [216, 222, 233], bg: [46, 52, 64],
|
|
98
|
+
teal: [136, 192, 208], cyan: [143, 188, 187], blue: [129, 161, 193], border: [94, 129, 172],
|
|
99
|
+
hover: [236, 239, 244], selBg: [59, 66, 82],
|
|
100
|
+
red: [191, 97, 106], green: [163, 190, 140], yellow: [235, 203, 139], orange: [208, 135, 112],
|
|
101
|
+
white: [236, 239, 244], gray: [129, 135, 148],
|
|
102
|
+
surface: [59, 66, 82],
|
|
103
|
+
},
|
|
104
|
+
dracula: {
|
|
105
|
+
fg: [248, 248, 242], bg: [40, 42, 54],
|
|
106
|
+
teal: [139, 233, 253], cyan: [139, 233, 253], blue: [98, 114, 164], border: [98, 114, 164],
|
|
107
|
+
hover: [255, 121, 198], selBg: [68, 71, 90],
|
|
108
|
+
red: [255, 85, 85], green: [80, 250, 123], yellow: [241, 250, 140], orange: [255, 184, 108],
|
|
109
|
+
white: [248, 248, 242], gray: [98, 114, 164],
|
|
110
|
+
surface: [68, 71, 90],
|
|
111
|
+
},
|
|
112
|
+
gruvbox: {
|
|
113
|
+
fg: [235, 219, 178], bg: [40, 40, 40],
|
|
114
|
+
teal: [142, 192, 124], cyan: [131, 165, 152], blue: [69, 133, 136], border: [146, 131, 116],
|
|
115
|
+
hover: [250, 189, 47], selBg: [60, 56, 54],
|
|
116
|
+
red: [251, 73, 52], green: [184, 187, 38], yellow: [250, 189, 47], orange: [254, 128, 25],
|
|
117
|
+
white: [235, 219, 178], gray: [146, 131, 116],
|
|
118
|
+
surface: [60, 56, 54],
|
|
119
|
+
},
|
|
120
|
+
mono: {
|
|
121
|
+
// No hue at all: every accent is a grey, so the UI is readable on a monochrome
|
|
122
|
+
// terminal or for anyone who needs colour off without losing the structure that
|
|
123
|
+
// colour was carrying. The lightness steps are what keep the context bar legible.
|
|
124
|
+
fg: [230, 230, 230], bg: [18, 18, 18],
|
|
125
|
+
teal: [190, 190, 190], cyan: [210, 210, 210], blue: [150, 150, 150], border: [110, 110, 110],
|
|
126
|
+
hover: [255, 255, 255], selBg: [60, 60, 60],
|
|
127
|
+
red: [200, 90, 90], green: [140, 190, 140], yellow: [200, 190, 120], orange: [210, 160, 110],
|
|
128
|
+
white: [240, 240, 240], gray: [130, 130, 130],
|
|
129
|
+
surface: [42, 42, 42],
|
|
130
|
+
},
|
|
131
|
+
catppuccin: {
|
|
132
|
+
// Mocha: a warm-tinted dark with pastel accents. Every accent is desaturated toward
|
|
133
|
+
// the background so long replies do not glare, which is the whole point of the palette.
|
|
134
|
+
fg: [205, 214, 244], bg: [30, 30, 46],
|
|
135
|
+
teal: [137, 180, 250], cyan: [137, 220, 235], blue: [137, 180, 250], border: [108, 112, 134],
|
|
136
|
+
hover: [203, 166, 247], selBg: [49, 50, 68],
|
|
137
|
+
red: [243, 139, 168], green: [166, 227, 161], yellow: [249, 226, 175], orange: [250, 179, 135],
|
|
138
|
+
white: [205, 214, 244], gray: [127, 132, 156],
|
|
139
|
+
surface: [49, 50, 68],
|
|
140
|
+
},
|
|
141
|
+
tokyo: {
|
|
142
|
+
// Night: a blue-black with high-contrast accents. Distinct from nord, which is greyed
|
|
143
|
+
// out; this keeps the blue in the background and lets the cyan carry the structure.
|
|
144
|
+
fg: [192, 202, 245], bg: [26, 27, 38],
|
|
145
|
+
teal: [125, 207, 255], cyan: [125, 207, 255], blue: [122, 162, 247], border: [86, 95, 137],
|
|
146
|
+
hover: [187, 154, 247], selBg: [41, 46, 66],
|
|
147
|
+
red: [247, 118, 142], green: [158, 206, 106], yellow: [224, 175, 104], orange: [255, 158, 100],
|
|
148
|
+
white: [192, 202, 245], gray: [86, 95, 137],
|
|
149
|
+
surface: [41, 46, 66],
|
|
150
|
+
},
|
|
151
|
+
solar: {
|
|
152
|
+
// Solarized LIGHT. Included because `light` is a plain neutral and solarized's even
|
|
153
|
+
// hue ramp is the best-tested light palette in the terminal world. The dark variant is
|
|
154
|
+
// `solar-dark`, so both exist; the light one is the one worth having.
|
|
155
|
+
fg: [101, 123, 131], bg: [253, 246, 227],
|
|
156
|
+
teal: [38, 139, 210], cyan: [38, 139, 210], blue: [108, 113, 196], border: [147, 161, 161],
|
|
157
|
+
hover: [211, 54, 130], selBg: [238, 232, 213],
|
|
158
|
+
red: [220, 50, 47], green: [133, 153, 0], yellow: [181, 137, 0], orange: [203, 75, 22],
|
|
159
|
+
white: [101, 123, 131], gray: [147, 161, 161],
|
|
160
|
+
surface: [238, 232, 213],
|
|
161
|
+
},
|
|
162
|
+
rose: {
|
|
163
|
+
// Pine: a muted mauve dark, between dracula's saturation and nord's restraint.
|
|
164
|
+
fg: [224, 222, 244], bg: [25, 23, 36],
|
|
165
|
+
teal: [196, 167, 231], cyan: [137, 180, 250], blue: [137, 180, 250], border: [110, 106, 134],
|
|
166
|
+
hover: [196, 167, 231], selBg: [31, 29, 46],
|
|
167
|
+
red: [215, 130, 126], green: [156, 207, 216], yellow: [234, 157, 173], orange: [235, 188, 186],
|
|
168
|
+
white: [224, 222, 244], gray: [110, 106, 134],
|
|
169
|
+
surface: [31, 29, 46],
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
/** Theme name -> one-line description, for the /theme picker. */
|
|
173
|
+
export const THEME_LABELS = {
|
|
174
|
+
auto: 'follow the terminal: light theme on a light background, dark otherwise',
|
|
175
|
+
dark: 'dark teal background, white text',
|
|
176
|
+
light: 'light background, darkened accents',
|
|
177
|
+
nord: 'cool blue-grey',
|
|
178
|
+
dracula: 'high-contrast purple and pink',
|
|
179
|
+
gruvbox: 'warm retro earth tones',
|
|
180
|
+
catppuccin: 'soft pastel, warm-tinted dark',
|
|
181
|
+
tokyo: 'blue-black, high-contrast accents',
|
|
182
|
+
solar: 'even hue ramp, light background',
|
|
183
|
+
rose: 'muted mauve dark',
|
|
184
|
+
mono: 'greyscale, no hue',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/** `auto` is a name you can set without being a palette, so it is listed separately from
|
|
188
|
+
* the tables — see `setTheme` for how it resolves. */
|
|
189
|
+
export const AUTO_THEME = 'auto';
|
|
190
|
+
|
|
191
|
+
/** Whether a theme name is one we know. */
|
|
192
|
+
export function hasTheme(name) {
|
|
193
|
+
return name === AUTO_THEME || Object.prototype.hasOwnProperty.call(THEMES, name);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The names a user may choose, `auto` first because it is the default. */
|
|
197
|
+
export const THEME_NAMES = [AUTO_THEME, ...Object.keys(THEMES)];
|
|
198
|
+
|
|
199
|
+
/** True when a theme paints on a light background. Resolves `auto` first, so a caller
|
|
200
|
+
* asking about the CURRENT theme gets the answer for what is actually on screen. */
|
|
201
|
+
export function isLightTheme(name) {
|
|
202
|
+
const resolved = name === AUTO_THEME ? (autoIsLight ? 'light' : 'dark') : name;
|
|
203
|
+
const t = THEMES[resolved];
|
|
204
|
+
return !!(t && Array.isArray(t.bg) && t.bg[0] > 128);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export const C = {
|
|
208
|
+
reset: '\x1b[0m',
|
|
209
|
+
bold: '\x1b[1m',
|
|
210
|
+
dim: '\x1b[2m',
|
|
211
|
+
// Italic (SGR 3). Used for the BODY of a reasoning block — the prose reads as
|
|
212
|
+
// an aside rather than as the answer. Must be closed with SGR 23 (`endItalic`),
|
|
213
|
+
// NOT with `reset`, because resetting also drops the surrounding dim/gray that
|
|
214
|
+
// the same row depends on. Terminals without italic fall back to normal text,
|
|
215
|
+
// so this is a decoration, never load-bearing.
|
|
216
|
+
italic: '\x1b[3m',
|
|
217
|
+
endItalic: '\x1b[23m',
|
|
218
|
+
muted: '\x1b[90m',
|
|
219
|
+
teal: TEAL,
|
|
220
|
+
cyan: CYAN,
|
|
221
|
+
// The mark's shadow: the same cyan at 40% brightness. `dim` (SGR 2) is applied by the TERMINAL and most render
|
|
222
|
+
// it barely darker; `teal` is only ~15% off `cyan`. Neither reads as a shadow behind the letters.
|
|
223
|
+
cyanDeep: rgb(0, 86, 102),
|
|
224
|
+
// The startup heading: the grey the annotations use, lifted towards white. The wordmark above it owns the cyan,
|
|
225
|
+
// so the name under it is a lighter neutral rather than a second colour competing with the mark.
|
|
226
|
+
heading: rgb(200, 210, 220),
|
|
227
|
+
// DIFF COLOURS ARE DERIVED FROM THE THEME, not fixed.
|
|
228
|
+
//
|
|
229
|
+
// A diff paints two layers: the whole changed LINE gets a wash, and the words that actually differ get a
|
|
230
|
+
// stronger one. Those have to sit on THIS theme's background — the Islands Dark tints read as a warm grey on
|
|
231
|
+
// gruvbox and as nothing at all on `light`. `setTheme` recomputes all four from the theme's own `green`, `red`
|
|
232
|
+
// and `bg`, so switching themes recolours the diff with everything else. The values here are the dark defaults,
|
|
233
|
+
// used before any theme is applied.
|
|
234
|
+
diffAddBg: brgb(34, 58, 38),
|
|
235
|
+
diffAddWordBg: brgb(52, 96, 58),
|
|
236
|
+
diffDelBg: brgb(74, 32, 34),
|
|
237
|
+
diffDelWordBg: brgb(112, 44, 48),
|
|
238
|
+
diffAddFg: rgb(133, 208, 143),
|
|
239
|
+
diffDelFg: rgb(255, 176, 168),
|
|
240
|
+
// A code comment. `setTheme` mixes it from the palette's foreground towards its background, so it is quiet without
|
|
241
|
+
// disappearing — `C.gray` is tuned for the page and vanishes on a diff wash in several themes.
|
|
242
|
+
comment: '\x1b[90m',
|
|
243
|
+
fg: FG,
|
|
244
|
+
bg: BG,
|
|
245
|
+
bgTeal: brgb(0, 184, 219),
|
|
246
|
+
bgDim: brgb(12, 24, 30),
|
|
247
|
+
// Fills for the segmented context bar: five blues in one family, deepening towards
|
|
248
|
+
// black, plus a neutral free segment. Background colours, because the bar is read by
|
|
249
|
+
// FILL rather than by any text — a segment is usually only a few columns wide, so a
|
|
250
|
+
// letter inside it would be unreadable noise.
|
|
251
|
+
//
|
|
252
|
+
// The steps are deliberately narrow. Widening them makes the bar easier to tell apart
|
|
253
|
+
// at a glance but harder to keep a dark terminal readable, and the darkest member has
|
|
254
|
+
// to stay distinguishable from the page background it sits on.
|
|
255
|
+
ctxSystem: brgb(35, 48, 95), // deepest navy
|
|
256
|
+
ctxPrompt: brgb(43, 61, 120), // navy
|
|
257
|
+
ctxAssistant: brgb(52, 74, 146), // indigo
|
|
258
|
+
ctxThinking: brgb(77, 107, 254), // brand blue, the brightest used segment
|
|
259
|
+
ctxTools: brgb(90, 124, 255), // light blue
|
|
260
|
+
ctxFree: brgb(46, 46, 46), // neutral grey: "nothing here yet"
|
|
261
|
+
// The SURFACE colour for a floating panel (picker menus, dialogs). A NEUTRAL GREY,
|
|
262
|
+
// deliberately separate from the theme's `bg`:
|
|
263
|
+
//
|
|
264
|
+
// * the theme background is `[0, 18, 26]` — a dark TEAL. A raised surface should be
|
|
265
|
+
// neutral in every theme; only the ACCENTS carry the brand hue. Reusing `bg` for
|
|
266
|
+
// the panel made every popup read blue, which is not what a panel is.
|
|
267
|
+
// * `applyTheme` used to overwrite this with `t.bg`, so the value here only applied
|
|
268
|
+
// before a theme was set. It is no longer touched by the theme.
|
|
269
|
+
//
|
|
270
|
+
// xterm-256's grey ramp runs 232..255 from rgb(8) to rgb(238) in steps of 10, so 236
|
|
271
|
+
// is rgb(48,48,48) = #303030 — clearly lifted off a near-black terminal without
|
|
272
|
+
// washing the text out. Truecolor gets `#2e2e2e`, the same shade written exactly.
|
|
273
|
+
bgPanel: TRUECOLOR ? '\x1b[48;2;46;46;46m' : '\x1b[48;5;236m',
|
|
274
|
+
// The code-surface background, set by setTheme from the theme's own page colour. A placeholder until then, so
|
|
275
|
+
// code drawn before the first setTheme still has a surface.
|
|
276
|
+
codeBg: TRUECOLOR ? '\x1b[48;2;12;20;26m' : '\x1b[48;5;233m',
|
|
277
|
+
// The terminal-surface background, set by setTheme from the theme's page colour. Placeholder until then.
|
|
278
|
+
termBg: TRUECOLOR ? '\x1b[48;2;0;14;21m' : '\x1b[48;5;234m',
|
|
279
|
+
// The composer's neutral-grey surface. Placeholder until setTheme runs.
|
|
280
|
+
composerBg: TRUECOLOR ? '\x1b[48;2;44;44;46m' : '\x1b[48;5;237m',
|
|
281
|
+
border: BORDER,
|
|
282
|
+
red: '\x1b[91m',
|
|
283
|
+
green: '\x1b[92m',
|
|
284
|
+
yellow: '\x1b[93m',
|
|
285
|
+
magenta: '\x1b[95m',
|
|
286
|
+
gray: '\x1b[90m',
|
|
287
|
+
white: '\x1b[97m',
|
|
288
|
+
orange: TRUECOLOR ? rgb(255, 140, 0) : '\x1b[38;5;208m',
|
|
289
|
+
// Cyan pushed slightly toward green — used for the Swarm mode badge so it reads
|
|
290
|
+
// as its own mode next to Plan (pure cyan) and Focus (blue) while staying in the
|
|
291
|
+
// theme's blue-green family. 38;5;43 is rgb(0,215,175): red at zero and green
|
|
292
|
+
// only 40 above blue, i.e. still clearly cyan with a green cast. 38;5;85 was the
|
|
293
|
+
// first attempt and read as plain GREEN — its red channel is lifted to 95 and
|
|
294
|
+
// green pins at 255, which is a spring green, not a green-tinted cyan.
|
|
295
|
+
spring: TRUECOLOR ? rgb(0, 215, 175) : '\x1b[38;5;43m',
|
|
296
|
+
// Git branch in the status line: yellow pulled about half way toward white, so
|
|
297
|
+
// it stays clearly "yellow" (not cream/ivory) while reading brighter than the
|
|
298
|
+
// plain 93 yellow on a dark background. rgb(255,219,110) keeps red at max,
|
|
299
|
+
// green near it, and blue around 43% — that ratio is what keeps the hue
|
|
300
|
+
// yellow rather than dropping into orange.
|
|
301
|
+
branch: TRUECOLOR ? rgb(255, 219, 110) : '\x1b[38;5;222m',
|
|
302
|
+
// Shell-mode (`!`) accent — violet, matching kimi-code's shellMode token so the
|
|
303
|
+
// bash-mode editor border and the `!` read as "shell", distinct from the cyan
|
|
304
|
+
// prompt and the yellow git badge. #BD93F9 dark / #7C3AED light.
|
|
305
|
+
shellMode: TRUECOLOR ? rgb(189, 147, 249) : '\x1b[38;5;141m',
|
|
306
|
+
bgRed: '\x1b[41m',
|
|
307
|
+
bgGreen: '\x1b[42m',
|
|
308
|
+
// Selection highlight (mouse text selection) and the scrollbar gutter.
|
|
309
|
+
// Selection uses a dark teal background so white text stays readable.
|
|
310
|
+
selBg: TRUECOLOR ? brgb(0, 70, 84) : '\x1b[48;5;23m', // Original dark cyan background
|
|
311
|
+
// Reset ONLY the background colour, keeping the current foreground. Used to end
|
|
312
|
+
// a selection highlight so text after it keeps its own colour (a bare ESC[0m
|
|
313
|
+
// would also reset the foreground, turning a cyan/white run grey).
|
|
314
|
+
bgReset: '\x1b[49m',
|
|
315
|
+
// Scrollbar, styled after OpenTUI (what cline uses): a solid block thumb on a
|
|
316
|
+
// near-black track. Only the FOREGROUND colour is stateful — the track is always the
|
|
317
|
+
// background — because that is how OpenTUI's SliderRenderable paints a cell:
|
|
318
|
+
// foreground = thumb, background = track. A `█` covers both columns with the
|
|
319
|
+
// foreground, while `▀`/`▄` expose one half to the track, so the two colours must
|
|
320
|
+
// stay DISTINCT; giving a half-cell the thumb colour as its background is what made
|
|
321
|
+
// it read as a second square, and it also survived the modal backdrop's faint
|
|
322
|
+
// attribute, which fades the foreground only.
|
|
323
|
+
// track #252527 thumb #9a9ea3 (OpenTUI's defaults, inlined)
|
|
324
|
+
// hover #d2d6da active #ffffff (brighter thumb, not a new hue)
|
|
325
|
+
scrollTrackBg: TRUECOLOR ? brgb(0x25, 0x25, 0x27) : '\x1b[48;5;235m',
|
|
326
|
+
scrollTrackFg: TRUECOLOR ? rgb(0x25, 0x25, 0x27) : '\x1b[38;5;235m',
|
|
327
|
+
scrollThumbBg: TRUECOLOR ? brgb(0x9a, 0x9e, 0xa3) : '\x1b[48;5;246m',
|
|
328
|
+
scrollThumbFg: TRUECOLOR ? rgb(0x9a, 0x9e, 0xa3) : '\x1b[38;5;246m',
|
|
329
|
+
scrollThumbHoverBg: TRUECOLOR ? brgb(0xd2, 0xd6, 0xda) : '\x1b[48;5;252m',
|
|
330
|
+
scrollThumbHoverFg: TRUECOLOR ? rgb(0xd2, 0xd6, 0xda) : '\x1b[38;5;252m',
|
|
331
|
+
scrollThumbActiveBg: TRUECOLOR ? brgb(0xff, 0xff, 0xff) : '\x1b[48;5;231m',
|
|
332
|
+
scrollThumbActiveFg: TRUECOLOR ? rgb(0xff, 0xff, 0xff) : '\x1b[38;5;231m',
|
|
333
|
+
// FOREGROUND aliases kept for the todo/queue resize rule, which draws a `─` line
|
|
334
|
+
// and therefore needs a foreground, not the block's background pair.
|
|
335
|
+
scrollThumbActive: TRUECOLOR ? rgb(0xff, 0xff, 0xff) : '\x1b[38;5;231m',
|
|
336
|
+
scrollThumbHover: TRUECOLOR ? rgb(0xd2, 0xd6, 0xda) : '\x1b[38;5;252m',
|
|
337
|
+
// Legacy foreground forms, still referenced by the gutter-hover path.
|
|
338
|
+
scrollTrack: '\x1b[90m',
|
|
339
|
+
scrollThumb: TRUECOLOR ? rgb(0, 184, 219) : '\x1b[38;5;37m',
|
|
340
|
+
// Hover highlight for clickable rows (menu items, picker options, form
|
|
341
|
+
// fields, composer rows). An explicit bright foreground + BOLD rather than a
|
|
342
|
+
// bare BOLD: BOLD only brightens the 16-colour palette (it does nothing to a
|
|
343
|
+
// true-color row), which is why hover used to be invisible on most rows.
|
|
344
|
+
// tintRange() re-applies this so the row's own SGR codes cannot cancel it.
|
|
345
|
+
hover: '\x1b[1m' + rgb(190, 245, 255),
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export function style(text, ...codes) {
|
|
349
|
+
return codes.join('') + text + '\x1b[0m';
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Linearly interpolate between two RGB triples and return an ANSI colour string.
|
|
353
|
+
// Used for the pulsing Working indicator (orange pulses to a brighter/darker
|
|
354
|
+
// shade over a 2s cycle).
|
|
355
|
+
export function lerpColor(r1, g1, b1, r2, g2, b2, t) {
|
|
356
|
+
const ti = Math.max(0, Math.min(1, t));
|
|
357
|
+
const r = Math.round(r1 + (r2 - r1) * ti);
|
|
358
|
+
const g = Math.round(g1 + (g2 - g1) * ti);
|
|
359
|
+
const b = Math.round(b1 + (b2 - b1) * ti);
|
|
360
|
+
return rgb(r, g, b);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Which concrete theme `auto` resolves to right now. `setTheme` keeps it so a repaint or a
|
|
364
|
+
// `/theme auto` after a terminal probe lands on the same answer.
|
|
365
|
+
let autoIsLight = false;
|
|
366
|
+
|
|
367
|
+
// The theme `setTheme` last applied, resolved (so `auto` reports the concrete name it
|
|
368
|
+
// became). Read by the render cache: a cached row holds finished escapes, so a palette
|
|
369
|
+
// change has to invalidate them or the old colours survive the switch.
|
|
370
|
+
let appliedTheme = '';
|
|
371
|
+
|
|
372
|
+
/** The concrete theme in force, or `''` before the first `setTheme`. */
|
|
373
|
+
export function currentTheme() { return appliedTheme; }
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Tell `setTheme` whether the terminal has a light background.
|
|
377
|
+
*
|
|
378
|
+
* The probe lives in term-caps.js and this module is a leaf that imports nothing, so the
|
|
379
|
+
* answer has to be handed in. Called once after the probe and again if the terminal is
|
|
380
|
+
* resized on a different display.
|
|
381
|
+
*/
|
|
382
|
+
export function setLightBackground(light) {
|
|
383
|
+
autoIsLight = !!light;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Apply a named theme IN PLACE. `C` is a module-level object and ESM imports are
|
|
387
|
+
// live bindings, so mutating its properties here changes the colours everywhere
|
|
388
|
+
// without re-importing. Returns true when the name was recognised.
|
|
389
|
+
//
|
|
390
|
+
// `auto` is a CHOICE, not a palette: it resolves to `light` on a light terminal and to
|
|
391
|
+
// `dark` otherwise, and then applies that theme's colours. It used to be a fixed table —
|
|
392
|
+
// a dark background with brand-cyan text — which is not what "auto" means and not what its
|
|
393
|
+
// own label claimed ("on the terminal's own palette"). The user asking for auto is asking
|
|
394
|
+
// not to have to think about it.
|
|
395
|
+
export function setTheme(name) {
|
|
396
|
+
const resolved = name === 'auto' ? (autoIsLight ? 'light' : 'dark') : name;
|
|
397
|
+
const t = THEMES[resolved];
|
|
398
|
+
if (!t) return false;
|
|
399
|
+
appliedTheme = resolved;
|
|
400
|
+
|
|
401
|
+
// A light page inverts several surface decisions, so everything below needs this. Declared at the top because
|
|
402
|
+
// the scrollbar and the context bar — set before the diff section — use it too.
|
|
403
|
+
const isLight = t.bg && t.bg[0] > 128;
|
|
404
|
+
// Mix `a` towards `b`: k = 1 is all `a`, k = 0 is all `b`.
|
|
405
|
+
const mix = (a, b, k) => a.map((v, i) => Math.round(v * k + b[i] * (1 - k)));
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
// Update foreground colors
|
|
410
|
+
C.teal = rgb(...t.teal);
|
|
411
|
+
C.fg = rgb(...t.fg);
|
|
412
|
+
C.cyan = rgb(...t.cyan);
|
|
413
|
+
C.blue = rgb(...t.blue);
|
|
414
|
+
C.border = rgb(...t.border);
|
|
415
|
+
// Update background colors
|
|
416
|
+
C.bg = brgb(...t.bg);
|
|
417
|
+
C.bgTeal = brgb(...t.teal);
|
|
418
|
+
// The panel surface is NEUTRAL GREY and comes from the theme's own `surface` triple,
|
|
419
|
+
// NOT from `bg`. It used to be set to `t.bg` (a dark teal), which made every popup
|
|
420
|
+
// carry a blue cast; a raised surface must be neutral, with only the accents following
|
|
421
|
+
// the brand hue. A light theme gets a light grey so the panel still reads as raised.
|
|
422
|
+
if (t.surface) C.bgPanel = brgb(...t.surface);
|
|
423
|
+
C.selBg = brgb(...t.selBg);
|
|
424
|
+
|
|
425
|
+
// Scrollbar colours. The thumb is a BLOCK, so its colour goes on BOTH the
|
|
426
|
+
// foreground and the background (a half-cell `▀`/`▄` shows the foreground, a full
|
|
427
|
+
// `█` shows the background — they must match). Hover / drag are brighter shades
|
|
428
|
+
// of the same hue, applied to the same pair, so the whole thumb changes together.
|
|
429
|
+
const active = [
|
|
430
|
+
Math.min(255, Math.round(t.teal[0] * 0.6 + 255 * 0.4)),
|
|
431
|
+
Math.min(255, Math.round(t.teal[1] * 0.6 + 255 * 0.4)),
|
|
432
|
+
Math.min(255, Math.round(t.teal[2] * 0.6 + 255 * 0.4)),
|
|
433
|
+
];
|
|
434
|
+
const hover = t.hover || [190, 245, 255];
|
|
435
|
+
// The rail: the page, one step darker, so it reads as part of the surface rather than a strip of grey
|
|
436
|
+
// from another interface. Was a fixed `#252527` in every theme.
|
|
437
|
+
const track = mix(t.bg, [0, 0, 0], isLight ? 0.93 : 0.86);
|
|
438
|
+
C.scrollTrackFg = rgb(...track);
|
|
439
|
+
C.scrollTrackBg = brgb(...track);
|
|
440
|
+
C.scrollThumbFg = rgb(...t.teal);
|
|
441
|
+
C.scrollThumbBg = brgb(...t.teal);
|
|
442
|
+
C.scrollThumbHoverFg = rgb(...hover);
|
|
443
|
+
C.scrollThumbHoverBg = brgb(...hover);
|
|
444
|
+
C.scrollThumbActiveFg = rgb(...active);
|
|
445
|
+
C.scrollThumbActiveBg = brgb(...active);
|
|
446
|
+
// Foreground aliases for the todo/queue resize rule.
|
|
447
|
+
C.scrollTrack = '\x1b[90m';
|
|
448
|
+
C.scrollThumb = rgb(...t.teal);
|
|
449
|
+
C.scrollThumbHover = rgb(...hover);
|
|
450
|
+
C.scrollThumbActive = rgb(...active);
|
|
451
|
+
|
|
452
|
+
// Hover stays visible on this theme's background (bright on dark, dark on light).
|
|
453
|
+
C.hover = '\x1b[1m' + rgb(...(t.hover || [190, 245, 255]));
|
|
454
|
+
|
|
455
|
+
// Semantic colors — swap to deep versions on light backgrounds.
|
|
456
|
+
if (t.white) C.white = rgb(...t.white);
|
|
457
|
+
if (t.gray) C.gray = rgb(...t.gray);
|
|
458
|
+
if (t.red) C.red = rgb(...t.red);
|
|
459
|
+
if (t.green) C.green = rgb(...t.green);
|
|
460
|
+
if (t.yellow) C.yellow = rgb(...t.yellow);
|
|
461
|
+
if (t.orange) C.orange = rgb(...t.orange);
|
|
462
|
+
// The git branch colour is derived per theme: the pale yellow that reads well
|
|
463
|
+
// on the dark background is nearly invisible on white, so on a light theme it
|
|
464
|
+
// is darkened (keeping the same hue) instead of being left as-is.
|
|
465
|
+
if (t.bg && t.bg[0] > 128) {
|
|
466
|
+
C.branch = rgb(146, 106, 0); // dark amber for light backgrounds
|
|
467
|
+
} else {
|
|
468
|
+
C.branch = TRUECOLOR ? rgb(255, 219, 110) : '\x1b[38;5;222m';
|
|
469
|
+
}
|
|
470
|
+
// DIFF TINTS, mixed from this theme's own green/red towards its background.
|
|
471
|
+
//
|
|
472
|
+
// A line wash is a WEAK mix and a word wash a STRONGER one of the same pair: weak enough that ordinary text on it
|
|
473
|
+
// still reads as text, strong enough that the block is visible without reading it. Mixing towards `t.bg` rather
|
|
474
|
+
// than towards black is what makes a light theme work — a dark red wash on white is a black bar with letters in
|
|
475
|
+
// it, while a pale red is a highlighter mark.
|
|
476
|
+
const green = t.green || [120, 200, 120];
|
|
477
|
+
const red = t.red || [230, 80, 80];
|
|
478
|
+
// ABOUT HALF. Lower mixes disappear into a dark page — the wash has to be obvious without being read, and at
|
|
479
|
+
// 16% an added block looked like ordinary text with a faint tint. Light backgrounds need slightly more still,
|
|
480
|
+
// because the same distance in RGB is a smaller difference next to white.
|
|
481
|
+
const line = isLight ? 0.52 : 0.46;
|
|
482
|
+
const word = isLight ? 0.68 : 0.62;
|
|
483
|
+
C.diffAddBg = brgb(...mix(green, t.bg, line));
|
|
484
|
+
C.diffAddWordBg = brgb(...mix(green, t.bg, word));
|
|
485
|
+
C.diffDelBg = brgb(...mix(red, t.bg, line));
|
|
486
|
+
C.diffDelWordBg = brgb(...mix(red, t.bg, word));
|
|
487
|
+
// The sign and the text of a changed line are the same hue as its wash, pulled towards the theme's own foreground
|
|
488
|
+
// so they read ON that wash — not the theme's plain green/red, which is tuned for the page background.
|
|
489
|
+
C.diffAddFg = rgb(...mix(green, t.fg, 0.55));
|
|
490
|
+
C.diffDelFg = rgb(...mix(red, t.fg, 0.55));
|
|
491
|
+
|
|
492
|
+
// THE CODE-SURFACE BACKGROUND, one step off the page. Read rows, Write previews and diff CONTEXT lines sit on
|
|
493
|
+
// it; diff `+`/`-` rows keep their green/red wash on top.
|
|
494
|
+
//
|
|
495
|
+
// The step is a VISIBLE DISTANCE, not a ratio. 6% of a near-black page doubles its brightness, while 6% of a
|
|
496
|
+
// white page is 16 levels out of 255 and reads as no change at all. A light page also has no brighter side to
|
|
497
|
+
// step toward, so its steps stay near white — 250 page, 241 code, 231 terminal — where a larger step turned the
|
|
498
|
+
// whole screen grey.
|
|
499
|
+
const codeStep = isLight ? 0.96 : 0.94;
|
|
500
|
+
C.codeBg = brgb(...mix(t.bg, t.fg, codeStep));
|
|
501
|
+
|
|
502
|
+
// THE CONTEXT BAR FOLLOWS THE THEME. These six were fixed constants in every palette, so a dracula or gruvbox
|
|
503
|
+
// session drew the same navy-to-blue bar as the default dark one — and its "free" segment was a neutral grey
|
|
504
|
+
// that matched neither the bar nor the page. The bar is a row of FILLS read at a glance, so each step is a mix
|
|
505
|
+
// of the theme accent into its own page: the free part is the plain page, and the used parts climb towards the
|
|
506
|
+
// accent.
|
|
507
|
+
const ctxBase = mix(t.bg, t.fg, codeStep); // = codeBg, the brightest surface
|
|
508
|
+
const ctxMix = (k) => brgb(...mix(ctxBase, t.teal, k));
|
|
509
|
+
C.ctxSystem = ctxMix(0.68);
|
|
510
|
+
C.ctxPrompt = ctxMix(0.56);
|
|
511
|
+
C.ctxAssistant = ctxMix(0.42);
|
|
512
|
+
C.ctxThinking = ctxMix(0.26);
|
|
513
|
+
C.ctxTools = ctxMix(0.10);
|
|
514
|
+
// The free segment is the page itself: "nothing here yet" should look like the surface it sits on, and a separate
|
|
515
|
+
// grey made the empty half of the bar look like a second widget.
|
|
516
|
+
C.ctxFree = brgb(...ctxBase);
|
|
517
|
+
// THE TERMINAL-SURFACE BACKGROUND: the same small step on the OTHER side of the page, so the ordering holds on
|
|
518
|
+
// both kinds of theme — page < terminal < code on a dark one, terminal < code < page on a light one. Bash output
|
|
519
|
+
// and the shell-mode echo sit on it: a command reads as "a terminal ran this" without becoming a black band,
|
|
520
|
+
// which is what a deeper well looked like — a hole in the screen rather than a region of it.
|
|
521
|
+
//
|
|
522
|
+
// Towards BLACK on a dark theme and towards the foreground on a light one: mixing a dark page further towards its
|
|
523
|
+
// own foreground would make it lighter, which is `codeBg`'s job, not this one.
|
|
524
|
+
C.termBg = brgb(...mix(t.bg, [0, 0, 0], isLight ? 0.925 : 0.78));
|
|
525
|
+
// THE COMPOSER SURFACE: NEUTRAL, and derived from the page. Neutral because a hue here reads as "more page"
|
|
526
|
+
// rather than as an input field; derived because a fixed grey meant every theme drew the default dark theme's
|
|
527
|
+
// input box. The three channels are set to the page's own LUMINANCE plus a step, so the field is grey while
|
|
528
|
+
// still belonging to the palette it sits in. A theme may override it with its own `composer` triple.
|
|
529
|
+
const pageLum = (t.bg[0] + t.bg[1] + t.bg[2]) / 3;
|
|
530
|
+
const neutral = Math.max(0, Math.min(255, Math.round(pageLum + (isLight ? -14 : 14))));
|
|
531
|
+
C.composerBg = brgb(...(t.composer || [neutral, neutral, neutral + (isLight ? 0 : 2)]));
|
|
532
|
+
|
|
533
|
+
// A comment: the palette's foreground, pulled most of the way towards its background so it reads as quiet. A dark
|
|
534
|
+
// page can afford a looser mix; a light one cannot — solar's foreground is already a muted blue-grey, and at the
|
|
535
|
+
// dark theme's ratio its comments came within 8 of the removal wash.
|
|
536
|
+
C.comment = rgb(...mix(t.fg, t.bg, isLight ? 0.86 : 0.72));
|
|
537
|
+
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export function clearScreen() {
|
|
542
|
+
return '\x1b[3J\x1b[H\x1b[2J';
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// Clear screen and set background color based on current theme
|
|
546
|
+
export function clearAndSetBg() {
|
|
547
|
+
// Reset all attributes first
|
|
548
|
+
const reset = '\x1b[0m';
|
|
549
|
+
// Clear screen
|
|
550
|
+
const clear = '\x1b[3J\x1b[H\x1b[2J';
|
|
551
|
+
// Set background color using current C.bg value
|
|
552
|
+
const bg = C.bg || '\x1b[48;2;0;18;26m'; // Default dark background
|
|
553
|
+
return reset + clear + bg;
|
|
554
|
+
}
|
|
555
|
+
export function eraseLine() {
|
|
556
|
+
return '\x1b[2K';
|
|
557
|
+
}
|
|
558
|
+
export function eraseScreen() {
|
|
559
|
+
return '\x1b[2J';
|
|
560
|
+
}
|
|
561
|
+
export function moveTo(r, c) {
|
|
562
|
+
return `\x1b[${r + 1};${c + 1}H`;
|
|
563
|
+
}
|
|
564
|
+
export function cursorUp(n) { return `\x1b[${n}A`; }
|
|
565
|
+
export function cursorDown(n) { return `\x1b[${n}B`; }
|
|
566
|
+
export function cursorLeft(n) { return `\x1b[${n}D`; }
|
|
567
|
+
export function cursorForward(n) { return `\x1b[${n}C`; }
|
|
568
|
+
export function hideCursor() { return '\x1b[?25l'; }
|
|
569
|
+
export function showCursor() { return '\x1b[?25h'; }
|
|
570
|
+
// Cursor shape: terminals accept DECSCUSR — 2 = block, 4 = underline, 6 = bar(I-beam);
|
|
571
|
+
// 1/3/5 = blinking variants. Force a solid block cursor so positioning is always exact
|
|
572
|
+
// and unaffected by I-beam alignment.
|
|
573
|
+
export function blockCursor() { return '\x1b[2 q'; }
|
|
574
|
+
export function underlineCursor() { return '\x1b[4 q'; }
|
|
575
|
+
export function barCursor() { return '\x1b[6 q'; }
|
|
576
|
+
export function alternateScreen(on) { return on ? '\x1b[?1049h' : '\x1b[?1049l'; }
|
|
577
|
+
export function setScrollRegion(top, bottom) {
|
|
578
|
+
if (process.platform === 'win32') return ''; // win TTY scroll regions are unreliable
|
|
579
|
+
return `\x1b[${top + 1};${bottom + 1}r`;
|
|
580
|
+
}
|
|
581
|
+
export function resetScrollRegion() {
|
|
582
|
+
return '\x1b[r';
|
|
583
|
+
}
|
|
584
|
+
export function setBracketed(on) {
|
|
585
|
+
return `\x1b[?2004h${on ? '' : ''}`; // placeholder; real impl toggles bracketed paste
|
|
586
|
+
}
|