mux-sesh 1.4.1 → 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/README.md +123 -7
- package/package.json +3 -3
- package/src/app.tsx +746 -173
- package/src/components/KeybindHelp.tsx +178 -111
- package/src/config/index.ts +413 -20
- package/src/config/listed-sessions.ts +36 -0
- package/src/config/session-rules.ts +101 -0
- package/src/handlers/actions.ts +93 -6
- package/src/handlers/keyboard.ts +299 -79
- package/src/items/order.ts +50 -0
- package/src/opencode/session.ts +1 -17
- package/src/opencode/stats.ts +1 -1
- package/src/preview/project.ts +235 -0
- package/src/projects/session-links.ts +31 -0
- package/src/search/index.ts +83 -47
- 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/tmux/index.ts +58 -14
- package/src/tmux/projects.ts +151 -20
- package/src/tmux/workflows.ts +22 -0
- package/src/types/index.ts +114 -0
- package/src/ui/CommandsModal.tsx +145 -0
- package/src/ui/HighlightedText.tsx +6 -3
- package/src/ui/ItemList.tsx +47 -41
- package/src/ui/Modal.tsx +41 -0
- package/src/ui/OpencodeSessionGroup.tsx +50 -46
- 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 +168 -72
- package/src/ui/SessionList.tsx +59 -34
- 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 +78 -0
- package/src/ui/list-window.ts +22 -0
- package/src/update/installation.ts +4 -15
- package/src/update/version.ts +2 -1
- package/src/util/glob.ts +47 -0
- package/src/util/terminal.ts +6 -20
- 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/tmux/index.ts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { spawn } from 'bun'
|
|
2
2
|
import type { Item, SessionDetails, WindowInfo } from '../types'
|
|
3
3
|
|
|
4
|
+
export interface CreateTmuxSessionOptions {
|
|
5
|
+
startupCommand?: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function sanitizeSessionName(name: string): string {
|
|
9
|
+
return name.replace(/\./g, '_').replace(/ /g, '_')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function readTmuxValue(args: string[], errorMessage: string): Promise<string> {
|
|
13
|
+
const proc = spawn(args)
|
|
14
|
+
const output = await new Response(proc.stdout).text()
|
|
15
|
+
await proc.exited
|
|
16
|
+
|
|
17
|
+
if (proc.exitCode !== 0) {
|
|
18
|
+
throw new Error(errorMessage)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const value = output.trim()
|
|
22
|
+
if (!value) {
|
|
23
|
+
throw new Error(errorMessage)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return value
|
|
27
|
+
}
|
|
28
|
+
|
|
4
29
|
export async function listTmuxSessions(): Promise<Item[]> {
|
|
5
30
|
const proc = spawn([
|
|
6
31
|
'tmux',
|
|
@@ -19,6 +44,7 @@ export async function listTmuxSessions(): Promise<Item[]> {
|
|
|
19
44
|
path: name,
|
|
20
45
|
desc: '',
|
|
21
46
|
isSession: true,
|
|
47
|
+
itemKind: 'tmux' as const,
|
|
22
48
|
isAttached: attached === '1',
|
|
23
49
|
windowCount: windows,
|
|
24
50
|
createdAt: parseInt(created, 10),
|
|
@@ -29,8 +55,12 @@ export async function listTmuxSessions(): Promise<Item[]> {
|
|
|
29
55
|
return sessions.sort((a, b) => a.title.localeCompare(b.title))
|
|
30
56
|
}
|
|
31
57
|
|
|
32
|
-
export async function createTmuxSession(
|
|
33
|
-
|
|
58
|
+
export async function createTmuxSession(
|
|
59
|
+
name: string,
|
|
60
|
+
path: string,
|
|
61
|
+
options: CreateTmuxSessionOptions = {}
|
|
62
|
+
): Promise<void> {
|
|
63
|
+
const sessionName = sanitizeSessionName(name)
|
|
34
64
|
const insideTmux = !!process.env.TMUX
|
|
35
65
|
|
|
36
66
|
// Check if tmux is running
|
|
@@ -39,7 +69,12 @@ export async function createTmuxSession(name: string, path: string): Promise<voi
|
|
|
39
69
|
const isTmuxRunning = tmuxRunning.exitCode === 0
|
|
40
70
|
|
|
41
71
|
if (!insideTmux && !isTmuxRunning) {
|
|
42
|
-
const
|
|
72
|
+
const command = ['tmux', 'new-session', '-s', sessionName, '-c', path]
|
|
73
|
+
if (options.startupCommand) {
|
|
74
|
+
command.push(options.startupCommand)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const proc = spawn(command, {
|
|
43
78
|
stdin: 'inherit',
|
|
44
79
|
stdout: 'inherit',
|
|
45
80
|
stderr: 'inherit',
|
|
@@ -55,15 +90,10 @@ export async function createTmuxSession(name: string, path: string): Promise<voi
|
|
|
55
90
|
const createProc = spawn(['tmux', 'new-session', '-d', '-s', sessionName, '-c', path])
|
|
56
91
|
await createProc.exited
|
|
57
92
|
|
|
58
|
-
|
|
59
|
-
'tmux',
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
sessionName,
|
|
63
|
-
"nvim -c \"lua vim.defer_fn(function() if pcall(require, 'telescope') then vim.cmd('Telescope find_files') end end, 100)\"",
|
|
64
|
-
'Enter',
|
|
65
|
-
])
|
|
66
|
-
await nvimProc.exited
|
|
93
|
+
if (options.startupCommand) {
|
|
94
|
+
const startupProc = spawn(['tmux', 'send-keys', '-t', sessionName, options.startupCommand, 'Enter'])
|
|
95
|
+
await startupProc.exited
|
|
96
|
+
}
|
|
67
97
|
}
|
|
68
98
|
|
|
69
99
|
const switchProc = spawn(['tmux', 'switch-client', '-t', sessionName])
|
|
@@ -71,7 +101,7 @@ export async function createTmuxSession(name: string, path: string): Promise<voi
|
|
|
71
101
|
}
|
|
72
102
|
|
|
73
103
|
export async function createNamedTmuxSession(name: string): Promise<void> {
|
|
74
|
-
const sessionName = name
|
|
104
|
+
const sessionName = sanitizeSessionName(name)
|
|
75
105
|
const insideTmux = !!process.env.TMUX
|
|
76
106
|
|
|
77
107
|
const tmuxRunning = spawn(['pgrep', 'tmux'])
|
|
@@ -105,13 +135,27 @@ export async function switchTmuxSession(name: string): Promise<void> {
|
|
|
105
135
|
await proc.exited
|
|
106
136
|
}
|
|
107
137
|
|
|
138
|
+
export async function getCurrentTmuxSessionName(): Promise<string> {
|
|
139
|
+
return readTmuxValue(
|
|
140
|
+
['tmux', 'display-message', '-p', '#S'],
|
|
141
|
+
'Failed to resolve the current tmux session name'
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export async function getTmuxSessionDirectory(sessionName: string): Promise<string> {
|
|
146
|
+
return readTmuxValue(
|
|
147
|
+
['tmux', 'display-message', '-t', sessionName, '-p', '#{pane_current_path}'],
|
|
148
|
+
`Failed to resolve tmux directory for session '${sessionName}'`
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
108
152
|
export async function killTmuxSession(name: string): Promise<void> {
|
|
109
153
|
const proc = spawn(['tmux', 'kill-session', '-t', name])
|
|
110
154
|
await proc.exited
|
|
111
155
|
}
|
|
112
156
|
|
|
113
157
|
export async function renameTmuxSession(oldName: string, newName: string): Promise<void> {
|
|
114
|
-
const sanitizedName = newName
|
|
158
|
+
const sanitizedName = sanitizeSessionName(newName)
|
|
115
159
|
const proc = spawn(['tmux', 'rename-session', '-t', oldName, sanitizedName])
|
|
116
160
|
await proc.exited
|
|
117
161
|
}
|