mux-sesh 1.6.3 → 1.7.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.
Files changed (82) hide show
  1. package/README.md +90 -59
  2. package/package.json +7 -5
  3. package/src/app/commands.ts +120 -0
  4. package/src/app/controller.ts +397 -0
  5. package/src/app/controls.ts +121 -0
  6. package/src/app/core-state.ts +71 -0
  7. package/src/app/data.ts +90 -0
  8. package/src/app/derived.ts +77 -0
  9. package/src/app/effects.ts +392 -0
  10. package/src/app/handlers.ts +325 -0
  11. package/src/app/keyboard.ts +161 -0
  12. package/src/app/modal-keyboard.ts +118 -0
  13. package/src/app/modal-state.ts +50 -0
  14. package/src/app/modals-layer.tsx +159 -0
  15. package/src/app/modals.ts +108 -0
  16. package/src/app/notifications.ts +21 -0
  17. package/src/app/opencode.ts +49 -0
  18. package/src/app/operations.ts +31 -0
  19. package/src/app/runtime.ts +76 -0
  20. package/src/app/screen.tsx +217 -0
  21. package/src/app/state.ts +166 -0
  22. package/src/app/textarea.ts +16 -0
  23. package/src/app/view.ts +89 -0
  24. package/src/app.tsx +7 -1101
  25. package/src/config/index.ts +36 -42
  26. package/src/config/listed-sessions.ts +2 -5
  27. package/src/config/paths.ts +13 -0
  28. package/src/config/session-rules.ts +10 -11
  29. package/src/config/store.ts +26 -0
  30. package/src/handlers/action-helpers.ts +50 -0
  31. package/src/handlers/actions.ts +34 -65
  32. package/src/handlers/keyboard/index.ts +5 -0
  33. package/src/handlers/keyboard/new-session.ts +57 -0
  34. package/src/handlers/keyboard/normal.ts +201 -0
  35. package/src/handlers/keyboard/opencode.ts +104 -0
  36. package/src/handlers/keyboard/search.ts +113 -0
  37. package/src/handlers/keyboard/shared.ts +116 -0
  38. package/src/items/order.ts +21 -2
  39. package/src/opencode/sqlite.ts +21 -6
  40. package/src/preview/project.ts +41 -15
  41. package/src/search/index.ts +4 -1
  42. package/src/settings.ts +294 -297
  43. package/src/styles/opencode-themes-a.ts +1442 -1
  44. package/src/styles/opencode-themes-b.ts +1212 -1
  45. package/src/styles/opencode-tui-colors.ts +1784 -1
  46. package/src/styles/theme.tsx +2 -1
  47. package/src/tmux/actions.ts +103 -0
  48. package/src/tmux/details.ts +123 -0
  49. package/src/tmux/helpers.ts +35 -0
  50. package/src/tmux/index.ts +10 -286
  51. package/src/tmux/list.ts +31 -0
  52. package/src/tmux/project-discovery.ts +113 -0
  53. package/src/tmux/project-loader.ts +74 -0
  54. package/src/tmux/project-zoxide.ts +128 -0
  55. package/src/tmux/projects.ts +23 -261
  56. package/src/types/index.ts +0 -1
  57. package/src/ui/CommandsModal.tsx +87 -22
  58. package/src/ui/HighlightedText.tsx +1 -5
  59. package/src/ui/ItemList.tsx +26 -11
  60. package/src/ui/Modal.tsx +8 -1
  61. package/src/ui/OpencodeSessionGroup.tsx +20 -9
  62. package/src/ui/OpencodeStatsPanel.tsx +48 -15
  63. package/src/ui/RenameModal.tsx +17 -17
  64. package/src/ui/SearchInput.tsx +1 -20
  65. package/src/ui/SessionDetailsPanel.tsx +43 -15
  66. package/src/ui/SessionList.tsx +25 -4
  67. package/src/ui/SettingEditorModal.tsx +15 -9
  68. package/src/ui/SettingOptionsModal.tsx +30 -12
  69. package/src/ui/SettingsModal.tsx +20 -14
  70. package/src/ui/VersionBadge.tsx +3 -1
  71. package/src/ui/item-icon.ts +5 -1
  72. package/src/ui/list-window.ts +5 -1
  73. package/src/ui/text-columns.ts +17 -0
  74. package/src/ui/use-textarea-focus.ts +26 -0
  75. package/src/update/index.ts +10 -2
  76. package/src/update/installation.ts +6 -2
  77. package/src/util/ansi.ts +3 -0
  78. package/src/util/glob.ts +5 -1
  79. package/src/util/path-display.ts +98 -0
  80. package/src/components/KeybindHelp.tsx +0 -289
  81. package/src/handlers/keyboard.ts +0 -654
  82. package/src/ui/SessionStats.tsx +0 -32
