mux-sesh 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/app.tsx +606 -175
- package/src/components/KeybindHelp.tsx +156 -135
- package/src/config/index.ts +208 -2
- package/src/handlers/keyboard.ts +204 -34
- package/src/settings.ts +425 -0
- package/src/styles/opencode-themes-a.ts +1 -0
- package/src/styles/opencode-themes-b.ts +1 -0
- package/src/styles/theme.tsx +441 -0
- package/src/types/index.ts +65 -0
- package/src/ui/CommandsModal.tsx +145 -0
- package/src/ui/HighlightedText.tsx +6 -3
- package/src/ui/ItemList.tsx +34 -35
- package/src/ui/Modal.tsx +41 -0
- package/src/ui/OpencodeSessionGroup.tsx +26 -28
- package/src/ui/OpencodeStatsPanel.tsx +34 -39
- package/src/ui/RenameModal.tsx +42 -0
- package/src/ui/SearchInput.tsx +3 -1
- package/src/ui/SessionDetailsPanel.tsx +68 -106
- package/src/ui/SessionList.tsx +33 -42
- package/src/ui/SessionStats.tsx +5 -3
- package/src/ui/SettingEditorModal.tsx +49 -0
- package/src/ui/SettingOptionsModal.tsx +77 -0
- package/src/ui/SettingsModal.tsx +96 -0
- package/src/ui/Toast.tsx +8 -9
- package/src/ui/item-icon.ts +13 -12
- package/src/styles/theme.ts +0 -50
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import { createContext, useContext, type ReactNode } from 'react'
|
|
2
|
+
import type {
|
|
3
|
+
DesktopTheme,
|
|
4
|
+
ThemeColorScheme,
|
|
5
|
+
ThemeColors,
|
|
6
|
+
ThemeDefinition,
|
|
7
|
+
ThemeVariant,
|
|
8
|
+
} from '../types'
|
|
9
|
+
import { THEMES_A } from './opencode-themes-a'
|
|
10
|
+
import { THEMES_B } from './opencode-themes-b'
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_THEME_ID = 'rosepine'
|
|
13
|
+
export const DEFAULT_COLOR_SCHEME: ThemeColorScheme = 'system'
|
|
14
|
+
|
|
15
|
+
export const BUILTIN_THEMES: Record<string, DesktopTheme> = {
|
|
16
|
+
...THEMES_A,
|
|
17
|
+
...THEMES_B,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function clamp(value: number): number {
|
|
21
|
+
return Math.max(0, Math.min(255, Math.round(value)))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function normalizeHex(color: string): string {
|
|
25
|
+
const normalized = color.startsWith('#') ? color.slice(1) : color
|
|
26
|
+
|
|
27
|
+
if (normalized.length === 3 || normalized.length === 4) {
|
|
28
|
+
return `#${normalized
|
|
29
|
+
.split('')
|
|
30
|
+
.map(char => `${char}${char}`)
|
|
31
|
+
.join('')}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return color.startsWith('#') ? color : `#${color}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function hexToRgb(hex: string) {
|
|
38
|
+
const normalized = normalizeHex(hex).slice(1)
|
|
39
|
+
const channel = (offset: number) => parseInt(normalized.slice(offset, offset + 2), 16)
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
r: channel(0),
|
|
43
|
+
g: channel(2),
|
|
44
|
+
b: channel(4),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function rgbToHex(r: number, g: number, b: number) {
|
|
49
|
+
return `#${[r, g, b].map(channel => clamp(channel).toString(16).padStart(2, '0')).join('')}`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function luminance(color: string) {
|
|
53
|
+
const { r, g, b } = hexToRgb(color)
|
|
54
|
+
return 0.299 * r + 0.587 * g + 0.114 * b
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function readableText(background: string) {
|
|
58
|
+
return luminance(background) > 150 ? '#171717' : '#f5f5f5'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const EXACT_TUI_THEME_COLORS: Partial<Record<string, Record<'light' | 'dark', ThemeColors>>> = {
|
|
62
|
+
rosepine: {
|
|
63
|
+
dark: {
|
|
64
|
+
background: '#191724',
|
|
65
|
+
surface: '#191724',
|
|
66
|
+
surfaceAlt: '#26233a',
|
|
67
|
+
surfaceModal: '#1f1d2e',
|
|
68
|
+
overlay: '#000000',
|
|
69
|
+
border: '#403d52',
|
|
70
|
+
borderMuted: '#21202e',
|
|
71
|
+
text: '#e0def4',
|
|
72
|
+
textMuted: '#908caa',
|
|
73
|
+
textSubtle: '#6e6a86',
|
|
74
|
+
primary: '#9ccfd8',
|
|
75
|
+
secondary: '#c4a7e7',
|
|
76
|
+
accent: '#ebbcba',
|
|
77
|
+
active: '#31748f',
|
|
78
|
+
inactive: '#6e6a86',
|
|
79
|
+
key: '#f6c177',
|
|
80
|
+
action: '#ebbcba',
|
|
81
|
+
separator: '#403d52',
|
|
82
|
+
program: '#31748f',
|
|
83
|
+
fileTree: '#9ccfd8',
|
|
84
|
+
danger: '#eb6f92',
|
|
85
|
+
dangerSurface: '#3a1f2d',
|
|
86
|
+
selection: '#9ccfd8',
|
|
87
|
+
selectionText: readableText('#9ccfd8'),
|
|
88
|
+
},
|
|
89
|
+
light: {
|
|
90
|
+
background: '#faf4ed',
|
|
91
|
+
surface: '#fffaf3',
|
|
92
|
+
surfaceAlt: '#f2e9e1',
|
|
93
|
+
surfaceModal: '#fffaf3',
|
|
94
|
+
overlay: '#000000',
|
|
95
|
+
border: '#dfdad9',
|
|
96
|
+
borderMuted: '#f4ede8',
|
|
97
|
+
text: '#575279',
|
|
98
|
+
textMuted: '#797593',
|
|
99
|
+
textSubtle: '#9893a5',
|
|
100
|
+
primary: '#31748f',
|
|
101
|
+
secondary: '#907aa9',
|
|
102
|
+
accent: '#d7827e',
|
|
103
|
+
active: '#286983',
|
|
104
|
+
inactive: '#9893a5',
|
|
105
|
+
key: '#ea9d34',
|
|
106
|
+
action: '#d7827e',
|
|
107
|
+
separator: '#dfdad9',
|
|
108
|
+
program: '#286983',
|
|
109
|
+
fileTree: '#31748f',
|
|
110
|
+
danger: '#b4637a',
|
|
111
|
+
dangerSurface: '#fce5e8',
|
|
112
|
+
selection: '#31748f',
|
|
113
|
+
selectionText: readableText('#31748f'),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
opencode: {
|
|
117
|
+
dark: {
|
|
118
|
+
background: '#0a0a0a',
|
|
119
|
+
surface: '#141414',
|
|
120
|
+
surfaceAlt: '#1e1e1e',
|
|
121
|
+
surfaceModal: '#141414',
|
|
122
|
+
overlay: '#000000',
|
|
123
|
+
border: '#484848',
|
|
124
|
+
borderMuted: '#3c3c3c',
|
|
125
|
+
text: '#eeeeee',
|
|
126
|
+
textMuted: '#a0a0a0',
|
|
127
|
+
textSubtle: '#808080',
|
|
128
|
+
primary: '#fab283',
|
|
129
|
+
secondary: '#5c9cf5',
|
|
130
|
+
accent: '#9d7cd8',
|
|
131
|
+
active: '#7fd88f',
|
|
132
|
+
inactive: '#808080',
|
|
133
|
+
key: '#f5a742',
|
|
134
|
+
action: '#56b6c2',
|
|
135
|
+
separator: '#808080',
|
|
136
|
+
program: '#7fd88f',
|
|
137
|
+
fileTree: '#fab283',
|
|
138
|
+
danger: '#e06c75',
|
|
139
|
+
dangerSurface: '#37222c',
|
|
140
|
+
selection: '#fab283',
|
|
141
|
+
selectionText: readableText('#fab283'),
|
|
142
|
+
},
|
|
143
|
+
light: {
|
|
144
|
+
background: '#ffffff',
|
|
145
|
+
surface: '#fafafa',
|
|
146
|
+
surfaceAlt: '#f5f5f5',
|
|
147
|
+
surfaceModal: '#fafafa',
|
|
148
|
+
overlay: '#000000',
|
|
149
|
+
border: '#b8b8b8',
|
|
150
|
+
borderMuted: '#d4d4d4',
|
|
151
|
+
text: '#1a1a1a',
|
|
152
|
+
textMuted: '#8a8a8a',
|
|
153
|
+
textSubtle: '#a0a0a0',
|
|
154
|
+
primary: '#3b7dd8',
|
|
155
|
+
secondary: '#7b5bb6',
|
|
156
|
+
accent: '#d68c27',
|
|
157
|
+
active: '#3d9a57',
|
|
158
|
+
inactive: '#8a8a8a',
|
|
159
|
+
key: '#d68c27',
|
|
160
|
+
action: '#318795',
|
|
161
|
+
separator: '#8a8a8a',
|
|
162
|
+
program: '#3d9a57',
|
|
163
|
+
fileTree: '#3b7dd8',
|
|
164
|
+
danger: '#d1383d',
|
|
165
|
+
dangerSurface: '#f7d8db',
|
|
166
|
+
selection: '#3b7dd8',
|
|
167
|
+
selectionText: readableText('#3b7dd8'),
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
'oc-2': {
|
|
171
|
+
dark: {
|
|
172
|
+
background: '#1f1f1f',
|
|
173
|
+
surface: '#232323',
|
|
174
|
+
surfaceAlt: '#282828',
|
|
175
|
+
surfaceModal: '#232323',
|
|
176
|
+
overlay: '#000000',
|
|
177
|
+
border: '#282828',
|
|
178
|
+
borderMuted: '#232323',
|
|
179
|
+
text: '#ededed',
|
|
180
|
+
textMuted: '#a0a0a0',
|
|
181
|
+
textSubtle: '#707070',
|
|
182
|
+
primary: '#fab283',
|
|
183
|
+
secondary: '#034cff',
|
|
184
|
+
accent: '#edb2f1',
|
|
185
|
+
active: '#12c905',
|
|
186
|
+
inactive: '#707070',
|
|
187
|
+
key: '#fcd53a',
|
|
188
|
+
action: '#edb2f1',
|
|
189
|
+
separator: '#505050',
|
|
190
|
+
program: '#00ceb9',
|
|
191
|
+
fileTree: '#93e9f6',
|
|
192
|
+
danger: '#fc533a',
|
|
193
|
+
dangerSurface: '#1f0603',
|
|
194
|
+
selection: '#fab283',
|
|
195
|
+
selectionText: readableText('#fab283'),
|
|
196
|
+
},
|
|
197
|
+
light: {
|
|
198
|
+
background: '#f8f8f8',
|
|
199
|
+
surface: '#f3f3f3',
|
|
200
|
+
surfaceAlt: '#ededed',
|
|
201
|
+
surfaceModal: '#ffffff',
|
|
202
|
+
overlay: '#000000',
|
|
203
|
+
border: '#dbdbdb',
|
|
204
|
+
borderMuted: '#e8e8e8',
|
|
205
|
+
text: '#171717',
|
|
206
|
+
textMuted: '#6f6f6f',
|
|
207
|
+
textSubtle: '#8f8f8f',
|
|
208
|
+
primary: '#dcde8d',
|
|
209
|
+
secondary: '#034cff',
|
|
210
|
+
accent: '#a753ae',
|
|
211
|
+
active: '#12c905',
|
|
212
|
+
inactive: '#8f8f8f',
|
|
213
|
+
key: '#ffdc17',
|
|
214
|
+
action: '#a753ae',
|
|
215
|
+
separator: '#c7c7c7',
|
|
216
|
+
program: '#00ceb9',
|
|
217
|
+
fileTree: '#007b80',
|
|
218
|
+
danger: '#fc533a',
|
|
219
|
+
dangerSurface: '#fff2f0',
|
|
220
|
+
selection: '#dcde8d',
|
|
221
|
+
selectionText: readableText('#dcde8d'),
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function mix(colorA: string, colorB: string, ratio: number) {
|
|
227
|
+
const from = hexToRgb(colorA)
|
|
228
|
+
const to = hexToRgb(colorB)
|
|
229
|
+
|
|
230
|
+
return rgbToHex(
|
|
231
|
+
from.r + (to.r - from.r) * ratio,
|
|
232
|
+
from.g + (to.g - from.g) * ratio,
|
|
233
|
+
from.b + (to.b - from.b) * ratio
|
|
234
|
+
)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function aliasThemeID(themeId?: string) {
|
|
238
|
+
if (themeId === 'rose-pine') {
|
|
239
|
+
return 'rosepine'
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (themeId === 'opencode-dark' || themeId === 'opencode-light') {
|
|
243
|
+
return 'opencode'
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return themeId
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function getColorSchemeFromColorFgbg(value?: string): 'light' | 'dark' | null {
|
|
250
|
+
if (!value) {
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const parts = value
|
|
255
|
+
.split(';')
|
|
256
|
+
.map(part => Number.parseInt(part, 10))
|
|
257
|
+
.filter(part => Number.isInteger(part))
|
|
258
|
+
|
|
259
|
+
const background = parts.at(-1)
|
|
260
|
+
if (background === undefined) {
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return background <= 6 || background === 8 ? 'dark' : 'light'
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function getSystemColorScheme(): 'light' | 'dark' {
|
|
268
|
+
const envOverride = process.env.MUX_SESH_COLOR_SCHEME
|
|
269
|
+
if (envOverride === 'light' || envOverride === 'dark') {
|
|
270
|
+
return envOverride
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const detected = getColorSchemeFromColorFgbg(process.env.COLORFGBG)
|
|
274
|
+
if (detected) {
|
|
275
|
+
return detected
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return 'dark'
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function themeFromDefinition(id: string, definition: ThemeDefinition): DesktopTheme {
|
|
282
|
+
return {
|
|
283
|
+
id,
|
|
284
|
+
name: definition.name ?? id,
|
|
285
|
+
light: definition.light,
|
|
286
|
+
dark: definition.dark,
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function pickVariant(
|
|
291
|
+
theme: DesktopTheme,
|
|
292
|
+
colorScheme: ThemeColorScheme
|
|
293
|
+
): { mode: 'light' | 'dark'; variant: ThemeVariant } {
|
|
294
|
+
const mode = colorScheme === 'system' ? getSystemColorScheme() : colorScheme
|
|
295
|
+
return {
|
|
296
|
+
mode,
|
|
297
|
+
variant: mode === 'light' ? theme.light : theme.dark,
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function resolveVariantTheme(theme: DesktopTheme, mode: 'light' | 'dark'): ThemeColors {
|
|
302
|
+
const exactTheme = EXACT_TUI_THEME_COLORS[theme.id]?.[mode]
|
|
303
|
+
if (exactTheme) {
|
|
304
|
+
return exactTheme
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const variant = mode === 'light' ? theme.light : theme.dark
|
|
308
|
+
const palette = variant.palette
|
|
309
|
+
const overrides = variant.overrides ?? {}
|
|
310
|
+
const background = palette.neutral
|
|
311
|
+
const ink = palette.ink
|
|
312
|
+
const surface = overrides['surface-base'] ?? mix(background, ink, mode === 'dark' ? 0.08 : 0.035)
|
|
313
|
+
const surfaceAlt =
|
|
314
|
+
overrides['surface-raised-base'] ??
|
|
315
|
+
overrides['surface-base-hover'] ??
|
|
316
|
+
mix(background, ink, mode === 'dark' ? 0.13 : 0.06)
|
|
317
|
+
const surfaceModal =
|
|
318
|
+
overrides['surface-raised-stronger-non-alpha'] ??
|
|
319
|
+
overrides['surface-raised-stronger'] ??
|
|
320
|
+
overrides['surface-raised-base'] ??
|
|
321
|
+
surface
|
|
322
|
+
const borderMuted =
|
|
323
|
+
overrides['border-weaker-base'] ?? mix(background, ink, mode === 'dark' ? 0.08 : 0.06)
|
|
324
|
+
const border =
|
|
325
|
+
overrides['border-weak-base'] ?? mix(background, ink, mode === 'dark' ? 0.16 : 0.12)
|
|
326
|
+
const textMuted = overrides['text-base'] ?? mix(ink, background, mode === 'dark' ? 0.38 : 0.5)
|
|
327
|
+
const textSubtle = overrides['text-weak'] ?? mix(ink, background, mode === 'dark' ? 0.55 : 0.66)
|
|
328
|
+
const primary = palette.primary
|
|
329
|
+
const secondary =
|
|
330
|
+
overrides['markdown-heading'] ??
|
|
331
|
+
overrides['syntax-constant'] ??
|
|
332
|
+
palette.accent ??
|
|
333
|
+
palette.primary
|
|
334
|
+
const accent = overrides['markdown-link-text'] ?? palette.accent ?? palette.info
|
|
335
|
+
const action = overrides['markdown-link-text'] ?? palette.info
|
|
336
|
+
const fileTree = overrides['markdown-link'] ?? palette.info
|
|
337
|
+
const program = overrides['markdown-code'] ?? palette.warning
|
|
338
|
+
const separator = overrides['markdown-horizontal-rule'] ?? borderMuted
|
|
339
|
+
const dangerSurface =
|
|
340
|
+
overrides['surface-critical-base'] ??
|
|
341
|
+
mix(background, palette.error, mode === 'dark' ? 0.2 : 0.12)
|
|
342
|
+
const selection = palette.primary
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
background,
|
|
346
|
+
surface,
|
|
347
|
+
surfaceAlt,
|
|
348
|
+
surfaceModal,
|
|
349
|
+
overlay: mix(background, ink, mode === 'dark' ? 0.2 : 0.04),
|
|
350
|
+
border,
|
|
351
|
+
borderMuted,
|
|
352
|
+
text: overrides['text-strong'] ?? overrides['markdown-text'] ?? ink,
|
|
353
|
+
textMuted,
|
|
354
|
+
textSubtle,
|
|
355
|
+
primary,
|
|
356
|
+
secondary,
|
|
357
|
+
accent,
|
|
358
|
+
active: palette.success,
|
|
359
|
+
inactive: textSubtle,
|
|
360
|
+
key: palette.warning,
|
|
361
|
+
action,
|
|
362
|
+
separator,
|
|
363
|
+
program,
|
|
364
|
+
fileTree,
|
|
365
|
+
danger: palette.error,
|
|
366
|
+
dangerSurface,
|
|
367
|
+
selection,
|
|
368
|
+
selectionText: readableText(selection),
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export function resolveTheme(
|
|
373
|
+
themeId?: string,
|
|
374
|
+
customThemes: Record<string, ThemeDefinition> = {},
|
|
375
|
+
colorScheme: ThemeColorScheme = DEFAULT_COLOR_SCHEME
|
|
376
|
+
) {
|
|
377
|
+
const customCatalog = Object.fromEntries(
|
|
378
|
+
Object.entries(customThemes).map(([id, definition]) => [
|
|
379
|
+
id,
|
|
380
|
+
themeFromDefinition(id, definition),
|
|
381
|
+
])
|
|
382
|
+
)
|
|
383
|
+
const catalog = {
|
|
384
|
+
...BUILTIN_THEMES,
|
|
385
|
+
...customCatalog,
|
|
386
|
+
}
|
|
387
|
+
const normalizedID = aliasThemeID(themeId)
|
|
388
|
+
const id = normalizedID && catalog[normalizedID] ? normalizedID : DEFAULT_THEME_ID
|
|
389
|
+
const theme = catalog[id] ?? BUILTIN_THEMES[DEFAULT_THEME_ID]
|
|
390
|
+
const { mode } = pickVariant(theme, colorScheme)
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
id,
|
|
394
|
+
name: theme.name,
|
|
395
|
+
mode,
|
|
396
|
+
colors: resolveVariantTheme(theme, mode),
|
|
397
|
+
catalog,
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export function getPanelStyle(theme: ThemeColors, width: 'split' | 'full' = 'split') {
|
|
402
|
+
return {
|
|
403
|
+
border: false,
|
|
404
|
+
backgroundColor: theme.surface,
|
|
405
|
+
paddingTop: 0.4,
|
|
406
|
+
paddingBottom: 0.4,
|
|
407
|
+
paddingLeft: 1,
|
|
408
|
+
paddingRight: 1,
|
|
409
|
+
width: width === 'full' ? ('100%' as const) : ('50%' as const),
|
|
410
|
+
height: '100%' as const,
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export function getDetailPanelStyle(theme: ThemeColors) {
|
|
415
|
+
return {
|
|
416
|
+
...getPanelStyle(theme, 'split'),
|
|
417
|
+
backgroundColor: theme.surface,
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function getModalStyle(theme: ThemeColors, columns: number, preferredWidth = 76) {
|
|
422
|
+
return {
|
|
423
|
+
width: Math.max(48, Math.min(columns - 8, preferredWidth)),
|
|
424
|
+
backgroundColor: theme.surfaceModal,
|
|
425
|
+
paddingTop: 1,
|
|
426
|
+
paddingBottom: 1,
|
|
427
|
+
paddingLeft: 2,
|
|
428
|
+
paddingRight: 2,
|
|
429
|
+
flexDirection: 'column' as const,
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const ThemeContext = createContext<ThemeColors>(EXACT_TUI_THEME_COLORS.rosepine!.dark)
|
|
434
|
+
|
|
435
|
+
export function ThemeProvider(props: { theme: ThemeColors; children: ReactNode }) {
|
|
436
|
+
return <ThemeContext.Provider value={props.theme}>{props.children}</ThemeContext.Provider>
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function useTheme(): ThemeColors {
|
|
440
|
+
return useContext(ThemeContext)
|
|
441
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -23,6 +23,67 @@ export interface IconConfig {
|
|
|
23
23
|
opencode: string
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export type ThemeColorScheme = 'light' | 'dark' | 'system'
|
|
27
|
+
|
|
28
|
+
export interface ThemePalette {
|
|
29
|
+
neutral: string
|
|
30
|
+
ink: string
|
|
31
|
+
primary: string
|
|
32
|
+
success: string
|
|
33
|
+
warning: string
|
|
34
|
+
error: string
|
|
35
|
+
info: string
|
|
36
|
+
accent?: string
|
|
37
|
+
interactive?: string
|
|
38
|
+
diffAdd?: string
|
|
39
|
+
diffDelete?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ThemeVariant {
|
|
43
|
+
palette: ThemePalette
|
|
44
|
+
overrides?: Record<string, string>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface DesktopTheme {
|
|
48
|
+
name: string
|
|
49
|
+
id: string
|
|
50
|
+
light: ThemeVariant
|
|
51
|
+
dark: ThemeVariant
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ThemeColors {
|
|
55
|
+
background: string
|
|
56
|
+
surface: string
|
|
57
|
+
surfaceAlt: string
|
|
58
|
+
surfaceModal: string
|
|
59
|
+
overlay: string
|
|
60
|
+
border: string
|
|
61
|
+
borderMuted: string
|
|
62
|
+
text: string
|
|
63
|
+
textMuted: string
|
|
64
|
+
textSubtle: string
|
|
65
|
+
primary: string
|
|
66
|
+
secondary: string
|
|
67
|
+
accent: string
|
|
68
|
+
active: string
|
|
69
|
+
inactive: string
|
|
70
|
+
key: string
|
|
71
|
+
action: string
|
|
72
|
+
separator: string
|
|
73
|
+
program: string
|
|
74
|
+
fileTree: string
|
|
75
|
+
danger: string
|
|
76
|
+
dangerSurface: string
|
|
77
|
+
selection: string
|
|
78
|
+
selectionText: string
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface ThemeDefinition {
|
|
82
|
+
name?: string
|
|
83
|
+
light: ThemeVariant
|
|
84
|
+
dark: ThemeVariant
|
|
85
|
+
}
|
|
86
|
+
|
|
26
87
|
export interface SessionDefaults {
|
|
27
88
|
startupCommand?: string
|
|
28
89
|
previewCommand?: string
|
|
@@ -98,11 +159,15 @@ export interface Config {
|
|
|
98
159
|
editor: string
|
|
99
160
|
editorCmd: string
|
|
100
161
|
keybindMode?: KeybindMode
|
|
162
|
+
prefixKey?: string
|
|
101
163
|
autoUpdate?: boolean
|
|
102
164
|
dirLength?: number
|
|
103
165
|
hiddenSessions?: string[]
|
|
104
166
|
zoxideMode?: ZoxideMode
|
|
105
167
|
sortOrder?: SortOrder
|
|
168
|
+
theme?: string
|
|
169
|
+
colorScheme?: ThemeColorScheme
|
|
170
|
+
themes?: Record<string, ThemeDefinition>
|
|
106
171
|
icons?: IconConfig
|
|
107
172
|
defaultSession?: SessionDefaults
|
|
108
173
|
projects?: ProjectProfile[]
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
+
import { useEffect } from 'react'
|
|
3
|
+
import { useTheme } from '../styles/theme'
|
|
4
|
+
import { AppMode, type Item, type KeybindMode } from '../types'
|
|
5
|
+
import Modal from './Modal'
|
|
6
|
+
|
|
7
|
+
export type CommandId =
|
|
8
|
+
| 'search'
|
|
9
|
+
| 'new-session'
|
|
10
|
+
| 'open-settings'
|
|
11
|
+
| 'view-projects'
|
|
12
|
+
| 'view-sessions'
|
|
13
|
+
| 'rename-session'
|
|
14
|
+
| 'kill-session'
|
|
15
|
+
| 'last-session'
|
|
16
|
+
| 'root-session'
|
|
17
|
+
| 'edit-target'
|
|
18
|
+
| 'open-opencode'
|
|
19
|
+
| 'refresh'
|
|
20
|
+
| 'back'
|
|
21
|
+
|
|
22
|
+
export interface CommandEntry {
|
|
23
|
+
id: CommandId
|
|
24
|
+
category: string
|
|
25
|
+
title: string
|
|
26
|
+
keybind: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface Props {
|
|
30
|
+
columns: number
|
|
31
|
+
themeId: string
|
|
32
|
+
entries: CommandEntry[]
|
|
33
|
+
cursor: number
|
|
34
|
+
searchQuery: string
|
|
35
|
+
textareaRef: { current: TextareaRenderable | null }
|
|
36
|
+
onContentChange: () => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function prefixed(prefixKey: string | undefined, suffix: string): string {
|
|
40
|
+
return `${prefixKey ?? 'ctrl+x'} ${suffix}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getCommandEntries(
|
|
44
|
+
appMode: AppMode,
|
|
45
|
+
keybindMode: KeybindMode = 'vim',
|
|
46
|
+
prefixKey: string | undefined,
|
|
47
|
+
selectedItem?: Item
|
|
48
|
+
): CommandEntry[] {
|
|
49
|
+
const commandKey = (suffix: string, fallback: string) => (prefixKey ? prefixed(prefixKey, suffix) : fallback)
|
|
50
|
+
const prefixCategory = prefixKey ? `Prefix ${prefixKey}` : 'Prefix'
|
|
51
|
+
|
|
52
|
+
if (appMode === AppMode.OpencodeManage) {
|
|
53
|
+
return [
|
|
54
|
+
{ id: 'back', category: 'Direct', title: 'Back', keybind: 'esc' },
|
|
55
|
+
{ id: 'kill-session', category: 'Direct', title: 'Kill session', keybind: 'd' },
|
|
56
|
+
{ id: 'open-settings', category: 'Direct', title: 'Open settings', keybind: 'ctrl+p' },
|
|
57
|
+
{ id: 'rename-session', category: prefixCategory, title: 'Rename session', keybind: commandKey('r', 'r') },
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return [
|
|
62
|
+
{ id: 'search', category: 'Direct', title: 'Search', keybind: 'i' },
|
|
63
|
+
{ id: 'new-session', category: 'Direct', title: 'New session', keybind: 'n' },
|
|
64
|
+
{ id: 'open-opencode', category: 'Direct', title: 'Open OpenCode sessions', keybind: 'o' },
|
|
65
|
+
{ id: 'kill-session', category: 'Direct', title: 'Kill session', keybind: 'd' },
|
|
66
|
+
{ id: 'open-settings', category: 'Direct', title: 'Open settings', keybind: 'ctrl+p' },
|
|
67
|
+
{ id: 'view-projects', category: prefixCategory, title: 'Show projects', keybind: commandKey('p', 'p') },
|
|
68
|
+
{ id: 'view-sessions', category: prefixCategory, title: 'Show sessions', keybind: commandKey('s', 's') },
|
|
69
|
+
{ id: 'rename-session', category: prefixCategory, title: 'Rename session', keybind: commandKey('r', 'r') },
|
|
70
|
+
{ id: 'last-session', category: prefixCategory, title: 'Last session', keybind: commandKey('l', 'l') },
|
|
71
|
+
{ id: 'root-session', category: prefixCategory, title: 'Root session', keybind: commandKey('g', 'g') },
|
|
72
|
+
...(selectedItem?.itemKind === 'configured'
|
|
73
|
+
? [{ id: 'edit-target' as const, category: prefixCategory, title: 'Edit target', keybind: commandKey('e', 'e') }]
|
|
74
|
+
: []),
|
|
75
|
+
{ id: 'refresh', category: prefixCategory, title: 'Refresh', keybind: commandKey('shift+r', 'R') },
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function filterCommandEntries(entries: CommandEntry[], query: string): CommandEntry[] {
|
|
80
|
+
const normalizedQuery = query.trim().toLowerCase()
|
|
81
|
+
|
|
82
|
+
if (!normalizedQuery) {
|
|
83
|
+
return entries
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return entries.filter(entry => {
|
|
87
|
+
const haystack = `${entry.category} ${entry.title} ${entry.keybind}`.toLowerCase()
|
|
88
|
+
return haystack.includes(normalizedQuery)
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default function CommandsModal({
|
|
93
|
+
columns,
|
|
94
|
+
themeId,
|
|
95
|
+
entries,
|
|
96
|
+
cursor,
|
|
97
|
+
searchQuery,
|
|
98
|
+
textareaRef,
|
|
99
|
+
onContentChange,
|
|
100
|
+
}: Props) {
|
|
101
|
+
const theme = useTheme()
|
|
102
|
+
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
queueMicrotask(() => {
|
|
105
|
+
textareaRef.current?.focus()
|
|
106
|
+
})
|
|
107
|
+
}, [textareaRef])
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Modal title='Commands' description={themeId} footer='↑/↓ navigate enter run esc close' columns={columns} preferredWidth={68}>
|
|
111
|
+
<box style={{ backgroundColor: theme.surfaceAlt, paddingLeft: 1, paddingRight: 1, marginBottom: 1 }}>
|
|
112
|
+
<textarea ref={textareaRef} initialValue={searchQuery} onContentChange={onContentChange} focused placeholder='Search' />
|
|
113
|
+
</box>
|
|
114
|
+
|
|
115
|
+
<box style={{ flexDirection: 'column' }}>
|
|
116
|
+
{entries.length === 0 ? (
|
|
117
|
+
<text style={{ fg: theme.textMuted }}>No commands found</text>
|
|
118
|
+
) : (
|
|
119
|
+
entries.map((row, index) => {
|
|
120
|
+
const showCategory = index === 0 || entries[index - 1]?.category !== row.category
|
|
121
|
+
const selected = index === cursor
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<box key={`${row.category}:${row.id}`} style={{ flexDirection: 'column' }}>
|
|
125
|
+
{showCategory && <text style={{ fg: theme.accent, marginTop: index === 0 ? 0 : 1 }}>{row.category}</text>}
|
|
126
|
+
<box
|
|
127
|
+
style={{
|
|
128
|
+
flexDirection: 'row',
|
|
129
|
+
justifyContent: 'space-between',
|
|
130
|
+
backgroundColor: selected ? theme.selection : 'transparent',
|
|
131
|
+
paddingLeft: 1,
|
|
132
|
+
paddingRight: 1,
|
|
133
|
+
}}
|
|
134
|
+
>
|
|
135
|
+
<text style={{ fg: selected ? theme.selectionText : theme.text }}>{row.title}</text>
|
|
136
|
+
<text style={{ fg: selected ? theme.selectionText : theme.textMuted }}>{row.keybind}</text>
|
|
137
|
+
</box>
|
|
138
|
+
</box>
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
)}
|
|
142
|
+
</box>
|
|
143
|
+
</Modal>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useTheme } from '../styles/theme'
|
|
2
2
|
|
|
3
3
|
interface Props {
|
|
4
4
|
text: string
|
|
@@ -13,8 +13,11 @@ interface Props {
|
|
|
13
13
|
export default function HighlightedText({
|
|
14
14
|
text,
|
|
15
15
|
matchIndices = [],
|
|
16
|
-
highlightColor
|
|
16
|
+
highlightColor,
|
|
17
17
|
}: Props) {
|
|
18
|
+
const theme = useTheme()
|
|
19
|
+
const resolvedHighlightColor = highlightColor ?? theme.action
|
|
20
|
+
|
|
18
21
|
// If no matches, return plain text
|
|
19
22
|
if (matchIndices.length === 0) {
|
|
20
23
|
return <>{text}</>
|
|
@@ -49,7 +52,7 @@ export default function HighlightedText({
|
|
|
49
52
|
<>
|
|
50
53
|
{segments.map((segment, i) =>
|
|
51
54
|
segment.highlighted ? (
|
|
52
|
-
<span key={i} style={{ fg:
|
|
55
|
+
<span key={i} style={{ fg: resolvedHighlightColor }}>
|
|
53
56
|
{segment.text}
|
|
54
57
|
</span>
|
|
55
58
|
) : (
|