mux-sesh 1.9.9 → 1.10.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 +2 -1
- package/package.json +2 -2
- package/src/app/commands.ts +4 -0
- package/src/app/controller.ts +22 -3
- package/src/app/effects.ts +69 -0
- package/src/app/handlers.ts +2 -0
- package/src/app/keyboard.ts +2 -0
- package/src/app/modal-keyboard.ts +20 -10
- package/src/app/modal-state.ts +3 -0
- package/src/app/modals.ts +1 -1
- package/src/app/screen.tsx +10 -2
- package/src/index.tsx +2 -0
- package/src/settings.ts +25 -14
- package/src/styles/omarchy.ts +295 -0
- package/src/styles/terminal-palette.ts +156 -0
- package/src/styles/theme-follow.ts +94 -0
- package/src/styles/theme.tsx +51 -20
- package/src/ui/CommandsModal.tsx +19 -2
- package/src/ui/VersionBadge.tsx +16 -3
package/README.md
CHANGED
|
@@ -105,7 +105,7 @@ Default mode is `vim`.
|
|
|
105
105
|
| `n` | New session |
|
|
106
106
|
| `d` | Kill selected session |
|
|
107
107
|
| `1-9` | Quick select |
|
|
108
|
-
| `Ctrl+P` | Open command palette
|
|
108
|
+
| `Ctrl+P` | Open command palette. Type `theme` for the theme picker |
|
|
109
109
|
| `q` / `Esc` | Quit |
|
|
110
110
|
|
|
111
111
|
With the default prefix key, secondary actions live behind `ctrl+x`:
|
|
@@ -137,6 +137,7 @@ Uncaught process-level failures restore the terminal first, then print the diagn
|
|
|
137
137
|
## Docs
|
|
138
138
|
|
|
139
139
|
- [Configuration](docs/configuration.md)
|
|
140
|
+
- [Themes](docs/themes.md)
|
|
140
141
|
- [Keybindings](docs/keybindings.md)
|
|
141
142
|
- [Workflows](docs/workflows.md)
|
|
142
143
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "mux-sesh",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.10.0",
|
|
5
5
|
"description": "An OpenTUI manager for tmux sessions and Herdr workspaces with fuzzy project search",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"packageManager": "bun@1.3.14",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"tsconfig.json"
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
|
-
"dev": "bun run src/index.tsx",
|
|
17
|
+
"dev": "MUX_SESH_DEV=1 bun run src/index.tsx",
|
|
18
18
|
"build": "bun build src/index.tsx --compile --outfile dist/mux-sesh",
|
|
19
19
|
"start": "bun run src/index.tsx",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
package/src/app/commands.ts
CHANGED
|
@@ -15,6 +15,7 @@ interface ExecuteCommandContext {
|
|
|
15
15
|
closeModal: () => void
|
|
16
16
|
openRenameModal: (item: Item) => void
|
|
17
17
|
openSettingsModal: () => void
|
|
18
|
+
openSettingOptions: (field: 'theme') => void
|
|
18
19
|
requestKillSession: (item: Item) => void
|
|
19
20
|
togglePinnedSession: (sessionName: string) => Promise<void>
|
|
20
21
|
setAppMode: (mode: AppMode) => void
|
|
@@ -54,6 +55,9 @@ export async function executeCommand(commandID: CommandId, ctx: ExecuteCommandCo
|
|
|
54
55
|
case 'open-settings':
|
|
55
56
|
ctx.openSettingsModal()
|
|
56
57
|
return
|
|
58
|
+
case 'open-themes':
|
|
59
|
+
ctx.openSettingOptions('theme')
|
|
60
|
+
return
|
|
57
61
|
case 'view-projects':
|
|
58
62
|
ctx.closeModal()
|
|
59
63
|
ctx.setViewMode(ViewMode.Projects)
|
package/src/app/controller.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef } from 'react'
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
2
|
import { useAppCoreState } from './core-state'
|
|
3
3
|
import { useAutoUpdateScheduler, useAppBehaviors } from './effects'
|
|
4
4
|
import { createAppControls } from './controls'
|
|
@@ -8,9 +8,10 @@ import { useAppModalState } from './modal-state'
|
|
|
8
8
|
import { createAppRuntime } from './runtime'
|
|
9
9
|
import { createAppHandlers, handleKillSessionWithFeedback } from './handlers'
|
|
10
10
|
import { useAppStartup } from './state'
|
|
11
|
-
import { getConfigPath, saveConfig } from '../config'
|
|
11
|
+
import { getConfigPath, getHomeDir, saveConfig } from '../config'
|
|
12
12
|
import { getOpencodeSessionStats } from '../opencode'
|
|
13
13
|
import { resolveTheme } from '../styles/theme'
|
|
14
|
+
import type { TerminalPalette } from '../styles/terminal-palette'
|
|
14
15
|
import { useTerminalSize } from '../util/terminal'
|
|
15
16
|
import { mark, measure } from '../util/perf'
|
|
16
17
|
import { getSettingEditorTitle, isOptionSetting } from '../settings'
|
|
@@ -77,6 +78,8 @@ export function useAppController() {
|
|
|
77
78
|
settingOptionsCursor,
|
|
78
79
|
setSettingOptionsCursor,
|
|
79
80
|
settingOptionsSearchQuery,
|
|
81
|
+
themePreviewId,
|
|
82
|
+
setThemePreviewId,
|
|
80
83
|
setSettingOptionsSearchQuery,
|
|
81
84
|
settingEditorValue,
|
|
82
85
|
setSettingEditorValue,
|
|
@@ -91,7 +94,16 @@ export function useAppController() {
|
|
|
91
94
|
|
|
92
95
|
const { columns, rows } = useTerminalSize()
|
|
93
96
|
const configPath = getConfigPath()
|
|
94
|
-
const
|
|
97
|
+
const homeDir = getHomeDir()
|
|
98
|
+
const [systemThemeEpoch, setSystemThemeEpoch] = useState(0)
|
|
99
|
+
const [terminalPalette, setTerminalPalette] = useState<TerminalPalette | null>(null)
|
|
100
|
+
const resolvedTheme = resolveTheme(
|
|
101
|
+
themePreviewId ?? config?.theme,
|
|
102
|
+
config?.themes,
|
|
103
|
+
config?.colorScheme,
|
|
104
|
+
{ homeDir, terminalPalette }
|
|
105
|
+
)
|
|
106
|
+
void systemThemeEpoch
|
|
95
107
|
const theme = resolvedTheme.colors
|
|
96
108
|
const { filteredSettingsEntries, filteredSettingOptions } = getSettingsState(
|
|
97
109
|
config,
|
|
@@ -227,6 +239,7 @@ export function useAppController() {
|
|
|
227
239
|
closeModal,
|
|
228
240
|
openRenameModal,
|
|
229
241
|
openSettingsModal,
|
|
242
|
+
openSettingOptions,
|
|
230
243
|
requestKillSession,
|
|
231
244
|
setAppMode,
|
|
232
245
|
setViewMode,
|
|
@@ -281,6 +294,7 @@ export function useAppController() {
|
|
|
281
294
|
handleNewSessionSubmit,
|
|
282
295
|
isOptionSetting,
|
|
283
296
|
openSettingOptions,
|
|
297
|
+
previewThemeOption: setThemePreviewId,
|
|
284
298
|
openSettingEditor,
|
|
285
299
|
closeModal,
|
|
286
300
|
clearPendingKill,
|
|
@@ -346,6 +360,11 @@ export function useAppController() {
|
|
|
346
360
|
setUpdatedVersion,
|
|
347
361
|
setToastMessage,
|
|
348
362
|
setToastVisible,
|
|
363
|
+
homeDir,
|
|
364
|
+
onSystemThemeRefresh: () => {
|
|
365
|
+
setSystemThemeEpoch(current => current + 1)
|
|
366
|
+
},
|
|
367
|
+
onTerminalPalette: setTerminalPalette,
|
|
349
368
|
})
|
|
350
369
|
|
|
351
370
|
return {
|
package/src/app/effects.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef, type Dispatch, type MutableRefObject, type SetStateAction } from 'react'
|
|
2
|
+
import { useRenderer } from '@opentui/react'
|
|
3
|
+
import type { TerminalColors } from '@opentui/core'
|
|
2
4
|
import { isOpencodeSessionItem } from '../opencode/session-name'
|
|
3
5
|
import { checkAndUpdate, updateEvents } from '../update'
|
|
4
6
|
import { showTemporaryToast } from './notifications'
|
|
@@ -13,6 +15,9 @@ import {
|
|
|
13
15
|
loadSessionItems,
|
|
14
16
|
reuseSessionItemIdentities,
|
|
15
17
|
} from './data'
|
|
18
|
+
import { SYSTEM_THEME_ID } from '../styles/theme'
|
|
19
|
+
import { subscribeThemeFollow } from '../styles/theme-follow'
|
|
20
|
+
import { terminalColorsToPalette, type TerminalPalette } from '../styles/terminal-palette'
|
|
16
21
|
import { AppMode, ViewMode, type Config, type Item } from '../types'
|
|
17
22
|
import type { MultiplexerBackend } from '../multiplexer'
|
|
18
23
|
import { getItemKey } from '../multiplexer/items'
|
|
@@ -22,6 +27,65 @@ import { measure } from '../util/perf'
|
|
|
22
27
|
|
|
23
28
|
const FILE_SEARCH_DEBOUNCE_MS = 120
|
|
24
29
|
|
|
30
|
+
export function useSystemThemeFollow(
|
|
31
|
+
themeId: string | undefined,
|
|
32
|
+
homeDir: string,
|
|
33
|
+
onRefresh: () => void
|
|
34
|
+
) {
|
|
35
|
+
const onRefreshRef = useRef(onRefresh)
|
|
36
|
+
onRefreshRef.current = onRefresh
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (themeId !== SYSTEM_THEME_ID) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const subscription = subscribeThemeFollow(homeDir, {
|
|
44
|
+
onRefresh: () => {
|
|
45
|
+
onRefreshRef.current()
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return () => {
|
|
50
|
+
subscription.stop()
|
|
51
|
+
}
|
|
52
|
+
}, [homeDir, themeId])
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function useTerminalPalette(
|
|
56
|
+
themeId: string | undefined,
|
|
57
|
+
onPalette: (palette: TerminalPalette | null) => void
|
|
58
|
+
) {
|
|
59
|
+
const renderer = useRenderer()
|
|
60
|
+
const onPaletteRef = useRef(onPalette)
|
|
61
|
+
onPaletteRef.current = onPalette
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (themeId !== SYSTEM_THEME_ID) {
|
|
65
|
+
onPaletteRef.current(null)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let cancelled = false
|
|
70
|
+
|
|
71
|
+
const publish = (colors: TerminalColors): void => {
|
|
72
|
+
if (!cancelled) {
|
|
73
|
+
onPaletteRef.current(terminalColorsToPalette(colors))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
void renderer.getPalette().then(colors => {
|
|
78
|
+
publish(colors)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
renderer.on('palette', publish)
|
|
82
|
+
return () => {
|
|
83
|
+
cancelled = true
|
|
84
|
+
renderer.off('palette', publish)
|
|
85
|
+
}
|
|
86
|
+
}, [renderer, themeId])
|
|
87
|
+
}
|
|
88
|
+
|
|
25
89
|
export function useAutoUpdateScheduler(
|
|
26
90
|
config: Config | null,
|
|
27
91
|
hasScheduledAutoUpdateRef: MutableRefObject<boolean>
|
|
@@ -495,9 +559,14 @@ interface UseAppBehaviorsOptions {
|
|
|
495
559
|
setUpdatedVersion: Dispatch<SetStateAction<string | null>>
|
|
496
560
|
setToastMessage: Dispatch<SetStateAction<string>>
|
|
497
561
|
setToastVisible: Dispatch<SetStateAction<boolean>>
|
|
562
|
+
homeDir: string
|
|
563
|
+
onSystemThemeRefresh: () => void
|
|
564
|
+
onTerminalPalette: (palette: TerminalPalette | null) => void
|
|
498
565
|
}
|
|
499
566
|
|
|
500
567
|
export function useAppBehaviors(options: UseAppBehaviorsOptions) {
|
|
568
|
+
useSystemThemeFollow(options.config?.theme, options.homeDir, options.onSystemThemeRefresh)
|
|
569
|
+
useTerminalPalette(options.config?.theme, options.onTerminalPalette)
|
|
501
570
|
useUpdateEventToasts(options.setUpdatedVersion, options.setToastMessage, options.setToastVisible)
|
|
502
571
|
useNormalModeSessionReset(
|
|
503
572
|
options.appMode,
|
package/src/app/handlers.ts
CHANGED
|
@@ -246,6 +246,7 @@ interface CreateAppHandlersOptions extends SharedHandlerOptions {
|
|
|
246
246
|
closeModal: () => void
|
|
247
247
|
openRenameModal: (item: Item) => void
|
|
248
248
|
openSettingsModal: () => void
|
|
249
|
+
openSettingOptions: (field: 'theme') => void
|
|
249
250
|
requestKillSession: (item: Item) => void
|
|
250
251
|
setAppMode: (mode: AppMode) => void
|
|
251
252
|
setViewMode: (mode: ViewMode) => void
|
|
@@ -370,6 +371,7 @@ export function createAppHandlers(options: CreateAppHandlersOptions) {
|
|
|
370
371
|
closeModal: options.closeModal,
|
|
371
372
|
openRenameModal: options.openRenameModal,
|
|
372
373
|
openSettingsModal: options.openSettingsModal,
|
|
374
|
+
openSettingOptions: options.openSettingOptions,
|
|
373
375
|
requestKillSession: options.requestKillSession,
|
|
374
376
|
togglePinnedSession: handleTogglePinnedSessionWrapper,
|
|
375
377
|
setAppMode: options.setAppMode,
|
package/src/app/keyboard.ts
CHANGED
|
@@ -48,6 +48,7 @@ interface UseAppKeyboardOptions {
|
|
|
48
48
|
handleNewSessionSubmit: () => Promise<void>
|
|
49
49
|
isOptionSetting: (field: SettingsFieldId) => boolean
|
|
50
50
|
openSettingOptions: (field: SettingsFieldId) => void
|
|
51
|
+
previewThemeOption?: (value: string | null) => void
|
|
51
52
|
openSettingEditor: (field: SettingsFieldId) => void
|
|
52
53
|
closeModal: () => void
|
|
53
54
|
clearPendingKill: () => void
|
|
@@ -133,6 +134,7 @@ export function useAppKeyboard(options: UseAppKeyboardOptions) {
|
|
|
133
134
|
setSettingOptionsCursor: options.setSettingOptionsCursor,
|
|
134
135
|
closeModal: options.closeModal,
|
|
135
136
|
openSettingOptions: options.openSettingOptions,
|
|
137
|
+
previewThemeOption: options.previewThemeOption,
|
|
136
138
|
openSettingEditor: options.openSettingEditor,
|
|
137
139
|
isOptionSetting: options.isOptionSetting,
|
|
138
140
|
setModalState: options.setModalState,
|
|
@@ -16,6 +16,7 @@ interface ModalKeyboardContext {
|
|
|
16
16
|
setSettingOptionsCursor: (cursor: (current: number) => number) => void
|
|
17
17
|
closeModal: () => void
|
|
18
18
|
openSettingOptions: (field: SettingsEntry['id']) => void
|
|
19
|
+
previewThemeOption?: (value: string | null) => void
|
|
19
20
|
openSettingEditor: (field: SettingsEntry['id']) => void
|
|
20
21
|
isOptionSetting: (field: SettingsEntry['id']) => boolean
|
|
21
22
|
setModalState: (state: ModalState) => void
|
|
@@ -93,22 +94,31 @@ export function handleModalKeyboard(key: KeyboardInput, ctx: ModalKeyboardContex
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
if (ctx.modalState?.type === 'setting-options') {
|
|
97
|
+
const previewIfTheme = (index: number) => {
|
|
98
|
+
if (ctx.modalState?.type !== 'setting-options' || ctx.modalState.field !== 'theme') return
|
|
99
|
+
ctx.previewThemeOption?.(ctx.filteredSettingOptions[index]?.value ?? null)
|
|
100
|
+
}
|
|
101
|
+
|
|
96
102
|
if (key.name === 'escape') {
|
|
97
|
-
ctx.
|
|
103
|
+
ctx.previewThemeOption?.(null)
|
|
104
|
+
if (ctx.modalState.openedFrom === 'commands') {
|
|
105
|
+
ctx.closeModal()
|
|
106
|
+
} else {
|
|
107
|
+
ctx.setModalState({ type: 'settings' })
|
|
108
|
+
}
|
|
98
109
|
} else if (key.name === 'down' || key.name === 'j') {
|
|
99
|
-
ctx.
|
|
100
|
-
|
|
101
|
-
)
|
|
110
|
+
const next = clampCursorIndex(ctx.filteredSettingOptions.length, ctx.settingOptionsCursor + 1)
|
|
111
|
+
ctx.setSettingOptionsCursor(() => next)
|
|
112
|
+
previewIfTheme(next)
|
|
102
113
|
} else if (key.name === 'up' || key.name === 'k') {
|
|
103
|
-
ctx.
|
|
104
|
-
|
|
105
|
-
)
|
|
114
|
+
const next = clampCursorIndex(ctx.filteredSettingOptions.length, ctx.settingOptionsCursor - 1)
|
|
115
|
+
ctx.setSettingOptionsCursor(() => next)
|
|
116
|
+
previewIfTheme(next)
|
|
106
117
|
} else if (key.name === 'return') {
|
|
107
118
|
const option = ctx.filteredSettingOptions[ctx.settingOptionsCursor]
|
|
108
|
-
if (!option)
|
|
109
|
-
return true
|
|
110
|
-
}
|
|
119
|
+
if (!option) return true
|
|
111
120
|
void ctx.handleSettingOptionSubmit(ctx.modalState.field, option.value)
|
|
121
|
+
ctx.previewThemeOption?.(null)
|
|
112
122
|
}
|
|
113
123
|
return true
|
|
114
124
|
}
|
package/src/app/modal-state.ts
CHANGED
|
@@ -13,6 +13,7 @@ export function useAppModalState() {
|
|
|
13
13
|
const [settingOptionsSearchQuery, setSettingOptionsSearchQuery] = useState('')
|
|
14
14
|
const [settingEditorValue, setSettingEditorValue] = useState('')
|
|
15
15
|
const [settingEditorError, setSettingEditorError] = useState('')
|
|
16
|
+
const [themePreviewId, setThemePreviewId] = useState<string | null>(null)
|
|
16
17
|
|
|
17
18
|
const modalTextareaRef = useRef<TextareaRenderable | null>(null)
|
|
18
19
|
const commandsSearchTextareaRef = useRef<TextareaRenderable | null>(null)
|
|
@@ -41,6 +42,8 @@ export function useAppModalState() {
|
|
|
41
42
|
setSettingEditorValue,
|
|
42
43
|
settingEditorError,
|
|
43
44
|
setSettingEditorError,
|
|
45
|
+
themePreviewId,
|
|
46
|
+
setThemePreviewId,
|
|
44
47
|
modalTextareaRef,
|
|
45
48
|
commandsSearchTextareaRef,
|
|
46
49
|
settingsSearchTextareaRef,
|
package/src/app/modals.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type ModalState =
|
|
|
6
6
|
| { type: 'rename'; target: string }
|
|
7
7
|
| { type: 'commands' }
|
|
8
8
|
| { type: 'settings' }
|
|
9
|
-
| { type: 'setting-options'; field: SettingsFieldId }
|
|
9
|
+
| { type: 'setting-options'; field: SettingsFieldId; openedFrom?: 'commands' | 'settings' }
|
|
10
10
|
| { type: 'setting-editor'; field: SettingsFieldId }
|
|
11
11
|
| null
|
|
12
12
|
|
package/src/app/screen.tsx
CHANGED
|
@@ -81,7 +81,11 @@ export function AppScreen({
|
|
|
81
81
|
const totalSessions = sessionItems.filter(item => item.isSession).length
|
|
82
82
|
const activeSessions = items.filter(item => item.isSession && item.isAttached).length
|
|
83
83
|
const maxVisibleItems = Math.max(8, rows - (appMode === AppMode.NewSession ? 10 : 12))
|
|
84
|
-
const versionLabel = formatVersionBadge(
|
|
84
|
+
const versionLabel = formatVersionBadge(
|
|
85
|
+
CURRENT_VERSION,
|
|
86
|
+
updatedVersion,
|
|
87
|
+
process.env.MUX_SESH_DEV === '1'
|
|
88
|
+
)
|
|
85
89
|
const selectedAgentSession = agentSessions[agentCursor]
|
|
86
90
|
const showOpencodeStats =
|
|
87
91
|
viewMode === ViewMode.Sessions &&
|
|
@@ -225,7 +229,11 @@ export function AppScreen({
|
|
|
225
229
|
)}
|
|
226
230
|
|
|
227
231
|
<Toast message={toastMessage} visible={toastVisible} />
|
|
228
|
-
<VersionBadge
|
|
232
|
+
<VersionBadge
|
|
233
|
+
currentVersion={CURRENT_VERSION}
|
|
234
|
+
updatedVersion={updatedVersion}
|
|
235
|
+
isDev={process.env.MUX_SESH_DEV === '1'}
|
|
236
|
+
/>
|
|
229
237
|
</box>
|
|
230
238
|
</>
|
|
231
239
|
)
|
package/src/index.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createCliRenderer } from '@opentui/core'
|
|
2
2
|
import { createRoot } from '@opentui/react'
|
|
3
3
|
import { App } from './app'
|
|
4
|
+
import { ignoreUnhandledThemeFollowSignal } from './styles/theme-follow'
|
|
4
5
|
import { initializeFatalErrorHandling, initializeShutdown, requestShutdown } from './util/shutdown'
|
|
5
6
|
|
|
6
7
|
initializeFatalErrorHandling()
|
|
8
|
+
ignoreUnhandledThemeFollowSignal()
|
|
7
9
|
|
|
8
10
|
const renderer = await createCliRenderer({
|
|
9
11
|
exitOnCtrlC: false,
|
package/src/settings.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { normalizeConfig, serializeConfig } from './config'
|
|
2
|
-
import { BUILTIN_THEMES } from './styles/theme'
|
|
2
|
+
import { BUILTIN_THEMES, DEFAULT_THEME_ID, SYSTEM_THEME_ID } from './styles/theme'
|
|
3
3
|
import type { Config, KeybindMode, SortOrder, ThemeColorScheme, ZoxideMode } from './types'
|
|
4
4
|
|
|
5
5
|
export type SettingsFieldId =
|
|
@@ -69,20 +69,31 @@ function formatJSON(value: unknown): string {
|
|
|
69
69
|
return JSON.stringify(value, null, 2)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export function getThemeOptions(): string[] {
|
|
73
|
-
|
|
74
|
-
if (left ===
|
|
75
|
-
if (right ===
|
|
72
|
+
export function getThemeOptions(config?: Config): string[] {
|
|
73
|
+
const builtin = Object.keys(BUILTIN_THEMES).sort((left, right) => {
|
|
74
|
+
if (left === DEFAULT_THEME_ID) return -1
|
|
75
|
+
if (right === DEFAULT_THEME_ID) return 1
|
|
76
76
|
return left.localeCompare(right)
|
|
77
77
|
})
|
|
78
|
+
const custom = Object.keys(config?.themes ?? {}).sort((left, right) => left.localeCompare(right))
|
|
79
|
+
return [SYSTEM_THEME_ID, ...builtin, ...custom]
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
function themeOptions(): SettingsOption[] {
|
|
81
|
-
return getThemeOptions().map(id =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
function themeOptions(config: Config): SettingsOption[] {
|
|
83
|
+
return getThemeOptions(config).map(id => {
|
|
84
|
+
if (id === SYSTEM_THEME_ID) {
|
|
85
|
+
return {
|
|
86
|
+
value: id,
|
|
87
|
+
label: 'System',
|
|
88
|
+
description: 'Follow the desktop or terminal theme',
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
value: id,
|
|
93
|
+
label: config.themes?.[id]?.name ?? BUILTIN_THEMES[id]?.name ?? id,
|
|
94
|
+
description: id,
|
|
95
|
+
}
|
|
96
|
+
})
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
function choiceOptions(
|
|
@@ -117,10 +128,10 @@ const SETTINGS_FIELDS: readonly SettingsFieldDefinition[] = [
|
|
|
117
128
|
{
|
|
118
129
|
id: 'theme',
|
|
119
130
|
label: 'Theme',
|
|
120
|
-
hint: 'Built-in
|
|
131
|
+
hint: 'Built-in, custom, or system',
|
|
121
132
|
kind: 'options',
|
|
122
|
-
getValue: config => config.theme ??
|
|
123
|
-
getOptions:
|
|
133
|
+
getValue: config => config.theme ?? DEFAULT_THEME_ID,
|
|
134
|
+
getOptions: config => themeOptions(config),
|
|
124
135
|
applyOption: (config, value) => ({
|
|
125
136
|
...config,
|
|
126
137
|
theme: value,
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import type { ThemeColors } from '../types'
|
|
4
|
+
|
|
5
|
+
export const OMARCHY_STATE_DIR = ['.local', 'state', 'omarchy', 'current'] as const
|
|
6
|
+
|
|
7
|
+
export type OmarchyMode = 'light' | 'dark'
|
|
8
|
+
|
|
9
|
+
export interface OmarchyPalette {
|
|
10
|
+
mode: OmarchyMode
|
|
11
|
+
background: string
|
|
12
|
+
foreground: string
|
|
13
|
+
accent?: string
|
|
14
|
+
selection?: string
|
|
15
|
+
muted?: string
|
|
16
|
+
dark_background?: string
|
|
17
|
+
darker_background?: string
|
|
18
|
+
lighter_background?: string
|
|
19
|
+
dark_foreground?: string
|
|
20
|
+
light_foreground?: string
|
|
21
|
+
bright_foreground?: string
|
|
22
|
+
red?: string
|
|
23
|
+
yellow?: string
|
|
24
|
+
orange?: string
|
|
25
|
+
green?: string
|
|
26
|
+
cyan?: string
|
|
27
|
+
blue?: string
|
|
28
|
+
magenta?: string
|
|
29
|
+
brown?: string
|
|
30
|
+
bright_red?: string
|
|
31
|
+
bright_yellow?: string
|
|
32
|
+
bright_green?: string
|
|
33
|
+
bright_cyan?: string
|
|
34
|
+
bright_blue?: string
|
|
35
|
+
bright_magenta?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const COLOR_KEYS = [
|
|
39
|
+
'background',
|
|
40
|
+
'foreground',
|
|
41
|
+
'accent',
|
|
42
|
+
'selection',
|
|
43
|
+
'muted',
|
|
44
|
+
'dark_background',
|
|
45
|
+
'darker_background',
|
|
46
|
+
'lighter_background',
|
|
47
|
+
'dark_foreground',
|
|
48
|
+
'light_foreground',
|
|
49
|
+
'bright_foreground',
|
|
50
|
+
'red',
|
|
51
|
+
'yellow',
|
|
52
|
+
'orange',
|
|
53
|
+
'green',
|
|
54
|
+
'cyan',
|
|
55
|
+
'blue',
|
|
56
|
+
'magenta',
|
|
57
|
+
'brown',
|
|
58
|
+
'bright_red',
|
|
59
|
+
'bright_yellow',
|
|
60
|
+
'bright_green',
|
|
61
|
+
'bright_cyan',
|
|
62
|
+
'bright_blue',
|
|
63
|
+
'bright_magenta',
|
|
64
|
+
] as const
|
|
65
|
+
|
|
66
|
+
type OmarchyColorKey = (typeof COLOR_KEYS)[number]
|
|
67
|
+
|
|
68
|
+
const COLOR_KEY_SET = new Set<string>(COLOR_KEYS)
|
|
69
|
+
|
|
70
|
+
function isOmarchyColorKey(key: string): key is OmarchyColorKey {
|
|
71
|
+
return COLOR_KEY_SET.has(key)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function clamp(value: number): number {
|
|
75
|
+
return Math.max(0, Math.min(255, Math.round(value)))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function normalizeHex(color: string): string {
|
|
79
|
+
const normalized = color.startsWith('#') ? color.slice(1) : color
|
|
80
|
+
|
|
81
|
+
if (normalized.length === 3 || normalized.length === 4) {
|
|
82
|
+
return `#${normalized
|
|
83
|
+
.split('')
|
|
84
|
+
.map(char => `${char}${char}`)
|
|
85
|
+
.join('')}`
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return color.startsWith('#') ? color : `#${color}`
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function hexToRgb(hex: string): { r: number; g: number; b: number } {
|
|
92
|
+
const normalized = normalizeHex(hex).slice(1)
|
|
93
|
+
const channel = (offset: number) => parseInt(normalized.slice(offset, offset + 2), 16)
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
r: channel(0),
|
|
97
|
+
g: channel(2),
|
|
98
|
+
b: channel(4),
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function rgbToHex(r: number, g: number, b: number): string {
|
|
103
|
+
return `#${[r, g, b].map(channel => clamp(channel).toString(16).padStart(2, '0')).join('')}`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function luminance(color: string): number {
|
|
107
|
+
const { r, g, b } = hexToRgb(color)
|
|
108
|
+
return 0.299 * r + 0.587 * g + 0.114 * b
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function readableText(background: string): string {
|
|
112
|
+
return luminance(background) > 150 ? '#171717' : '#f5f5f5'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function mix(colorA: string, colorB: string, ratio: number): string {
|
|
116
|
+
const from = hexToRgb(colorA)
|
|
117
|
+
const to = hexToRgb(colorB)
|
|
118
|
+
|
|
119
|
+
return rgbToHex(
|
|
120
|
+
from.r + (to.r - from.r) * ratio,
|
|
121
|
+
from.g + (to.g - from.g) * ratio,
|
|
122
|
+
from.b + (to.b - from.b) * ratio
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function parseHexColor(value: string): string | null {
|
|
127
|
+
const unquoted = stripQuotes(value)
|
|
128
|
+
const hex = unquoted.startsWith('#') ? unquoted.slice(1) : unquoted
|
|
129
|
+
|
|
130
|
+
if (!/^[0-9a-fA-F]{3}$|^[0-9a-fA-F]{4}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/.test(hex)) {
|
|
131
|
+
return null
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return normalizeHex(`#${hex}`)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function stripQuotes(value: string): string {
|
|
138
|
+
if (
|
|
139
|
+
(value.startsWith('"') && value.endsWith('"') && value.length >= 2) ||
|
|
140
|
+
(value.startsWith("'") && value.endsWith("'") && value.length >= 2)
|
|
141
|
+
) {
|
|
142
|
+
return value.slice(1, -1)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return value
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function parseMode(value: string): OmarchyMode | null {
|
|
149
|
+
const normalized = stripQuotes(value).toLowerCase()
|
|
150
|
+
return normalized === 'light' || normalized === 'dark' ? normalized : null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function getOmarchyThemeNamePath(homeDir: string): string {
|
|
154
|
+
return join(homeDir, ...OMARCHY_STATE_DIR, 'theme.name')
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function getOmarchyColorsPath(homeDir: string): string {
|
|
158
|
+
return join(homeDir, ...OMARCHY_STATE_DIR, 'theme', 'colors.toml')
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function isOmarchyPresent(homeDir: string): boolean {
|
|
162
|
+
return existsSync(getOmarchyColorsPath(homeDir))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function parseOmarchyColorsToml(text: string): OmarchyPalette | null {
|
|
166
|
+
const colors: Partial<Record<OmarchyColorKey, string>> = {}
|
|
167
|
+
let mode: OmarchyMode | null = null
|
|
168
|
+
let themeType: OmarchyMode | null = null
|
|
169
|
+
|
|
170
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
171
|
+
const line = rawLine.trim()
|
|
172
|
+
if (!line || line.startsWith('#')) {
|
|
173
|
+
continue
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const separator = line.indexOf('=')
|
|
177
|
+
if (separator === -1) {
|
|
178
|
+
continue
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const key = line.slice(0, separator).trim().toLowerCase()
|
|
182
|
+
const value = line.slice(separator + 1).trim()
|
|
183
|
+
|
|
184
|
+
if (key === 'mode') {
|
|
185
|
+
mode = parseMode(value) ?? mode
|
|
186
|
+
continue
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (key === 'theme_type') {
|
|
190
|
+
themeType = parseMode(value) ?? themeType
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!isOmarchyColorKey(key)) {
|
|
195
|
+
continue
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const color = parseHexColor(value)
|
|
199
|
+
if (!color) {
|
|
200
|
+
if (key === 'background' || key === 'foreground') {
|
|
201
|
+
return null
|
|
202
|
+
}
|
|
203
|
+
continue
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
colors[key] = color
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const background = colors.background
|
|
210
|
+
const foreground = colors.foreground
|
|
211
|
+
if (!background || !foreground) {
|
|
212
|
+
return null
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const resolvedMode = mode ?? themeType ?? (luminance(background) > 150 ? 'light' : 'dark')
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
mode: resolvedMode,
|
|
219
|
+
background,
|
|
220
|
+
foreground,
|
|
221
|
+
accent: colors.accent,
|
|
222
|
+
selection: colors.selection,
|
|
223
|
+
muted: colors.muted,
|
|
224
|
+
dark_background: colors.dark_background,
|
|
225
|
+
darker_background: colors.darker_background,
|
|
226
|
+
lighter_background: colors.lighter_background,
|
|
227
|
+
dark_foreground: colors.dark_foreground,
|
|
228
|
+
light_foreground: colors.light_foreground,
|
|
229
|
+
bright_foreground: colors.bright_foreground,
|
|
230
|
+
red: colors.red,
|
|
231
|
+
yellow: colors.yellow,
|
|
232
|
+
orange: colors.orange,
|
|
233
|
+
green: colors.green,
|
|
234
|
+
cyan: colors.cyan,
|
|
235
|
+
blue: colors.blue,
|
|
236
|
+
magenta: colors.magenta,
|
|
237
|
+
brown: colors.brown,
|
|
238
|
+
bright_red: colors.bright_red,
|
|
239
|
+
bright_yellow: colors.bright_yellow,
|
|
240
|
+
bright_green: colors.bright_green,
|
|
241
|
+
bright_cyan: colors.bright_cyan,
|
|
242
|
+
bright_blue: colors.bright_blue,
|
|
243
|
+
bright_magenta: colors.bright_magenta,
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function readOmarchyPalette(homeDir: string): OmarchyPalette | null {
|
|
248
|
+
try {
|
|
249
|
+
const colorsPath = getOmarchyColorsPath(homeDir)
|
|
250
|
+
if (!existsSync(colorsPath)) {
|
|
251
|
+
return null
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return parseOmarchyColorsToml(readFileSync(colorsPath, 'utf8'))
|
|
255
|
+
} catch {
|
|
256
|
+
return null
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function omarchyPaletteToThemeColors(palette: OmarchyPalette): ThemeColors {
|
|
261
|
+
const background = palette.background
|
|
262
|
+
const text = palette.foreground
|
|
263
|
+
const muted = palette.muted ?? palette.dark_foreground ?? mix(text, background, 0.5)
|
|
264
|
+
const chrome = palette.cyan ?? palette.blue ?? palette.accent ?? text
|
|
265
|
+
const accent = palette.accent ?? palette.orange ?? chrome
|
|
266
|
+
const danger = palette.red ?? palette.bright_red ?? text
|
|
267
|
+
const selection = chrome
|
|
268
|
+
|
|
269
|
+
return {
|
|
270
|
+
background,
|
|
271
|
+
surface: background,
|
|
272
|
+
surfaceAlt: palette.lighter_background ?? mix(background, text, 0.08),
|
|
273
|
+
surfaceModal: palette.dark_background ?? mix(background, text, 0.04),
|
|
274
|
+
overlay: '#000000',
|
|
275
|
+
border: muted,
|
|
276
|
+
borderMuted: palette.dark_foreground ?? muted,
|
|
277
|
+
text,
|
|
278
|
+
textMuted: muted,
|
|
279
|
+
textSubtle: muted,
|
|
280
|
+
primary: chrome,
|
|
281
|
+
secondary: palette.magenta ?? accent,
|
|
282
|
+
accent,
|
|
283
|
+
active: palette.green ?? palette.bright_green ?? text,
|
|
284
|
+
inactive: muted,
|
|
285
|
+
key: palette.yellow ?? palette.bright_yellow ?? palette.orange ?? text,
|
|
286
|
+
action: accent,
|
|
287
|
+
separator: muted,
|
|
288
|
+
program: palette.green ?? palette.bright_green ?? text,
|
|
289
|
+
fileTree: chrome,
|
|
290
|
+
danger,
|
|
291
|
+
dangerSurface: mix(background, danger, 0.2),
|
|
292
|
+
selection,
|
|
293
|
+
selectionText: readableText(selection),
|
|
294
|
+
}
|
|
295
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
}
|
package/src/styles/theme.tsx
CHANGED
|
@@ -6,12 +6,30 @@ import type {
|
|
|
6
6
|
ThemeDefinition,
|
|
7
7
|
ThemeVariant,
|
|
8
8
|
} from '../types'
|
|
9
|
+
import { getHomeDir } from '../config/paths'
|
|
9
10
|
import { TUI_THEME_COLORS } from './opencode-tui-colors'
|
|
10
11
|
import { THEMES_A } from './opencode-themes-a'
|
|
11
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'
|
|
12
23
|
|
|
13
24
|
export const DEFAULT_THEME_ID = 'rosepine'
|
|
14
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
|
+
}
|
|
15
33
|
|
|
16
34
|
export const BUILTIN_THEMES: Record<string, DesktopTheme> = {
|
|
17
35
|
...THEMES_A,
|
|
@@ -85,31 +103,13 @@ function aliasThemeID(themeId?: string) {
|
|
|
85
103
|
return themeId
|
|
86
104
|
}
|
|
87
105
|
|
|
88
|
-
function getColorSchemeFromColorFgbg(value?: string): 'light' | 'dark' | null {
|
|
89
|
-
if (!value) {
|
|
90
|
-
return null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const parts = value
|
|
94
|
-
.split(';')
|
|
95
|
-
.map(part => Number.parseInt(part, 10))
|
|
96
|
-
.filter(part => Number.isInteger(part))
|
|
97
|
-
|
|
98
|
-
const background = parts.at(-1)
|
|
99
|
-
if (background === undefined) {
|
|
100
|
-
return null
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return background <= 6 || background === 8 ? 'dark' : 'light'
|
|
104
|
-
}
|
|
105
|
-
|
|
106
106
|
export function getSystemColorScheme(): 'light' | 'dark' {
|
|
107
107
|
const envOverride = process.env.MUX_SESH_COLOR_SCHEME
|
|
108
108
|
if (envOverride === 'light' || envOverride === 'dark') {
|
|
109
109
|
return envOverride
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
const detected =
|
|
112
|
+
const detected = colorSchemeFromColorFgbg(process.env.COLORFGBG)
|
|
113
113
|
if (detected) {
|
|
114
114
|
return detected
|
|
115
115
|
}
|
|
@@ -211,7 +211,8 @@ function resolveVariantTheme(theme: DesktopTheme, mode: 'light' | 'dark'): Theme
|
|
|
211
211
|
export function resolveTheme(
|
|
212
212
|
themeId?: string,
|
|
213
213
|
customThemes: Record<string, ThemeDefinition> = {},
|
|
214
|
-
colorScheme: ThemeColorScheme = DEFAULT_COLOR_SCHEME
|
|
214
|
+
colorScheme: ThemeColorScheme = DEFAULT_COLOR_SCHEME,
|
|
215
|
+
options: ResolveThemeOptions = {}
|
|
215
216
|
) {
|
|
216
217
|
const customCatalog = Object.fromEntries(
|
|
217
218
|
Object.entries(customThemes).map(([id, definition]) => [
|
|
@@ -224,6 +225,36 @@ export function resolveTheme(
|
|
|
224
225
|
...customCatalog,
|
|
225
226
|
}
|
|
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
|
+
|
|
227
258
|
const id = normalizedID && catalog[normalizedID] ? normalizedID : DEFAULT_THEME_ID
|
|
228
259
|
const theme = catalog[id] ?? BUILTIN_THEMES[DEFAULT_THEME_ID]
|
|
229
260
|
const { mode } = pickVariant(theme, colorScheme)
|
package/src/ui/CommandsModal.tsx
CHANGED
|
@@ -9,6 +9,7 @@ export type CommandId =
|
|
|
9
9
|
| 'search'
|
|
10
10
|
| 'new-session'
|
|
11
11
|
| 'open-settings'
|
|
12
|
+
| 'open-themes'
|
|
12
13
|
| 'view-projects'
|
|
13
14
|
| 'view-sessions'
|
|
14
15
|
| 'rename-session'
|
|
@@ -26,6 +27,7 @@ export interface CommandEntry {
|
|
|
26
27
|
category: string
|
|
27
28
|
title: string
|
|
28
29
|
keybind: string
|
|
30
|
+
keywords?: string
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
interface Props {
|
|
@@ -59,7 +61,14 @@ export function getCommandEntries(
|
|
|
59
61
|
...(canManageSession
|
|
60
62
|
? [{ id: 'kill-session' as const, category: 'Direct', title: 'Kill session', keybind: 'd' }]
|
|
61
63
|
: []),
|
|
62
|
-
{ id: 'open-settings', category: 'Direct', title: '
|
|
64
|
+
{ id: 'open-settings', category: 'Direct', title: 'Settings', keybind: 'ctrl+p' },
|
|
65
|
+
{
|
|
66
|
+
id: 'open-themes',
|
|
67
|
+
category: 'Direct',
|
|
68
|
+
title: 'Themes',
|
|
69
|
+
keybind: 'ctrl+p',
|
|
70
|
+
keywords: 'theme color scheme appearance',
|
|
71
|
+
},
|
|
63
72
|
...(canManageSession
|
|
64
73
|
? [
|
|
65
74
|
{
|
|
@@ -89,6 +98,13 @@ export function getCommandEntries(
|
|
|
89
98
|
]
|
|
90
99
|
: []),
|
|
91
100
|
{ id: 'open-settings', category: 'Direct', title: 'Open settings', keybind: 'ctrl+p' },
|
|
101
|
+
{
|
|
102
|
+
id: 'open-themes',
|
|
103
|
+
category: 'Direct',
|
|
104
|
+
title: 'Themes',
|
|
105
|
+
keybind: 'ctrl+p',
|
|
106
|
+
keywords: 'theme color scheme appearance',
|
|
107
|
+
},
|
|
92
108
|
{
|
|
93
109
|
id: 'view-projects',
|
|
94
110
|
category: prefixCategory,
|
|
@@ -146,7 +162,8 @@ export function filterCommandEntries(entries: CommandEntry[], query: string): Co
|
|
|
146
162
|
}
|
|
147
163
|
|
|
148
164
|
return entries.filter(entry => {
|
|
149
|
-
const haystack =
|
|
165
|
+
const haystack =
|
|
166
|
+
`${entry.category} ${entry.title} ${entry.keybind} ${entry.keywords ?? ''}`.toLowerCase()
|
|
150
167
|
return haystack.includes(normalizedQuery)
|
|
151
168
|
})
|
|
152
169
|
}
|
package/src/ui/VersionBadge.tsx
CHANGED
|
@@ -3,9 +3,18 @@ import { useTheme } from '../styles/theme'
|
|
|
3
3
|
interface VersionBadgeProps {
|
|
4
4
|
currentVersion: string
|
|
5
5
|
updatedVersion?: string | null
|
|
6
|
+
isDev?: boolean
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export function formatVersionBadge(
|
|
9
|
+
export function formatVersionBadge(
|
|
10
|
+
currentVersion: string,
|
|
11
|
+
updatedVersion?: string | null,
|
|
12
|
+
isDev = false
|
|
13
|
+
): string {
|
|
14
|
+
if (isDev) {
|
|
15
|
+
return 'dev'
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
if (updatedVersion && updatedVersion !== currentVersion) {
|
|
10
19
|
return `v${currentVersion} -> v${updatedVersion}`
|
|
11
20
|
}
|
|
@@ -13,7 +22,11 @@ export function formatVersionBadge(currentVersion: string, updatedVersion?: stri
|
|
|
13
22
|
return `v${currentVersion}`
|
|
14
23
|
}
|
|
15
24
|
|
|
16
|
-
export default function VersionBadge({
|
|
25
|
+
export default function VersionBadge({
|
|
26
|
+
currentVersion,
|
|
27
|
+
updatedVersion,
|
|
28
|
+
isDev = false,
|
|
29
|
+
}: VersionBadgeProps) {
|
|
17
30
|
const theme = useTheme()
|
|
18
31
|
|
|
19
32
|
return (
|
|
@@ -25,7 +38,7 @@ export default function VersionBadge({ currentVersion, updatedVersion }: Version
|
|
|
25
38
|
}}
|
|
26
39
|
>
|
|
27
40
|
<text style={{ fg: theme.textSubtle }}>
|
|
28
|
-
{formatVersionBadge(currentVersion, updatedVersion)}
|
|
41
|
+
{formatVersionBadge(currentVersion, updatedVersion, isDev)}
|
|
29
42
|
</text>
|
|
30
43
|
</box>
|
|
31
44
|
)
|