@@ -1,5 +1,4 @@
1
1
  import { join } from 'path'
2
- import { mkdir } from 'fs/promises'
3
2
  import type {
4
3
  Config,
5
4
  IconConfig,
@@ -46,7 +45,9 @@ function asStringArray(value: unknown): string[] | undefined {
46
45
  return undefined
47
46
  }
48
47
 
49
- const strings = value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0)
48
+ const strings = value.filter(
49
+ (entry): entry is string => typeof entry === 'string' && entry.length > 0
50
+ )
50
51
  return strings.length > 0 ? strings : undefined
51
52
  }
52
53
 
@@ -59,7 +60,10 @@ function asZoxideMode(value: unknown): ZoxideMode | undefined {
59
60
  }
60
61
 
61
62
  function asSortOrder(value: unknown): SortOrder | undefined {
62
- return value === 'live-first' || value === 'configured-first' || value === 'zoxide-first' || value === 'alphabetical'
63
+ return value === 'live-first' ||
64
+ value === 'configured-first' ||
65
+ value === 'zoxide-first' ||
66
+ value === 'alphabetical'
63
67
  ? value
64
68
  : undefined
65
69
  }
@@ -277,21 +281,30 @@ export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME |
277
281
  ? 'opencode'
278
282
  : requestedTheme
279
283
  const implicitColorScheme =
280
- requestedTheme === 'opencode-light' ? 'light' : requestedTheme === 'opencode-dark' ? 'dark' : undefined
281
-
282
- const projectPaths = (asStringArray(raw.project_paths) ?? asStringArray(raw.projectPaths) ?? defaultConfig.projectPaths).map(
283
- projectPath => expandHomePath(projectPath, homeDir)
284
- )
284
+ requestedTheme === 'opencode-light'
285
+ ? 'light'
286
+ : requestedTheme === 'opencode-dark'
287
+ ? 'dark'
288
+ : undefined
289
+
290
+ const projectPaths = (
291
+ asStringArray(raw.project_paths) ??
292
+ asStringArray(raw.projectPaths) ??
293
+ defaultConfig.projectPaths
294
+ ).map(projectPath => expandHomePath(projectPath, homeDir))
285
295
  const reposPath = expandHomePath(
286
296
  asString(raw.repos_path) ?? asString(raw.reposPath) ?? defaultConfig.reposPath,
287
297
  homeDir
288
298
  )
289
299
  const editor = asString(raw.editor) ?? defaultConfig.editor
290
300
  const editorCmd = asString(raw.editor_cmd) ?? asString(raw.editorCmd) ?? defaultConfig.editorCmd
291
- const keybindMode = asKeybindMode(raw.keybind_mode) ?? asKeybindMode(raw.keybindMode) ?? defaultConfig.keybindMode
301
+ const keybindMode =
302
+ asKeybindMode(raw.keybind_mode) ?? asKeybindMode(raw.keybindMode) ?? defaultConfig.keybindMode
292
303
  const prefixKey = asString(raw.prefix_key) ?? asString(raw.prefixKey) ?? defaultConfig.prefixKey
293
- const zoxideMode = asZoxideMode(raw.zoxide_mode) ?? asZoxideMode(raw.zoxideMode) ?? defaultConfig.zoxideMode
294
- const sortOrder = asSortOrder(raw.sort_order) ?? asSortOrder(raw.sortOrder) ?? defaultConfig.sortOrder
304
+ const zoxideMode =
305
+ asZoxideMode(raw.zoxide_mode) ?? asZoxideMode(raw.zoxideMode) ?? defaultConfig.zoxideMode
306
+ const sortOrder =
307
+ asSortOrder(raw.sort_order) ?? asSortOrder(raw.sortOrder) ?? defaultConfig.sortOrder
295
308
  const theme = normalizedTheme ?? defaultConfig.theme
