mux-sesh 1.10.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +133 -86
  2. package/bin/mux-sesh +45 -17
  3. package/bin/platform.sh +139 -0
  4. package/bin/postinstall +22 -0
  5. package/package.json +27 -38
  6. package/src/agents/index.ts +0 -1
  7. package/src/agents/session-name.ts +0 -24
  8. package/src/app/commands.ts +0 -138
  9. package/src/app/controller.ts +0 -437
  10. package/src/app/controls.ts +0 -123
  11. package/src/app/core-state.ts +0 -75
  12. package/src/app/data.ts +0 -130
  13. package/src/app/derived.ts +0 -77
  14. package/src/app/effects.ts +0 -650
  15. package/src/app/handlers.ts +0 -406
  16. package/src/app/keyboard.ts +0 -165
  17. package/src/app/modal-keyboard.ts +0 -137
  18. package/src/app/modal-state.ts +0 -53
  19. package/src/app/modals-layer.tsx +0 -159
  20. package/src/app/modals.ts +0 -108
  21. package/src/app/notifications.ts +0 -21
  22. package/src/app/opencode.ts +0 -49
  23. package/src/app/operations.ts +0 -31
  24. package/src/app/runtime.ts +0 -79
  25. package/src/app/screen.tsx +0 -240
  26. package/src/app/state.ts +0 -178
  27. package/src/app/textarea.ts +0 -16
  28. package/src/app/view.ts +0 -101
  29. package/src/app.tsx +0 -50
  30. package/src/config/index.ts +0 -475
  31. package/src/config/listed-sessions.ts +0 -33
  32. package/src/config/paths.ts +0 -13
  33. package/src/config/session-rules.ts +0 -100
  34. package/src/config/store.ts +0 -33
  35. package/src/files/target.ts +0 -96
  36. package/src/handlers/action-helpers.ts +0 -83
  37. package/src/handlers/actions.ts +0 -216
  38. package/src/handlers/keyboard/agents.ts +0 -134
  39. package/src/handlers/keyboard/index.ts +0 -5
  40. package/src/handlers/keyboard/new-session.ts +0 -58
  41. package/src/handlers/keyboard/normal.ts +0 -220
  42. package/src/handlers/keyboard/search.ts +0 -118
  43. package/src/handlers/keyboard/shared.ts +0 -117
  44. package/src/herdr/backend.ts +0 -357
  45. package/src/herdr/protocol.ts +0 -268
  46. package/src/index.tsx +0 -23
  47. package/src/items/order.ts +0 -95
  48. package/src/multiplexer/backend.ts +0 -43
  49. package/src/multiplexer/command.ts +0 -48
  50. package/src/multiplexer/index.ts +0 -21
  51. package/src/multiplexer/items.ts +0 -66
  52. package/src/multiplexer/resolve.ts +0 -109
  53. package/src/multiplexer/tmux-backend.ts +0 -87
  54. package/src/multiplexer/types.ts +0 -93
  55. package/src/opencode/constants.ts +0 -7
  56. package/src/opencode/index.ts +0 -20
  57. package/src/opencode/parser.ts +0 -45
  58. package/src/opencode/session-name.ts +0 -13
  59. package/src/opencode/session.ts +0 -146
  60. package/src/opencode/sqlite.ts +0 -447
  61. package/src/opencode/stats.ts +0 -26
  62. package/src/opencode/tokens.ts +0 -116
  63. package/src/opencode/types.ts +0 -33
  64. package/src/preview/project.ts +0 -362
  65. package/src/projects/session-links.ts +0 -52
  66. package/src/search/fff.ts +0 -224
  67. package/src/search/index.ts +0 -198
  68. package/src/settings.ts +0 -465
  69. package/src/styles/omarchy.ts +0 -295
  70. package/src/styles/opencode-themes-a.ts +0 -1442
  71. package/src/styles/opencode-themes-b.ts +0 -1212
  72. package/src/styles/opencode-tui-colors.ts +0 -1784
  73. package/src/styles/terminal-palette.ts +0 -156
  74. package/src/styles/theme-follow.ts +0 -94
  75. package/src/styles/theme.tsx +0 -311
  76. package/src/tmux/actions.ts +0 -145
  77. package/src/tmux/details.ts +0 -104
  78. package/src/tmux/helpers.ts +0 -35
  79. package/src/tmux/index.ts +0 -10
  80. package/src/tmux/list.ts +0 -31
  81. package/src/tmux/project-discovery.ts +0 -116
  82. package/src/tmux/project-loader.ts +0 -92
  83. package/src/tmux/project-zoxide.ts +0 -128
  84. package/src/tmux/projects.ts +0 -38
  85. package/src/tmux/workflows.ts +0 -26
  86. package/src/types/index.ts +0 -221
  87. package/src/ui/AgentSessionGroup.tsx +0 -93
  88. package/src/ui/CommandsModal.tsx +0 -246
  89. package/src/ui/ErrorScreen.tsx +0 -102
  90. package/src/ui/HighlightedText.tsx +0 -60
  91. package/src/ui/ItemList.tsx +0 -119
  92. package/src/ui/Modal.tsx +0 -48
  93. package/src/ui/OpencodeStatsPanel.tsx +0 -233
  94. package/src/ui/RenameModal.tsx +0 -42
  95. package/src/ui/SearchInput.tsx +0 -43
  96. package/src/ui/SessionDetailsPanel.tsx +0 -273
  97. package/src/ui/SessionList.tsx +0 -119
  98. package/src/ui/SettingEditorModal.tsx +0 -55
  99. package/src/ui/SettingOptionsModal.tsx +0 -95
  100. package/src/ui/SettingsModal.tsx +0 -102
  101. package/src/ui/Toast.tsx +0 -34
  102. package/src/ui/VersionBadge.tsx +0 -45
  103. package/src/ui/item-icon.ts +0 -110
  104. package/src/ui/list-window.ts +0 -35
  105. package/src/ui/session-meta.ts +0 -10
  106. package/src/ui/text-columns.ts +0 -17
  107. package/src/ui/use-textarea-focus.ts +0 -29
  108. package/src/update/events.ts +0 -28
  109. package/src/update/index.ts +0 -91
  110. package/src/update/installation.ts +0 -161
  111. package/src/update/version.ts +0 -33
  112. package/src/util/ansi.ts +0 -3
  113. package/src/util/browser.ts +0 -37
  114. package/src/util/clipboard.ts +0 -22
  115. package/src/util/errors.ts +0 -170
  116. package/src/util/github.ts +0 -100
  117. package/src/util/glob.ts +0 -51
  118. package/src/util/path-display.ts +0 -98
  119. package/src/util/perf.ts +0 -23
  120. package/src/util/shell.ts +0 -3
  121. package/src/util/shutdown.ts +0 -111
  122. package/src/util/terminal.ts +0 -28
  123. package/src/util/time.ts +0 -48
  124. package/tsconfig.json +0 -25
