Repository navigation
Expand file tree
/
Copy paththeme.ts
More file actions
446 lines (429 loc) · 16.2 KB
/
Copy paththeme.ts
File metadata and controls
446 lines (429 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
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
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
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
441
442
443
444
445
446
/**
* dsh-tui color themes — Gentle Mist Blue (雾蓝) family.
*
* Two truecolor palettes share one identity: mist blues carry brand, focus,
* and interaction; body text stays neutral. `light` is the strict Gentle
* Mist Blue card (warm off-white background #F6F3ED, ink text #343945) for
* light terminals; `dark` is its dark-terminal adaptation (warm off-white
* text, accent-soft blues). `dark-ansi` is the 16-color fallback for
* terminals without truecolor. The active palette is chosen at startup by
* querying the terminal background (OSC 11) — see ThemeProvider.
*
* `auto` is a pseudo-theme, not a palette: it resolves to `light` or `dark`
* from the terminal background detected via OSC 11 (which tracks the system
* theme in terminals that follow it). ThemeProvider re-runs detection every
* time `auto` is selected and pushes the result through setAutoThemeBase(),
* so getTheme('auto') always serves the currently detected palette.
*/
export type Theme = {
autoAccept: string
bashBorder: string
claude: string
claudeShimmer: string
claudeBlue_FOR_SYSTEM_SPINNER: string
claudeBlueShimmer_FOR_SYSTEM_SPINNER: string
permission: string
permissionShimmer: string
planMode: string
ide: string
promptBorder: string
promptBorderShimmer: string
text: string
inverseText: string
inactive: string
inactiveShimmer: string
subtle: string
suggestion: string
remember: string
background: string
// Semantic colors
success: string
error: string
warning: string
merged: string
warningShimmer: string
// Diff colors
diffAdded: string
diffRemoved: string
diffAddedDimmed: string
diffRemovedDimmed: string
diffAddedWord: string
diffRemovedWord: string
// Agent colors
red_FOR_SUBAGENTS_ONLY: string
blue_FOR_SUBAGENTS_ONLY: string
green_FOR_SUBAGENTS_ONLY: string
yellow_FOR_SUBAGENTS_ONLY: string
purple_FOR_SUBAGENTS_ONLY: string
orange_FOR_SUBAGENTS_ONLY: string
pink_FOR_SUBAGENTS_ONLY: string
cyan_FOR_SUBAGENTS_ONLY: string
// Grove colors
professionalBlue: string
// Chrome colors
chromeYellow: string
// TUI V2 colors
clawd_body: string
clawd_background: string
userMessageBackground: string
userMessageBackgroundHover: string
messageActionsBackground: string
selectionBg: string
bashMessageBackgroundColor: string
memoryBackgroundColor: string
rate_limit_fill: string
rate_limit_empty: string
fastMode: string
fastModeShimmer: string
briefLabelYou: string
briefLabelClaude: string
rainbow_red: string
rainbow_orange: string
rainbow_yellow: string
rainbow_green: string
rainbow_blue: string
rainbow_indigo: string
rainbow_violet: string
rainbow_red_shimmer: string
rainbow_orange_shimmer: string
rainbow_yellow_shimmer: string
rainbow_green_shimmer: string
rainbow_blue_shimmer: string
rainbow_indigo_shimmer: string
rainbow_violet_shimmer: string
}
/** The built-in theme names, in display order. */
export const THEME_NAMES = ['dark', 'dark-ansi', 'light'] as const
/**
* The `auto` pseudo-theme: not a palette, but a standing request to follow
* the terminal background (OSC 11, which tracks the system theme in
* terminals that follow it). Selectable everywhere a theme name is
* (/theme, DSH_TUI_THEME, ~/.dsh-tui/theme.json); getTheme() resolves it to
* the last detected `light`/`dark` palette via the auto base below.
*/
export const AUTO_THEME_NAME = 'auto'
/**
* The palette `auto` currently resolves to, mirrored module-level so
* getTheme('auto') works for non-React rendering without a context.
* ThemeProvider sets this on every detection (startup and runtime switch);
* defaults to `dark` until the first detection settles (the pre-detection
* status quo, biased dark for readability).
*/
let autoBase: 'light' | 'dark' = 'dark'
/**
* Record the palette `auto` should resolve to. Called by ThemeProvider
* after each terminal-background detection while `auto` is active.
* @param name - The detected base palette.
*/
export function setAutoThemeBase(name: 'light' | 'dark'): void {
autoBase = name
}
/** The palette `auto` currently resolves to (`light` or `dark`). */
export function getAutoThemeBase(): 'light' | 'dark' {
return autoBase
}
/**
* Any theme name: a built-in palette (`light`/`dark`/`dark-ansi`) or a user
* theme from ~/.dsh-tui/themes/<name>.json. Always resolvable to a concrete
* color palette via getTheme() (unknown names fall back to `dark`).
*/
export type ThemeName = string
const rgb = (hex: string): string => {
const n = parseInt(hex.slice(1), 16)
return `rgb(${(n >> 16) & 255},${(n >> 8) & 255},${n & 255})`
}
/**
* Gentle Mist Blue dark adaptation. The blues come straight from the card
* (#27478C–#ABC2EC); neutrals are warm (derived from #F6F3ED/#343945) so
* the palette reads calm rather than cyber-hard on a dark terminal.
*/
const darkTheme: Theme = {
autoAccept: rgb('#B3A0D4'), // Soft violet
bashBorder: rgb('#D194AE'), // Mist rose
claude: rgb('#7DA1DE'), // Accent Soft — mist brand blue
claudeShimmer: rgb('#ABC2EC'), // Border Blue for shimmer effect
claudeBlue_FOR_SYSTEM_SPINNER: rgb('#7DA1DE'),
claudeBlueShimmer_FOR_SYSTEM_SPINNER: rgb('#ABC2EC'),
permission: rgb('#ABC2EC'), // Border Blue — pane/dialog accent
permissionShimmer: rgb('#C9D7F2'),
planMode: rgb('#7FAE99'), // Muted sage green
ide: rgb('#5E88CC'), // Accent Blue
promptBorder: rgb('#55606F'), // Muted blue-gray
promptBorderShimmer: rgb('#7DA1DE'),
text: rgb('#E8E6E0'), // Warm off-white (from #F6F3ED)
inverseText: rgb('#22262E'), // Deep warm charcoal (from #343945)
inactive: rgb('#8D95A6'), // Mist gray-blue — feeds dimColor
inactiveShimmer: rgb('#AAB2C2'),
subtle: rgb('#5E6673'), // Dimmer blue-gray
suggestion: rgb('#ABC2EC'), // Border Blue — focus/selection
remember: rgb('#ABC2EC'),
background: rgb('#5E88CC'), // Accent Blue — badge fill
success: rgb('#82B89D'), // Mist green (from #4E9675)
error: rgb('#DA8A93'), // Soft rose
warning: rgb('#D8B270'), // Soft amber
merged: rgb('#B3A0D4'), // Soft violet (matches autoAccept)
warningShimmer: rgb('#E4C78E'),
diffAdded: rgb('#27392C'),
diffRemoved: rgb('#3E2A2C'),
diffAddedDimmed: rgb('#2B352C'),
diffRemovedDimmed: rgb('#362B2C'),
diffAddedWord: rgb('#57956B'),
diffRemovedWord: rgb('#B26671'),
red_FOR_SUBAGENTS_ONLY: rgb('#D4685E'),
blue_FOR_SUBAGENTS_ONLY: rgb('#7496D6'),
green_FOR_SUBAGENTS_ONLY: rgb('#66B285'),
yellow_FOR_SUBAGENTS_ONLY: rgb('#D1A94E'),
purple_FOR_SUBAGENTS_ONLY: rgb('#AC8CD2'),
orange_FOR_SUBAGENTS_ONLY: rgb('#DB8C50'),
pink_FOR_SUBAGENTS_ONLY: rgb('#D384A8'),
cyan_FOR_SUBAGENTS_ONLY: rgb('#6FAFB4'),
professionalBlue: rgb('#7DA1DE'),
chromeYellow: rgb('#D8B270'),
clawd_body: rgb('#D98A63'), // Warm mascot orange
clawd_background: rgb('#000000'),
userMessageBackground: rgb('#292D36'),
userMessageBackgroundHover: rgb('#343945'),
messageActionsBackground: rgb('#2E333D'),
selectionBg: rgb('#3B4A66'), // Mist-blue tint on dark
bashMessageBackgroundColor: rgb('#2C3038'),
memoryBackgroundColor: rgb('#30353D'),
rate_limit_fill: rgb('#7DA1DE'),
rate_limit_empty: rgb('#3C414B'),
fastMode: rgb('#E09A58'),
fastModeShimmer: rgb('#EAB478'),
briefLabelYou: rgb('#ABC2EC'),
briefLabelClaude: rgb('#7DA1DE'),
rainbow_red: rgb('#D98F8A'),
rainbow_orange: rgb('#D9A97E'),
rainbow_yellow: rgb('#D6BE78'),
rainbow_green: rgb('#93BBA0'),
rainbow_blue: rgb('#8FA9D6'),
rainbow_indigo: rgb('#A89CD4'),
rainbow_violet: rgb('#C29CC0'),
rainbow_red_shimmer: rgb('#E4AAAA'),
rainbow_orange_shimmer: rgb('#E4C09C'),
rainbow_yellow_shimmer: rgb('#E2D29C'),
rainbow_green_shimmer: rgb('#B0CEBA'),
rainbow_blue_shimmer: rgb('#AFBFE2'),
rainbow_indigo_shimmer: rgb('#BFB4DE'),
rainbow_violet_shimmer: rgb('#D1B4D1'),
}
/**
* Gentle Mist Blue light theme — the strict original card. Blue carries
* brand, focus, interaction, and highlight only; body text stays ink gray
* on the warm off-white family (background #F6F3ED, surface #EEE5D2,
* surface-alt #E4D9E5).
*/
const lightTheme: Theme = {
autoAccept: rgb('#9B86B8'), // Muted violet (from surface-alt pink-mist)
bashBorder: rgb('#C07A93'), // Muted rose (from surface-alt pink-mist)
claude: rgb('#3F6CC4'), // Primary Blue — brand
claudeShimmer: rgb('#5E88CC'), // Accent Blue for shimmer effect
claudeBlue_FOR_SYSTEM_SPINNER: rgb('#3F6CC4'),
claudeBlueShimmer_FOR_SYSTEM_SPINNER: rgb('#5E88CC'),
permission: rgb('#3F6CC4'), // Primary Blue — pane/dialog accent
permissionShimmer: rgb('#5E88CC'),
planMode: rgb('#4E9675'), // Sage green
ide: rgb('#5E88CC'), // Accent Blue
promptBorder: rgb('#ABC2EC'), // Border Blue
promptBorderShimmer: rgb('#7DA1DE'), // Accent Soft
text: rgb('#343945'), // Ink
inverseText: rgb('#F6F3ED'), // Warm off-white (on colored fills)
inactive: rgb('#8991A0'), // Text-muted — feeds dimColor
inactiveShimmer: rgb('#626978'), // Text-secondary
subtle: rgb('#A6ADBA'), // Lower contrast than inactive
suggestion: rgb('#3F6CC4'), // Primary Blue — focus/selection
remember: rgb('#27478C'), // Deep Outline — picker titles
background: rgb('#3F6CC4'), // Primary Blue — badge fill
success: rgb('#4E9675'),
error: rgb('#C65D6B'), // Muted rose-red
warning: rgb('#C08A3E'), // Muted amber
merged: rgb('#9B86B8'), // Muted violet (matches autoAccept)
warningShimmer: rgb('#D0A050'),
diffAdded: rgb('#DCEBDD'),
diffRemoved: rgb('#F2DEDE'),
diffAddedDimmed: rgb('#E4EFE5'),
diffRemovedDimmed: rgb('#F5E6E4'),
diffAddedWord: rgb('#A9D3B4'),
diffRemovedWord: rgb('#E5B3AE'),
red_FOR_SUBAGENTS_ONLY: rgb('#BE5A52'),
blue_FOR_SUBAGENTS_ONLY: rgb('#3F6CC4'),
green_FOR_SUBAGENTS_ONLY: rgb('#4E9675'),
yellow_FOR_SUBAGENTS_ONLY: rgb('#B98A34'),
purple_FOR_SUBAGENTS_ONLY: rgb('#9678B4'),
orange_FOR_SUBAGENTS_ONLY: rgb('#C97F4A'),
pink_FOR_SUBAGENTS_ONLY: rgb('#C06E97'),
cyan_FOR_SUBAGENTS_ONLY: rgb('#5698A0'),
professionalBlue: rgb('#5E88CC'),
chromeYellow: rgb('#C99A3F'),
clawd_body: rgb('#D98A63'), // Warm mascot orange
clawd_background: rgb('#F6F3ED'),
userMessageBackground: rgb('#EEE5D2'), // Surface
userMessageBackgroundHover: rgb('#E4D9E5'), // Surface Alt
messageActionsBackground: rgb('#E4D9E5'),
selectionBg: rgb('#D5DEF2'), // Mist-blue tint on warm white
bashMessageBackgroundColor: rgb('#EAE1D3'),
memoryBackgroundColor: rgb('#E4D9E5'),
rate_limit_fill: rgb('#7DA1DE'),
rate_limit_empty: rgb('#DDD5C7'),
fastMode: rgb('#D98E4A'),
fastModeShimmer: rgb('#E2A465'),
briefLabelYou: rgb('#5E88CC'),
briefLabelClaude: rgb('#3F6CC4'),
rainbow_red: rgb('#D98888'),
rainbow_orange: rgb('#D9A276'),
rainbow_yellow: rgb('#CEB264'),
rainbow_green: rgb('#8AB392'),
rainbow_blue: rgb('#87A3D3'),
rainbow_indigo: rgb('#9C92C8'),
rainbow_violet: rgb('#BB92B8'),
rainbow_red_shimmer: rgb('#E4A6A6'),
rainbow_orange_shimmer: rgb('#E4BB96'),
rainbow_yellow_shimmer: rgb('#DEC988'),
rainbow_green_shimmer: rgb('#A9C8AF'),
rainbow_blue_shimmer: rgb('#A9BCE0'),
rainbow_indigo_shimmer: rgb('#B7AFD8'),
rainbow_violet_shimmer: rgb('#CFB0CC'),
}
/**
* Dark ANSI theme using only the 16 standard ANSI colors, for terminals
* without true color support (verbatim from Claude Code).
*
* User themes (JSON files in ~/.dsh-tui/themes/) overlay one of these three
* bases — see customTheme.ts. `getTheme` resolves them through a resolver
* registered by ThemeProvider.
*/
const darkAnsiTheme: Theme = {
autoAccept: 'ansi:magentaBright',
bashBorder: 'ansi:magentaBright',
claude: 'ansi:blueBright',
claudeShimmer: 'ansi:blueBright',
claudeBlue_FOR_SYSTEM_SPINNER: 'ansi:blueBright',
claudeBlueShimmer_FOR_SYSTEM_SPINNER: 'ansi:blueBright',
permission: 'ansi:blueBright',
permissionShimmer: 'ansi:blueBright',
planMode: 'ansi:cyanBright',
ide: 'ansi:blue',
promptBorder: 'ansi:white',
promptBorderShimmer: 'ansi:whiteBright',
text: 'ansi:whiteBright',
inverseText: 'ansi:black',
inactive: 'ansi:white',
inactiveShimmer: 'ansi:whiteBright',
subtle: 'ansi:white',
suggestion: 'ansi:blueBright',
remember: 'ansi:blueBright',
background: 'ansi:cyanBright',
success: 'ansi:greenBright',
error: 'ansi:redBright',
warning: 'ansi:yellowBright',
merged: 'ansi:magentaBright',
warningShimmer: 'ansi:yellowBright',
diffAdded: 'ansi:green',
diffRemoved: 'ansi:red',
diffAddedDimmed: 'ansi:green',
diffRemovedDimmed: 'ansi:red',
diffAddedWord: 'ansi:greenBright',
diffRemovedWord: 'ansi:redBright',
red_FOR_SUBAGENTS_ONLY: 'ansi:redBright',
blue_FOR_SUBAGENTS_ONLY: 'ansi:blueBright',
green_FOR_SUBAGENTS_ONLY: 'ansi:greenBright',
yellow_FOR_SUBAGENTS_ONLY: 'ansi:yellowBright',
purple_FOR_SUBAGENTS_ONLY: 'ansi:magentaBright',
orange_FOR_SUBAGENTS_ONLY: 'ansi:redBright',
pink_FOR_SUBAGENTS_ONLY: 'ansi:magentaBright',
cyan_FOR_SUBAGENTS_ONLY: 'ansi:cyanBright',
professionalBlue: 'ansi:blueBright',
chromeYellow: 'ansi:yellowBright',
clawd_body: 'ansi:redBright',
clawd_background: 'ansi:black',
userMessageBackground: 'ansi:blackBright',
userMessageBackgroundHover: 'ansi:white',
messageActionsBackground: 'ansi:blackBright',
selectionBg: 'ansi:blue',
bashMessageBackgroundColor: 'ansi:black',
memoryBackgroundColor: 'ansi:blackBright',
rate_limit_fill: 'ansi:yellow',
rate_limit_empty: 'ansi:white',
fastMode: 'ansi:redBright',
fastModeShimmer: 'ansi:redBright',
briefLabelYou: 'ansi:blueBright',
briefLabelClaude: 'ansi:blueBright',
rainbow_red: 'ansi:red',
rainbow_orange: 'ansi:redBright',
rainbow_yellow: 'ansi:yellow',
rainbow_green: 'ansi:green',
rainbow_blue: 'ansi:cyan',
rainbow_indigo: 'ansi:blue',
rainbow_violet: 'ansi:magenta',
rainbow_red_shimmer: 'ansi:redBright',
rainbow_orange_shimmer: 'ansi:yellow',
rainbow_yellow_shimmer: 'ansi:yellowBright',
rainbow_green_shimmer: 'ansi:greenBright',
rainbow_blue_shimmer: 'ansi:cyanBright',
rainbow_indigo_shimmer: 'ansi:blueBright',
rainbow_violet_shimmer: 'ansi:magentaBright',
}
/**
* Resolve a theme name to its concrete color palette.
* @param themeName - The theme to resolve (built-in, `auto`, or user theme
* name).
* @returns The matching palette; `auto` resolves to the detected base
* (light/dark), unknown names fall back to `dark`.
*/
export function getTheme(themeName: ThemeName): Theme {
switch (themeName) {
case 'light':
return lightTheme
// `dark` is an explicit case (not the default): built-in bases must
// resolve without touching the custom-theme resolver — parseCustomTheme
// calls getTheme(base) while the resolver may still be indexing, and a
// resolver round-trip there re-enters theme-file parsing recursively.
case 'dark':
return darkTheme
case 'dark-ansi':
return darkAnsiTheme
case AUTO_THEME_NAME:
return autoBase === 'light' ? lightTheme : darkTheme
default:
return customThemeResolver?.(themeName) ?? darkTheme
}
}
/**
* Resolver that maps a user theme name to a fully built palette (see
* customTheme.ts). Wired by ThemeProvider at startup so non-React rendering
* (markdown inline code) resolves user themes through getActiveTheme().
*/
let customThemeResolver: ((name: string) => Theme | undefined) | undefined
/**
* Register the custom-theme resolver. Called once by ThemeProvider; the
* resolver must return `undefined` for names it does not know so getTheme
* falls back to `dark`.
* @param resolver - Resolves a user theme name to a built palette.
*/
export function registerCustomThemeResolver(
resolver: (name: string) => Theme | undefined,
): void {
customThemeResolver = resolver
}
/**
* The theme chosen at startup, mirrored module-level so non-React rendering
* (markdown inline code in cc/markdown.ts) can resolve palette colors
* without a context. ThemeProvider sets this once detection settles.
*/
let activeThemeName: ThemeName = 'dark'
/**
* Set the module-level active theme; ThemeProvider calls this once
* background detection settles and on every runtime theme switch.
* @param name - The theme to activate.
*/
export function setActiveThemeName(name: ThemeName): void {
activeThemeName = name
}
/**
* Resolve the currently active theme for non-React rendering.
* @returns The palette of the module-level active theme.
*/
export function getActiveTheme(): Theme {
return getTheme(activeThemeName)
}