296
309
  const colorScheme =
297
310
  asThemeColorScheme(raw.color_scheme) ??
@@ -299,11 +312,17 @@ export function normalizeConfig(rawConfig: unknown, homeDir = process.env.HOME |
299
312
  implicitColorScheme ??
300
313
  defaultConfig.colorScheme
301
314
  const themes = normalizeThemes(raw.themes) ?? defaultConfig.themes
302
- const autoUpdate = asBoolean(raw.auto_update) ?? asBoolean(raw.autoUpdate) ?? defaultConfig.autoUpdate
303
- const dirLength = asPositiveInteger(raw.dir_length) ?? asPositiveInteger(raw.dirLength) ?? defaultConfig.dirLength
304
- const hiddenSessions = asStringArray(raw.hidden_sessions) ?? asStringArray(raw.hiddenSessions) ?? defaultConfig.hiddenSessions
315
+ const autoUpdate =
316
+ asBoolean(raw.auto_update) ?? asBoolean(raw.autoUpdate) ?? defaultConfig.autoUpdate
317
+ const dirLength =
318
+ asPositiveInteger(raw.dir_length) ?? asPositiveInteger(raw.dirLength) ?? defaultConfig.dirLength
319
+ const hiddenSessions =
320
+ asStringArray(raw.hidden_sessions) ??
321
+ asStringArray(raw.hiddenSessions) ??
322
+ defaultConfig.hiddenSessions
305
323
  const icons = normalizeIcons(raw.icons) ?? defaultConfig.icons
306
- const configuredDefaultSession = normalizeSessionDefaults(raw.default_session) ?? normalizeSessionDefaults(raw.defaultSession)
324
+ const configuredDefaultSession =
325
+ normalizeSessionDefaults(raw.default_session) ?? normalizeSessionDefaults(raw.defaultSession)
307
326
  const defaultSession = {
308
327
  startupCommand: configuredDefaultSession?.startupCommand ?? editorCmd,
309
328
  previewCommand: configuredDefaultSession?.previewCommand,
@@ -418,30 +437,5 @@ export function serializeConfig(config: Config): Record<string, unknown> {
418
437
  }
419
438
  }
420
439
 
421
-
422
- export async function loadConfig(): Promise<Config> {
423
- const configDir = join(process.env.HOME!, '.config', 'mux-sesh')
424
- const configPath = join(configDir, 'config.json')
425
-
426
- try {
427
- const file = Bun.file(configPath)
428
- return normalizeConfig(await file.json(), process.env.HOME || '~')
429
- } catch {
430
- // Config doesn't exist, create default
431
- const defaultConfig = getDefaultConfig()
432
- await saveConfig(defaultConfig)
433
- return defaultConfig
434
- }
435
- }
436
-
437
- export async function saveConfig(config: Config): Promise<void> {
438
- const configDir = join(process.env.HOME!, '.config', 'mux-sesh')
439
- const configPath = join(configDir, 'config.json')
440
-
441
- await mkdir(configDir, { recursive: true })
442
- await Bun.write(configPath, JSON.stringify(serializeConfig(config), null, 2))
443
- }
444
-
445
- export function getConfigPath(): string {
446
- return join(process.env.HOME!, '.config', 'mux-sesh', 'config.json')
447
- }
440
+ export { getConfigDir, getConfigPath, getHomeDir } from './paths'
441
+ export { loadConfig, saveConfig } from './store'
@@ -1,9 +1,6 @@
1
1
  import type { Config, Item, ProjectProfile } from '../types'
2
2
  import { resolveProjectSession } from './session-rules'
3
-
4
- function displayPath(path: string): string {
5
- return path.replace(process.env.HOME || '', '~')
6
- }
3
+ import { getPathGroupLabel } from '../util/path-display'
7
4
 
8
5
  function isListedProjectProfile(profile: ProjectProfile): boolean {
9
6
  return profile.listed === true
@@ -18,7 +15,7 @@ export async function getListedSessionItems(config: Config): Promise<Item[]> {
18
15
 
19
16
  return {
20
17
  title: resolvedSession.sessionName,
21
- desc: displayPath(profile.path),
18
+ desc: getPathGroupLabel(profile.path),
22
19
  path: profile.path,
23
20
  isSession: false,
24
21
  itemKind: 'configured' as const,
@@ -0,0 +1,13 @@
1
+ import { join } from 'path'
2
+
3
+ export function getHomeDir(): string {
4
+ return process.env.HOME || '~'
5
+ }
6
+
7
+ export function getConfigDir(homeDir = getHomeDir()): string {
8
+ return process.env.XDG_CONFIG_HOME || join(homeDir, '.config')
9
+ }
10
+
11
+ export function getConfigPath(homeDir = getHomeDir()): string {
12
+ return join(getConfigDir(homeDir), 'mux-sesh', 'config.json')
13
+ }
@@ -50,8 +50,8 @@ export async function getGitRoot(projectPath: string): Promise<string | null> {
50
50
  }
51
51
  }
52
52
 
53
- function buildSessionName(projectPath: string, dirLength = 1, gitRoot: string | null): string {
54
- const namingPath = normalizePathForMatching(gitRoot ?? projectPath)
53
+ function buildSessionName(projectPath: string, dirLength = 1): string {
54
+ const namingPath = normalizePathForMatching(projectPath)
55
55
  const parts = namingPath.split('/').filter(Boolean)
56
56
  const segmentCount = Math.max(1, dirLength)
57
57
  const relevantParts = parts.slice(-segmentCount)
@@ -63,16 +63,16 @@ function buildSessionName(projectPath: string, dirLength = 1, gitRoot: string |
63
63
  export async function resolveProjectSession(
64
64
  projectPath: string,
65
65
  config: Config,
66
- options: ResolveProjectSessionOptions = {}
66
+ _options: ResolveProjectSessionOptions = {}
67
67
  ): Promise<ResolvedProjectSession> {
68
68
  const normalizedProjectPath = normalizePathForMatching(projectPath)
69
- const getGitRootForPath = options.getGitRoot ?? getGitRoot
70
69
  const projectProfile = findProjectProfile(normalizedProjectPath, config)
71
70
 
72
71
  if (projectProfile) {
73
- const gitRoot = await getGitRootForPath(projectPath)
74
72
  return {
75
- sessionName: sanitizeSessionName(projectProfile.sessionName ?? buildSessionName(projectPath, config.dirLength, gitRoot)),
73
+ sessionName: sanitizeSessionName(
74
+ projectProfile.sessionName ?? buildSessionName(projectPath, config.dirLength)
75
+ ),
76
76
  startupCommand: projectProfile.startupCommand ?? config.defaultSession?.startupCommand,
77
77
  previewCommand: projectProfile.previewCommand ?? config.defaultSession?.previewCommand,
78
78
  source: 'project',
@@ -81,19 +81,18 @@ export async function resolveProjectSession(
81
81
 
82
82
  const wildcard = findWildcard(normalizedProjectPath, config)
83
83
  if (wildcard) {
84
- const gitRoot = await getGitRootForPath(projectPath)
85
84
  return {
86
- sessionName: sanitizeSessionName(wildcard.sessionName ?? buildSessionName(projectPath, config.dirLength, gitRoot)),
85
+ sessionName: sanitizeSessionName(
86
+ wildcard.sessionName ?? buildSessionName(projectPath, config.dirLength)
87
+ ),
87
88
  startupCommand: wildcard.startupCommand ?? config.defaultSession?.startupCommand,
88
89
  previewCommand: wildcard.previewCommand ?? config.defaultSession?.previewCommand,
89
90
  source: 'wildcard',
90
91
  }
91
92
  }
92
93
 
93
- const gitRoot = await getGitRootForPath(projectPath)
94
-
95
94
  return {
96
- sessionName: buildSessionName(projectPath, config.dirLength, gitRoot),
95
+ sessionName: buildSessionName(projectPath, config.dirLength),
97
96
  startupCommand: config.defaultSession?.startupCommand,
98
97
  previewCommand: config.defaultSession?.previewCommand,
99
98
  source: 'default',
@@ -0,0 +1,26 @@
1
+ import { mkdir } from 'fs/promises'
2
+ import { dirname } from 'path'
3
+ import type { Config } from '../types'
4
+ import { getConfigPath, getHomeDir } from './paths'
5
+ import { getDefaultConfig, normalizeConfig, serializeConfig } from './index'
6
+
7
+ export async function loadConfig(): Promise<Config> {
8
+ const homeDir = getHomeDir()
9
+ const configPath = getConfigPath(homeDir)
10
+
11
+ try {
12
+ const file = Bun.file(configPath)
13
+ return normalizeConfig(await file.json(), homeDir)
14
+ } catch {
15
+ const defaultConfig = getDefaultConfig(homeDir)
16
+ await saveConfig(defaultConfig, homeDir)
17
+ return defaultConfig
18
+ }
19
+ }
20
+
21
+ export async function saveConfig(config: Config, homeDir = getHomeDir()): Promise<void> {
22
+ const configPath = getConfigPath(homeDir)
23
+
24
+ await mkdir(dirname(configPath), { recursive: true })
25
+ await Bun.write(configPath, JSON.stringify(serializeConfig(config), null, 2))
26
+ }
@@ -0,0 +1,50 @@
1
+ import type { Config, Item } from '../types'
2
+ import { getGitRoot, resolveProjectSession } from '../config/session-rules'
3
+ import { createTmuxSession, getTmuxSessionDirectory } from '../tmux'
4
+ import { requestShutdown } from '../util/shutdown'
5
+
6
+ export function quoteShellArg(value: string): string {
7
+ return `'${value.replaceAll("'", "'\\''")}'`
8
+ }
9
+
10
+ export function buildEditorCommand(editor: string, path: string): string {
11
+ return `${editor} ${quoteShellArg(path)}`
12
+ }
13
+
14
+ export function requireConfig(config: Config | null): Config {
15
+ if (!config) {
16
+ throw new Error('Config is not loaded yet')
17
+ }
18
+
19
+ return config
20
+ }
21
+
22
+ export function requireConfiguredItem(item: Item | undefined): Item {
23
+ if (!item || item.itemKind !== 'configured') {
24
+ throw new Error('Select a configured session to edit its target')
25
+ }
26
+
27
+ return item
28
+ }
29
+
30
+ export function getNextSessionName(renameTarget: string, newName: string): string | null {
31
+ const trimmedName = newName.trim()
32
+ if (!trimmedName || trimmedName === renameTarget) {
33
+ return null
34
+ }
35
+
36
+ return trimmedName
37
+ }
38
+
39
+ export async function openProjectSession(projectPath: string, config: Config): Promise<void> {
40
+ const resolvedSession = await resolveProjectSession(projectPath, config)
41
+ await createTmuxSession(resolvedSession.sessionName, projectPath, {
42
+ startupCommand: resolvedSession.startupCommand,
43
+ })
44
+ await requestShutdown(0)
45
+ }
46
+
47
+ export async function getRootSessionPath(item: Item): Promise<string> {
48
+ const itemPath = item.isSession ? await getTmuxSessionDirectory(item.title) : item.path
49
+ return (await getGitRoot(itemPath)) ?? itemPath
50
+ }
@@ -2,37 +2,31 @@ import { spawn } from 'bun'
2
2
  import type { Item, Config } from '../types'
3
3
  import {
4
4
  switchTmuxSession,
5
- createTmuxSession,
6
5
  killTmuxSession,
7
6
  renameTmuxSession,
8
7
  createNamedTmuxSession,
9
8
  getCurrentTmuxSessionName,
10
- getTmuxSessionDirectory,
11
- } from '../tmux/index'
12
- import { getGitRoot, resolveProjectSession } from '../config/session-rules'
9
+ } from '../tmux'
13
10
  import { getLastSessionTarget } from '../tmux/workflows'
14
11
  import { isGitHubURL, cloneGitHubRepo } from '../util/github'
15
12
  import { requestShutdown } from '../util/shutdown'
16
-
17
- function quoteShellArg(value: string): string {
18
- return `'${value.replaceAll("'", "'\\''")}'`
19
- }
13
+ import {
14
+ buildEditorCommand,
15
+ getNextSessionName,
16
+ getRootSessionPath,
17
+ openProjectSession,
18
+ requireConfig,
19
+ requireConfiguredItem,
20
+ } from './action-helpers'
20
21
 
21
22
  export async function handleSelect(item: Item, config: Config | null) {
22
23
  if (item.isSession) {
23
24
  await switchTmuxSession(item.title)
24
25
  await requestShutdown(0)
25
- } else {
26
- if (!config) {
27
- throw new Error('Config is not loaded yet')
28
- }
29
-
30
- const resolvedSession = await resolveProjectSession(item.path, config)
31
- await createTmuxSession(resolvedSession.sessionName, item.path, {
32
- startupCommand: resolvedSession.startupCommand,
33
- })
34
- await requestShutdown(0)
26
+ return
35
27
  }
28
+
29
+ await openProjectSession(item.path, requireConfig(config))
36
30
  }
37
31
 
38
32
  export async function handleKillSession(
@@ -61,15 +55,17 @@ export async function handleRenameSubmit(
61
55
  refreshItems: () => Promise<void>
62
56
  }
63
57
  ) {
64
- const trimmedName = newName.trim()
65
- if (trimmedName && trimmedName !== renameTarget) {
66
- try {
67
- await renameTmuxSession(renameTarget, trimmedName)
68
- callbacks.onSuccess(`Session renamed to '${trimmedName}'`)
69
- await callbacks.refreshItems()
70
- } catch (error) {
71
- callbacks.onError(`Error renaming session: ${error}`)
72
- }
58
+ const nextSessionName = getNextSessionName(renameTarget, newName)
59
+ if (!nextSessionName) {
60
+ return
61
+ }
62
+
63
+ try {
64
+ await renameTmuxSession(renameTarget, nextSessionName)
65
+ callbacks.onSuccess(`Session renamed to '${nextSessionName}'`)
66
+ await callbacks.refreshItems()
67
+ } catch (error) {
68
+ callbacks.onError(`Error renaming session: ${error}`)
73
69
  }
74
70
  }
75
71
 
@@ -85,25 +81,13 @@ export async function handleNewSessionSubmit(
85
81
  try {
86
82
  if (!config) return
87
83
  const clonedPath = await cloneGitHubRepo(searchTerm, config)
88
- const resolvedSession = await resolveProjectSession(clonedPath, config)
89
- await createTmuxSession(resolvedSession.sessionName, clonedPath, {
90
- startupCommand: resolvedSession.startupCommand,
91
- })
92
- await requestShutdown(0)
84
+ await openProjectSession(clonedPath, config)
93
85
  } catch (error) {
94
86
  throw new Error(`Error cloning repository: ${error}`)
95
87
  }
96
88
  } else if (items.length > 0 && cursor < items.length) {
97
89
  const selectedItem = items[cursor]
98
- if (!config) {
99
- throw new Error('Config is not loaded yet')
100
- }
101
-
102
- const resolvedSession = await resolveProjectSession(selectedItem.path, config)
103
- await createTmuxSession(resolvedSession.sessionName, selectedItem.path, {
104
- startupCommand: resolvedSession.startupCommand,
105
- })
106
- await requestShutdown(0)
90
+ await openProjectSession(selectedItem.path, requireConfig(config))
107
91
  } else {
108
92
  await createNamedTmuxSession(searchTerm)
109
93
  await requestShutdown(0)
@@ -127,37 +111,22 @@ export async function handleRootSession(item: Item | undefined, config: Config |
127
111
  throw new Error('No session or project is selected')
128
112
  }
129
113
 
130
- if (!config) {
131
- throw new Error('Config is not loaded yet')
132
- }
133
-
134
- const itemPath = item.isSession ? await getTmuxSessionDirectory(item.title) : item.path
135
- const rootPath = (await getGitRoot(itemPath)) ?? itemPath
136
- const resolvedSession = await resolveProjectSession(rootPath, config)
137
-
138
- await createTmuxSession(resolvedSession.sessionName, rootPath, {
139
- startupCommand: resolvedSession.startupCommand,
140
- })
141
- await requestShutdown(0)
114
+ await openProjectSession(await getRootSessionPath(item), requireConfig(config))
142
115
  }
143
116
 
144
117
  export async function handleEditTarget(item: Item | undefined, config: Config | null) {
145
- if (!item || item.itemKind !== 'configured') {
146
- throw new Error('Select a configured session to edit its target')
147
- }
148
-
149
- if (!config) {
150
- throw new Error('Config is not loaded yet')
151
- }
152
-
153
- const command = `${config.editor} ${quoteShellArg(item.path)}`
118
+ const configuredItem = requireConfiguredItem(item)
119
+ const loadedConfig = requireConfig(config)
120
+ const command = buildEditorCommand(loadedConfig.editor, configuredItem.path)
154
121
 
155
122
  if (process.env.TMUX) {
156
- const proc = spawn(['tmux', 'new-window', '-c', item.path, command], { stderr: 'pipe' })
123
+ const proc = spawn(['tmux', 'new-window', '-c', configuredItem.path, command], {
124
+ stderr: 'pipe',
125
+ })
157
126
  await proc.exited
158
127
 
159
128
  if (proc.exitCode !== 0) {
160
- throw new Error(`Failed to open editor for '${item.title}'`)
129
+ throw new Error(`Failed to open editor for '${configuredItem.title}'`)
161
130
  }
162
131
 
163
132
  await requestShutdown(0)
@@ -165,7 +134,7 @@ export async function handleEditTarget(item: Item | undefined, config: Config |
165
134
  }
166
135
 
167
136
  spawn(['sh', '-lc', command], {
168
- cwd: item.path,
137
+ cwd: configuredItem.path,
169
138
  stdin: 'inherit',
170
139
  stdout: 'inherit',
171
140
  stderr: 'inherit',
@@ -0,0 +1,5 @@
1
+ export type { KeyboardHandlerContext, KeyboardInput } from './shared'
2
+ export { handleNormalMode } from './normal'
3
+ export { handleOpencodeManageMode } from './opencode'
4
+ export { handleSearchMode } from './search'
5
+ export { handleNewSessionMode } from './new-session'
@@ -0,0 +1,57 @@
1
+ import { AppMode, ViewMode, type KeybindMode } from '../../types'
2
+ import { getKeyName, type KeyboardHandlerContext, type KeyboardInput } from './shared'
3
+
4
+ export function handleNewSessionMode(
5
+ key: KeyboardInput,
6
+ ctx: KeyboardHandlerContext,
7
+ keybindMode: KeybindMode = 'vim'
8
+ ) {
9
+ const keyName = getKeyName(key)
10
+ const isStandard = keybindMode === 'standard'
11
+
12
+ if (isStandard && key.ctrl) {
13
+ if (keyName === 'i') {
14
+ ctx.clearPendingKill()
15
+ ctx.setAppMode(AppMode.Search)
16
+ ctx.setViewMode(ViewMode.Sessions)
17
+ ctx.setAllItems(ctx.sessionItems)
18
+ ctx.setItems(ctx.sessionItems)
19
+ ctx.setSearchQuery('')
20
+ return
21
+ }
22
+
23
+ if (keyName === 'd' && ctx.items[ctx.cursor]?.isSession) {
24
+ ctx.requestKillSession(ctx.items[ctx.cursor].title)
25
+ return
26
+ }
27
+ }
28
+
29
+ if (keyName === 'escape') {
30
+ ctx.clearPendingKill()
31
+ if (isStandard) {
32
+ ctx.setAppMode(AppMode.Search)
33
+ ctx.setViewMode(ViewMode.Sessions)
34
+ ctx.setSearchQuery('')
35
+ ctx.setCursor(0)
36
+ void ctx.refreshItems(ViewMode.Sessions)
37
+ return
38
+ }
39
+
40
+ ctx.setAppMode(AppMode.Normal)
41
+ ctx.setViewMode(ViewMode.Sessions)
42
+ ctx.setSearchQuery('')
43
+ ctx.setCursor(0)
44
+ return
45
+ }
46
+
47
+ switch (keyName) {
48
+ case 'down':
49
+ ctx.clearPendingKill()
50
+ ctx.setCursor(cursor => Math.min(cursor + 1, ctx.items.length - 1))
51
+ break
52
+ case 'up':
53
+ ctx.clearPendingKill()
54
+ ctx.setCursor(cursor => Math.max(cursor - 1, 0))
55
+ break
56
+ }
57
+ }