@@ -1,156 +0,0 @@
1
- import type { ThemeColors } from '../types'
2
-
3
- export type TerminalMode = 'light' | 'dark'
4
-
5
- export interface TerminalColorsInput {
6
- palette?: Array<string | null | undefined>
7
- defaultForeground?: string | null
8
- defaultBackground?: string | null
9
- highlightBackground?: string | null
10
- highlightForeground?: string | null
11
- }
12
-
13
- export interface TerminalPalette {
14
- mode: TerminalMode
15
- background: string
16
- foreground: string
17
- palette: Array<string | undefined>
18
- highlightBackground?: string
19
- highlightForeground?: string
20
- }
21
-
22
- function clamp(value: number): number {
23
- return Math.max(0, Math.min(255, Math.round(value)))
24
- }
25
-
26
- function normalizeHex(color: string): string | null {
27
- const trimmed = color.trim()
28
- const hex = trimmed.startsWith('#') ? trimmed.slice(1) : trimmed
29
-
30
- if (!/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/.test(hex)) {
31
- return null
32
- }
33
-
34
- if (hex.length === 3) {
35
- return `#${hex
36
- .split('')
37
- .map(char => `${char}${char}`)
38
- .join('')}`
39
- }
40
-
41
- return `#${hex.slice(0, 6)}`
42
- }
43
-
44
- function hexToRgb(hex: string): { r: number; g: number; b: number } {
45
- const normalized = hex.slice(1)
46
- const channel = (offset: number) => parseInt(normalized.slice(offset, offset + 2), 16)
47
-
48
- return {
49
- r: channel(0),
50
- g: channel(2),
51
- b: channel(4),
52
- }
53
- }
54
-
55
- function rgbToHex(r: number, g: number, b: number): string {
56
- return `#${[r, g, b].map(channel => clamp(channel).toString(16).padStart(2, '0')).join('')}`
57
- }
58
-
59
- function luminance(color: string): number {
60
- const { r, g, b } = hexToRgb(color)
61
- return 0.299 * r + 0.587 * g + 0.114 * b
62
- }
63
-
64
- function readableText(background: string): string {
65
- return luminance(background) > 150 ? '#171717' : '#f5f5f5'
66
- }
67
-
68
- function mix(colorA: string, colorB: string, ratio: number): string {
69
- const from = hexToRgb(colorA)
70
- const to = hexToRgb(colorB)
71
-
72
- return rgbToHex(
73
- from.r + (to.r - from.r) * ratio,
74
- from.g + (to.g - from.g) * ratio,
75
- from.b + (to.b - from.b) * ratio
76
- )
77
- }
78
-
79
- function asHex(value?: string | null): string | undefined {
80
- return value ? (normalizeHex(value) ?? undefined) : undefined
81
- }
82
-
83
- export function colorSchemeFromColorFgbg(value?: string): TerminalMode | null {
84
- if (!value) {
85
- return null
86
- }
87
-
88
- const parts = value
89
- .split(';')
90
- .map(part => Number.parseInt(part, 10))
91
- .filter(part => Number.isInteger(part))
92
-
93
- const background = parts.at(-1)
94
- if (background === undefined) {
95
- return null
96
- }
97
-
98
- return background <= 6 || background === 8 ? 'dark' : 'light'
99
- }
100
-
101
- export function terminalColorsToPalette(colors: TerminalColorsInput): TerminalPalette | null {
102
- const ansi = (colors.palette ?? []).map(entry => asHex(entry))
103
- const background = asHex(colors.defaultBackground) ?? ansi[0]
104
- const foreground = asHex(colors.defaultForeground) ?? ansi[7]
105
-
106
- if (!background || !foreground) {
107
- return null
108
- }
109
-
110
- return {
111
- mode: luminance(background) > 150 ? 'light' : 'dark',
112
- background,
113
- foreground,
114
- palette: ansi,
115
- highlightBackground: asHex(colors.highlightBackground),
116
- highlightForeground: asHex(colors.highlightForeground),
117
- }
118
- }
119
-
120
- export function terminalPaletteToThemeColors(palette: TerminalPalette): ThemeColors {
121
- const background = palette.background
122
- const text = palette.foreground
123
- const ansi = palette.palette
124
- const muted = ansi[8] ?? mix(text, background, 0.5)
125
- const chrome = ansi[6] ?? ansi[4] ?? text
126
- const accent = chrome
127
- const danger = ansi[1] ?? text
128
- const selection = palette.highlightBackground ?? chrome
129
-
130
- return {
131
- background,
132
- surface: background,
133
- surfaceAlt: mix(background, text, 0.08),
134
- surfaceModal: mix(background, text, 0.04),
135
- overlay: '#000000',
136
- border: muted,
137
- borderMuted: muted,
138
- text,
139
- textMuted: muted,
140
- textSubtle: muted,
141
- primary: chrome,
142
- secondary: ansi[5] ?? accent,
143
- accent,
144
- active: ansi[2] ?? text,
145
- inactive: muted,
146
- key: ansi[3] ?? text,
147
- action: accent,
148
- separator: muted,
149
- program: ansi[2] ?? text,
150
- fileTree: chrome,
151
- danger,
152
- dangerSurface: mix(background, danger, 0.2),
153
- selection,
154
- selectionText: palette.highlightForeground ?? readableText(selection),
155
- }
156
- }
@@ -1,94 +0,0 @@
1
- import { watch, type FSWatcher } from 'node:fs'
2
- import { getOmarchyThemeNamePath } from './omarchy'
3
-
4
- export type ThemeFollowSignal = 'SIGUSR2'
5
-
6
- export interface ThemeFollowHandlers {
7
- onRefresh: () => void
8
- }
9
-
10
- export interface ThemeFollowWatchHandle {
11
- close: () => void
12
- }
13
-
14
- export interface SubscribeThemeFollowOptions {
15
- debounceMs?: number
16
- watch?: (path: string, listener: () => void) => ThemeFollowWatchHandle
17
- onSignal?: (signal: ThemeFollowSignal, listener: () => void) => () => void
18
- }
19
-
20
- export interface ThemeFollowSubscription {
21
- stop: () => void
22
- }
23
-
24
- const DEFAULT_DEBOUNCE_MS = 80
25
-
26
- export function ignoreUnhandledThemeFollowSignal(): void {
27
- process.on('SIGUSR2', () => {})
28
- }
29
-
30
- function defaultWatch(path: string, listener: () => void): ThemeFollowWatchHandle {
31
- const watcher: FSWatcher = watch(path, listener)
32
- return {
33
- close: () => {
34
- watcher.close()
35
- },
36
- }
37
- }
38
-
39
- function defaultOnSignal(signal: ThemeFollowSignal, listener: () => void): () => void {
40
- process.on(signal, listener)
41
- return () => {
42
- process.off(signal, listener)
43
- }
44
- }
45
-
46
- export function subscribeThemeFollow(
47
- homeDir: string,
48
- handlers: ThemeFollowHandlers,
49
- options: SubscribeThemeFollowOptions = {}
50
- ): ThemeFollowSubscription {
51
- const debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS
52
- const watchPath = options.watch ?? defaultWatch
53
- const onSignal = options.onSignal ?? defaultOnSignal
54
- let timeout: ReturnType<typeof setTimeout> | undefined
55
- let stopped = false
56
-
57
- const scheduleRefresh = (): void => {
58
- if (stopped) {
59
- return
60
- }
61
-
62
- if (timeout) {
63
- clearTimeout(timeout)
64
- }
65
-
66
- timeout = setTimeout(() => {
67
- timeout = undefined
68
- if (!stopped) {
69
- handlers.onRefresh()
70
- }
71
- }, debounceMs)
72
- }
73
-
74
- let watcher: ThemeFollowWatchHandle | undefined
75
- try {
76
- watcher = watchPath(getOmarchyThemeNamePath(homeDir), scheduleRefresh)
77
- } catch {
78
- watcher = undefined
79
- }
80
-
81
- const unsubscribeSignal = onSignal('SIGUSR2', scheduleRefresh)
82
-
83
- return {
84
- stop: () => {
85
- stopped = true
86
- if (timeout) {
87
- clearTimeout(timeout)
88
- timeout = undefined
89
- }
90
- watcher?.close()
91
- unsubscribeSignal()
92
- },
93
- }
94
- }
@@ -1,311 +0,0 @@
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 { getHomeDir } from '../config/paths'
10
- import { TUI_THEME_COLORS } from './opencode-tui-colors'
11
- import { THEMES_A } from './opencode-themes-a'
12
- import { THEMES_B } from './opencode-themes-b'
13
- import {
14
- omarchyPaletteToThemeColors,
15
- readOmarchyPalette,
16
- type OmarchyPalette,
17
- } from './omarchy'
18
- import {
19
- colorSchemeFromColorFgbg,
20
- terminalPaletteToThemeColors,
21
- type TerminalPalette,
22
- } from './terminal-palette'
23
-
24
- export const DEFAULT_THEME_ID = 'rosepine'
25
- export const DEFAULT_COLOR_SCHEME: ThemeColorScheme = 'system'
26
- export const SYSTEM_THEME_ID = 'system'
27
-
28
- export interface ResolveThemeOptions {
29
- homeDir?: string
30
- omarchyPalette?: OmarchyPalette | null
31
- terminalPalette?: TerminalPalette | null
32
- }
33
-
34
- export const BUILTIN_THEMES: Record<string, DesktopTheme> = {
35
- ...THEMES_A,
36
- ...THEMES_B,
37
- }
38
-
39
- function clamp(value: number): number {
40
- return Math.max(0, Math.min(255, Math.round(value)))
41
- }
42
-
43
- function normalizeHex(color: string): string {
44
- const normalized = color.startsWith('#') ? color.slice(1) : color
45
-
46
- if (normalized.length === 3 || normalized.length === 4) {
47
- return `#${normalized
48
- .split('')
49
- .map(char => `${char}${char}`)
50
- .join('')}`
51
- }
52
-
53
- return color.startsWith('#') ? color : `#${color}`
54
- }
55
-
56
- function hexToRgb(hex: string) {
57
- const normalized = normalizeHex(hex).slice(1)
58
- const channel = (offset: number) => parseInt(normalized.slice(offset, offset + 2), 16)
59
-
60
- return {
61
- r: channel(0),
62
- g: channel(2),
63
- b: channel(4),
64
- }
65
- }
66
-
67
- function rgbToHex(r: number, g: number, b: number) {
68
- return `#${[r, g, b].map(channel => clamp(channel).toString(16).padStart(2, '0')).join('')}`
69
- }
70
-
71
- function luminance(color: string) {
72
- const { r, g, b } = hexToRgb(color)
73
- return 0.299 * r + 0.587 * g + 0.114 * b
74
- }
75
-
76
- function readableText(background: string) {
77
- return luminance(background) > 150 ? '#171717' : '#f5f5f5'
78
- }
79
-
80
- const EXACT_TUI_THEME_COLORS: Partial<Record<string, Record<'light' | 'dark', ThemeColors>>> =
81
- TUI_THEME_COLORS
82
-
83
- function mix(colorA: string, colorB: string, ratio: number) {
84
- const from = hexToRgb(colorA)
85
- const to = hexToRgb(colorB)
86
-
87
- return rgbToHex(
88
- from.r + (to.r - from.r) * ratio,
89
- from.g + (to.g - from.g) * ratio,
90
- from.b + (to.b - from.b) * ratio
91
- )
92
- }
93
-
94
- function aliasThemeID(themeId?: string) {
95
- if (themeId === 'rose-pine') {
96
- return 'rosepine'
97
- }
98
-
99
- if (themeId === 'opencode-dark' || themeId === 'opencode-light') {
100
- return 'opencode'
101
- }
102
-
103
- return themeId
104
- }
105
-
106
- export function getSystemColorScheme(): 'light' | 'dark' {
107
- const envOverride = process.env.MUX_SESH_COLOR_SCHEME
108
- if (envOverride === 'light' || envOverride === 'dark') {
109
- return envOverride
110
- }
111
-
112
- const detected = colorSchemeFromColorFgbg(process.env.COLORFGBG)
113
- if (detected) {
114
- return detected
115
- }
116
-
117
- return 'dark'
118
- }
119
-
120
- function themeFromDefinition(id: string, definition: ThemeDefinition): DesktopTheme {
121
- return {
122
- id,
123
- name: definition.name ?? id,
124
- light: definition.light,
125
- dark: definition.dark,
126
- }
127
- }
128
-
129
- function pickVariant(
130
- theme: DesktopTheme,
131
- colorScheme: ThemeColorScheme
132
- ): { mode: 'light' | 'dark'; variant: ThemeVariant } {
133
- const mode = colorScheme === 'system' ? getSystemColorScheme() : colorScheme
134
- return {
135
- mode,
136
- variant: mode === 'light' ? theme.light : theme.dark,
137
- }
138
- }
139
-
140
- function resolveVariantTheme(theme: DesktopTheme, mode: 'light' | 'dark'): ThemeColors {
141
- const exactTheme = EXACT_TUI_THEME_COLORS[theme.id]?.[mode]
142
- if (exactTheme) {
143
- return exactTheme
144
- }
145
-
146
- const variant = mode === 'light' ? theme.light : theme.dark
147
- const palette = variant.palette
148
- const overrides = variant.overrides ?? {}
149
- const background = palette.neutral
150
- const ink = palette.ink
151
- const surface = overrides['surface-base'] ?? mix(background, ink, mode === 'dark' ? 0.08 : 0.035)
152
- const surfaceAlt =
153
- overrides['surface-raised-base'] ??
154
- overrides['surface-base-hover'] ??
155
- mix(background, ink, mode === 'dark' ? 0.13 : 0.06)
156
- const surfaceModal =
157
- overrides['surface-raised-stronger-non-alpha'] ??
158
- overrides['surface-raised-stronger'] ??
159
- overrides['surface-raised-base'] ??
160
- surface
161
- const borderMuted =
162
- overrides['border-weaker-base'] ?? mix(background, ink, mode === 'dark' ? 0.08 : 0.06)
163
- const border =
164
- overrides['border-weak-base'] ?? mix(background, ink, mode === 'dark' ? 0.16 : 0.12)
165
- const textMuted = overrides['text-base'] ?? mix(ink, background, mode === 'dark' ? 0.38 : 0.5)
166
- const textSubtle = overrides['text-weak'] ?? mix(ink, background, mode === 'dark' ? 0.55 : 0.66)
167
- const primary = palette.primary
168
- const secondary =
169
- overrides['markdown-heading'] ??
170
- overrides['syntax-constant'] ??
171
- palette.accent ??
172
- palette.primary
173
- const accent = overrides['markdown-link-text'] ?? palette.accent ?? palette.info
174
- const action = overrides['markdown-link-text'] ?? palette.info
175
- const fileTree = overrides['markdown-link'] ?? palette.info
176
- const program = overrides['markdown-code'] ?? palette.warning
177
- const separator = overrides['markdown-horizontal-rule'] ?? borderMuted
178
- const dangerSurface =
179
- overrides['surface-critical-base'] ??
180
- mix(background, palette.error, mode === 'dark' ? 0.2 : 0.12)
181
- const selection = palette.primary
182
-
183
- return {
184
- background,
185
- surface,
186
- surfaceAlt,
187
- surfaceModal,
188
- overlay: mix(background, ink, mode === 'dark' ? 0.2 : 0.04),
189
- border,
190
- borderMuted,
191
- text: overrides['text-strong'] ?? overrides['markdown-text'] ?? ink,
192
- textMuted,
193
- textSubtle,
194
- primary,
195
- secondary,
196
- accent,
197
- active: palette.success,
198
- inactive: textSubtle,
199
- key: palette.warning,
200
- action,
201
- separator,
202
- program,
203
- fileTree,
204
- danger: palette.error,
205
- dangerSurface,
206
- selection,
207
- selectionText: readableText(selection),
208
- }
209
- }
210
-
211
- export function resolveTheme(
212
- themeId?: string,
213
- customThemes: Record<string, ThemeDefinition> = {},
214
- colorScheme: ThemeColorScheme = DEFAULT_COLOR_SCHEME,
215
- options: ResolveThemeOptions = {}
216
- ) {
217
- const customCatalog = Object.fromEntries(
218
- Object.entries(customThemes).map(([id, definition]) => [
219
- id,
220
- themeFromDefinition(id, definition),
221
- ])
222
- )
223
- const catalog = {
224
- ...BUILTIN_THEMES,
225
- ...customCatalog,
226
- }
227
- const normalizedID = aliasThemeID(themeId)
228
-
229
- if (normalizedID === SYSTEM_THEME_ID) {
230
- const palette =
231
- options.omarchyPalette !== undefined
232
- ? options.omarchyPalette
233
- : readOmarchyPalette(options.homeDir ?? getHomeDir())
234
-
235
- if (palette) {
236
- const mode = colorScheme === 'system' ? palette.mode : colorScheme
237
- return {
238
- id: SYSTEM_THEME_ID,
239
- name: 'System',
240
- mode,
241
- colors: omarchyPaletteToThemeColors(palette),
242
- catalog,
243
- }
244
- }
245
-
246
- if (options.terminalPalette) {
247
- const mode = colorScheme === 'system' ? options.terminalPalette.mode : colorScheme
248
- return {
249
- id: SYSTEM_THEME_ID,
250
- name: 'System',
251
- mode,
252
- colors: terminalPaletteToThemeColors(options.terminalPalette),
253
- catalog,
254
- }
255
- }
256
- }
257
-
258
- const id = normalizedID && catalog[normalizedID] ? normalizedID : DEFAULT_THEME_ID
259
- const theme = catalog[id] ?? BUILTIN_THEMES[DEFAULT_THEME_ID]
260
- const { mode } = pickVariant(theme, colorScheme)
261
-
262
- return {
263
- id,
264
- name: theme.name,
265
- mode,
266
- colors: resolveVariantTheme(theme, mode),
267
- catalog,
268
- }
269
- }
270
-
271
- export function getPanelStyle(theme: ThemeColors, width: 'split' | 'full' = 'split') {
272
- return {
273
- border: false,
274
- backgroundColor: theme.surface,
275
- paddingTop: 0.4,
276
- paddingBottom: 0.4,
277
- paddingLeft: 1,
278
- paddingRight: 1,
279
- width: width === 'full' ? ('100%' as const) : ('50%' as const),
280
- height: '100%' as const,
281
- }
282
- }
283
-
284
- export function getDetailPanelStyle(theme: ThemeColors) {
285
- return {
286
- ...getPanelStyle(theme, 'split'),
287
- backgroundColor: theme.surface,
288
- }
289
- }
290
-
291
- export function getModalStyle(theme: ThemeColors, columns: number, preferredWidth = 76) {
292
- return {
293
- width: Math.max(48, Math.min(columns - 8, preferredWidth)),
294
- backgroundColor: theme.surfaceModal,
295
- paddingTop: 1,
296
- paddingBottom: 1,
297
- paddingLeft: 2,
298
- paddingRight: 2,
299
- flexDirection: 'column' as const,
300
- }
301
- }
302
-
303
- const ThemeContext = createContext<ThemeColors>(resolveTheme(DEFAULT_THEME_ID, {}, 'dark').colors)
304
-
305
- export function ThemeProvider(props: { theme: ThemeColors; children: ReactNode }) {
306
- return <ThemeContext.Provider value={props.theme}>{props.children}</ThemeContext.Provider>
307
- }
308
-
309
- export function useTheme(): ThemeColors {
310
- return useContext(ThemeContext)
311
- }
@@ -1,145 +0,0 @@
1
- import { spawn } from 'bun'
2
- import { sanitizeTmuxSessionName } from './helpers'
3
-
4
- type SpawnOptions = Parameters<typeof spawn>[1]
5
-
6
- export interface CreateTmuxSessionOptions {
7
- startupCommand?: string
8
- }
9
-
10
- async function isTmuxRunning(): Promise<boolean> {
11
- const proc = spawn(['pgrep', 'tmux'])
12
- await proc.exited
13
- return proc.exitCode === 0
14
- }
15
-
16
- async function tmuxSessionExists(sessionName: string): Promise<boolean> {
17
- const proc = spawn(['tmux', 'has-session', `-t=${sessionName}`])
18
- await proc.exited
19
- return proc.exitCode === 0
20
- }
21
-
22
- async function switchClient(sessionName: string): Promise<void> {
23
- await runTmuxCommand(
24
- ['tmux', 'switch-client', '-t', sessionName],
25
- `Failed to switch to tmux session '${sessionName}'`
26
- )
27
- }
28
-
29
- async function runTmuxCommand(
30
- command: string[],
31
- errorMessage: string,
32
- options?: SpawnOptions
33
- ): Promise<void> {
34
- const proc = spawn(command, options)
35
- const stderrPromise =
36
- proc.stderr instanceof ReadableStream ? new Response(proc.stderr).text() : Promise.resolve('')
37
- await proc.exited
38
- const stderr = (await stderrPromise).trim()
39
-
40
- if (proc.exitCode !== 0) {
41
- throw new Error(stderr ? `${errorMessage}: ${stderr}` : errorMessage)
42
- }
43
- }
44
-
45
- async function openTmuxSession(sessionName: string): Promise<void> {
46
- if (process.env.TMUX) {
47
- await switchClient(sessionName)
48
- return
49
- }
50
-
51
- await runTmuxCommand(
52
- ['tmux', 'attach-session', '-t', sessionName],
53
- `Failed to attach tmux session '${sessionName}'`,
54
- {
55
- stdin: 'inherit',
56
- stdout: 'inherit',
57
- stderr: 'inherit',
58
- }
59
- )
60
- }
61
-
62
- export async function createTmuxSession(
63
- name: string,
64
- path: string,
65
- options: CreateTmuxSessionOptions = {}
66
- ): Promise<void> {
67
- const sessionName = sanitizeTmuxSessionName(name)
68
- const insideTmux = !!process.env.TMUX
69
-
70
- if (!insideTmux && !(await isTmuxRunning())) {
71
- const command = ['tmux', 'new-session', '-s', sessionName, '-c', path]
72
- if (options.startupCommand) {
73
- command.push(options.startupCommand)
74
- }
75
-
76
- await runTmuxCommand(command, `Failed to create tmux session '${sessionName}'`, {
77
- stdin: 'inherit',
78
- stdout: 'inherit',
79
- stderr: 'inherit',
80
- })
81
- return
82
- }
83
-
84
- if (!(await tmuxSessionExists(sessionName))) {
85
- await runTmuxCommand(
86
- ['tmux', 'new-session', '-d', '-s', sessionName, '-c', path],
87
- `Failed to create tmux session '${sessionName}'`
88
- )
89
-
90
- if (options.startupCommand) {
91
- await runTmuxCommand(
92
- ['tmux', 'send-keys', '-t', sessionName, options.startupCommand, 'Enter'],
93
- `Failed to run startup command for tmux session '${sessionName}'`
94
- )
95
- }
96
- }
97
-
98
- await openTmuxSession(sessionName)
99
- }
100
-
101
- export async function createNamedTmuxSession(name: string): Promise<void> {
102
- const sessionName = sanitizeTmuxSessionName(name)
103
- const insideTmux = !!process.env.TMUX
104
-
105
- if (!insideTmux && !(await isTmuxRunning())) {
106
- await runTmuxCommand(
107
- ['tmux', 'new-session', '-s', sessionName],
108
- `Failed to create tmux session '${sessionName}'`,
109
- {
110
- stdin: 'inherit',
111
- stdout: 'inherit',
112
- stderr: 'inherit',
113
- }
114
- )
115
- return
116
- }
117
-
118
- if (!(await tmuxSessionExists(sessionName))) {
119
- await runTmuxCommand(
120
- ['tmux', 'new-session', '-d', '-s', sessionName],
121
- `Failed to create tmux session '${sessionName}'`
122
- )
123
- }
124
-
125
- await openTmuxSession(sessionName)
126
- }
127
-
128
- export async function switchTmuxSession(name: string): Promise<void> {
129
- await openTmuxSession(name)
130
- }
131
-
132
- export async function killTmuxSession(name: string): Promise<void> {
133
- await runTmuxCommand(
134
- ['tmux', 'kill-session', '-t', name],
135
- `Failed to kill tmux session '${name}'`
136
- )
137
- }
138
-
139
- export async function renameTmuxSession(oldName: string, newName: string): Promise<void> {
140
- const sanitizedName = sanitizeTmuxSessionName(newName)
141
- await runTmuxCommand(
142
- ['tmux', 'rename-session', '-t', oldName, sanitizedName],
143
- `Failed to rename tmux session '${oldName}'`
144
- )
145
- }