mux-sesh 1.4.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -7
- package/package.json +3 -3
- package/src/app.tsx +746 -173
- package/src/components/KeybindHelp.tsx +178 -111
- package/src/config/index.ts +413 -20
- package/src/config/listed-sessions.ts +36 -0
- package/src/config/session-rules.ts +101 -0
- package/src/handlers/actions.ts +93 -6
- package/src/handlers/keyboard.ts +299 -79
- package/src/items/order.ts +50 -0
- package/src/opencode/session.ts +1 -17
- package/src/opencode/stats.ts +1 -1
- package/src/preview/project.ts +235 -0
- package/src/projects/session-links.ts +31 -0
- package/src/search/index.ts +83 -47
- package/src/settings.ts +425 -0
- package/src/styles/opencode-themes-a.ts +1 -0
- package/src/styles/opencode-themes-b.ts +1 -0
- package/src/styles/theme.tsx +441 -0
- package/src/tmux/index.ts +58 -14
- package/src/tmux/projects.ts +151 -20
- package/src/tmux/workflows.ts +22 -0
- package/src/types/index.ts +114 -0
- package/src/ui/CommandsModal.tsx +145 -0
- package/src/ui/HighlightedText.tsx +6 -3
- package/src/ui/ItemList.tsx +47 -41
- package/src/ui/Modal.tsx +41 -0
- package/src/ui/OpencodeSessionGroup.tsx +50 -46
- package/src/ui/OpencodeStatsPanel.tsx +34 -39
- package/src/ui/RenameModal.tsx +42 -0
- package/src/ui/SearchInput.tsx +3 -1
- package/src/ui/SessionDetailsPanel.tsx +168 -72
- package/src/ui/SessionList.tsx +59 -34
- package/src/ui/SessionStats.tsx +5 -3
- package/src/ui/SettingEditorModal.tsx +49 -0
- package/src/ui/SettingOptionsModal.tsx +77 -0
- package/src/ui/SettingsModal.tsx +96 -0
- package/src/ui/Toast.tsx +8 -9
- package/src/ui/item-icon.ts +78 -0
- package/src/ui/list-window.ts +22 -0
- package/src/update/installation.ts +4 -15
- package/src/update/version.ts +2 -1
- package/src/util/glob.ts +47 -0
- package/src/util/terminal.ts +6 -20
- package/src/styles/theme.ts +0 -50
package/src/handlers/keyboard.ts
CHANGED
|
@@ -1,65 +1,169 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { TextareaRenderable } from '@opentui/core'
|
|
2
|
+
import type { Dispatch, MutableRefObject, SetStateAction } from 'react'
|
|
3
|
+
import { AppMode, ViewMode, KeybindMode, type Config, type Item, type OpencodeSessionStats } from '../types'
|
|
2
4
|
import { requestShutdown } from '../util/shutdown'
|
|
3
5
|
|
|
6
|
+
export interface KeyboardInput {
|
|
7
|
+
name?: string
|
|
8
|
+
ctrl?: boolean
|
|
9
|
+
shift?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
export interface KeyboardHandlerContext {
|
|
5
13
|
appMode: AppMode
|
|
6
14
|
viewMode: ViewMode
|
|
7
|
-
items:
|
|
8
|
-
regularSessions:
|
|
9
|
-
opencodeSessions:
|
|
15
|
+
items: Item[]
|
|
16
|
+
regularSessions: Item[]
|
|
17
|
+
opencodeSessions: Item[]
|
|
10
18
|
cursor: number
|
|
11
19
|
opencodeCursor: number
|
|
12
20
|
searchQuery: string
|
|
13
21
|
renameTarget: string
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
prefixKey?: string
|
|
23
|
+
projectItems: Item[]
|
|
24
|
+
sessionItems: Item[]
|
|
16
25
|
prefixActive: boolean
|
|
17
|
-
prefixTimeoutRef:
|
|
18
|
-
textareaRef:
|
|
26
|
+
prefixTimeoutRef: MutableRefObject<NodeJS.Timeout | null>
|
|
27
|
+
textareaRef: MutableRefObject<TextareaRenderable | null>
|
|
19
28
|
|
|
20
29
|
setAppMode: (mode: AppMode) => void
|
|
21
30
|
setViewMode: (mode: ViewMode) => void
|
|
22
|
-
setCursor:
|
|
23
|
-
setOpencodeCursor:
|
|
31
|
+
setCursor: Dispatch<SetStateAction<number>>
|
|
32
|
+
setOpencodeCursor: Dispatch<SetStateAction<number>>
|
|
24
33
|
setSearchQuery: (query: string) => void
|
|
25
34
|
setRenameTarget: (target: string) => void
|
|
26
|
-
setAllItems:
|
|
27
|
-
setItems:
|
|
35
|
+
setAllItems: Dispatch<SetStateAction<Item[]>>
|
|
36
|
+
setItems: Dispatch<SetStateAction<Item[]>>
|
|
28
37
|
setPrefixActive: (active: boolean) => void
|
|
29
38
|
|
|
30
|
-
refreshItems: (forceViewMode?: ViewMode) => Promise<void>
|
|
31
|
-
|
|
39
|
+
refreshItems: (forceViewMode?: ViewMode, nextConfig?: Config) => Promise<void>
|
|
40
|
+
requestKillSession: (sessionName: string) => void
|
|
41
|
+
clearPendingKill: () => void
|
|
42
|
+
handleSelect: (item: Item) => Promise<void>
|
|
32
43
|
handleKillSession: (sessionName: string) => Promise<void>
|
|
33
|
-
|
|
44
|
+
handleLastSession: () => Promise<void>
|
|
45
|
+
handleRootSession: (item?: Item) => Promise<void>
|
|
46
|
+
handleEditTarget: (item?: Item) => Promise<void>
|
|
47
|
+
openRenameModal: (sessionName: string) => void
|
|
48
|
+
openCommandsModal: () => void
|
|
49
|
+
openSettingsModal: () => void
|
|
50
|
+
loadOpencodeStatsForSession: (sessionName: string) => Promise<OpencodeSessionStats | null>
|
|
34
51
|
setMessage: (message: string) => void
|
|
35
52
|
}
|
|
36
53
|
|
|
54
|
+
function getKeyName(key: KeyboardInput): string {
|
|
55
|
+
return key.name ?? ''
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function matchesPrefixKey(key: KeyboardInput, prefixKey = 'ctrl+x'): boolean {
|
|
59
|
+
const parts = prefixKey.toLowerCase().split('+')
|
|
60
|
+
const keyPart = parts.at(-1) ?? prefixKey.toLowerCase()
|
|
61
|
+
const expectsCtrl = parts.includes('ctrl')
|
|
62
|
+
const expectsShift = parts.includes('shift')
|
|
63
|
+
|
|
64
|
+
return Boolean(key.ctrl) === expectsCtrl && Boolean(key.shift) === expectsShift && getKeyName(key).toLowerCase() === keyPart
|
|
65
|
+
}
|
|
66
|
+
|
|
37
67
|
export function handleNormalMode(
|
|
38
|
-
key:
|
|
68
|
+
key: KeyboardInput,
|
|
39
69
|
ctx: KeyboardHandlerContext,
|
|
40
70
|
keybindMode: KeybindMode = 'vim'
|
|
41
71
|
) {
|
|
72
|
+
const keyName = getKeyName(key)
|
|
42
73
|
// Standard mode requires Ctrl for most actions
|
|
43
74
|
const isStandard = keybindMode === 'standard'
|
|
44
75
|
|
|
76
|
+
if (ctx.prefixActive) {
|
|
77
|
+
if (ctx.prefixTimeoutRef.current) {
|
|
78
|
+
clearTimeout(ctx.prefixTimeoutRef.current)
|
|
79
|
+
ctx.prefixTimeoutRef.current = null
|
|
80
|
+
}
|
|
81
|
+
ctx.setPrefixActive(false)
|
|
82
|
+
|
|
83
|
+
if (key.shift && keyName.toLowerCase() === 'r') {
|
|
84
|
+
ctx.clearPendingKill()
|
|
85
|
+
ctx.refreshItems()
|
|
86
|
+
ctx.setMessage('Refreshed')
|
|
87
|
+
setTimeout(() => ctx.setMessage(''), 2000)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
switch (keyName) {
|
|
92
|
+
case 'l':
|
|
93
|
+
ctx.clearPendingKill()
|
|
94
|
+
void ctx.handleLastSession()
|
|
95
|
+
return
|
|
96
|
+
case 'g': {
|
|
97
|
+
ctx.clearPendingKill()
|
|
98
|
+
const selectedItem =
|
|
99
|
+
ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
100
|
+
void ctx.handleRootSession(selectedItem)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
case 'e': {
|
|
104
|
+
ctx.clearPendingKill()
|
|
105
|
+
const selectedItem =
|
|
106
|
+
ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
107
|
+
if (selectedItem?.itemKind === 'configured') {
|
|
108
|
+
void ctx.handleEditTarget(selectedItem)
|
|
109
|
+
}
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
case 'd':
|
|
113
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
114
|
+
ctx.requestKillSession(ctx.regularSessions[ctx.cursor].title)
|
|
115
|
+
}
|
|
116
|
+
return
|
|
117
|
+
case 'r':
|
|
118
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
119
|
+
ctx.clearPendingKill()
|
|
120
|
+
ctx.openRenameModal(ctx.regularSessions[ctx.cursor].title)
|
|
121
|
+
}
|
|
122
|
+
return
|
|
123
|
+
case 's':
|
|
124
|
+
ctx.clearPendingKill()
|
|
125
|
+
ctx.setViewMode(ViewMode.Sessions)
|
|
126
|
+
ctx.refreshItems(ViewMode.Sessions)
|
|
127
|
+
return
|
|
128
|
+
case 'p':
|
|
129
|
+
ctx.clearPendingKill()
|
|
130
|
+
ctx.setViewMode(ViewMode.Projects)
|
|
131
|
+
ctx.refreshItems(ViewMode.Projects)
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
|
|
139
|
+
ctx.setPrefixActive(true)
|
|
140
|
+
const timeout = setTimeout(() => {
|
|
141
|
+
ctx.setPrefixActive(false)
|
|
142
|
+
}, 2000)
|
|
143
|
+
ctx.prefixTimeoutRef.current = timeout
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
45
147
|
// Handle quit (q for vim, Ctrl+Q or Escape for standard)
|
|
46
148
|
if (
|
|
47
|
-
(isStandard && ((key.ctrl &&
|
|
48
|
-
(!isStandard && (
|
|
149
|
+
(isStandard && ((key.ctrl && keyName === 'q') || keyName === 'escape')) ||
|
|
150
|
+
(!isStandard && (keyName === 'q' || keyName === 'escape'))
|
|
49
151
|
) {
|
|
50
152
|
void requestShutdown(0)
|
|
51
153
|
return
|
|
52
154
|
}
|
|
53
155
|
|
|
54
156
|
// Handle search mode (i for vim, Ctrl+I for standard)
|
|
55
|
-
if (
|
|
157
|
+
if (!isStandard && keyName === 'i') {
|
|
158
|
+
ctx.clearPendingKill()
|
|
56
159
|
ctx.setAppMode(AppMode.Search)
|
|
57
160
|
ctx.setSearchQuery('')
|
|
58
161
|
return
|
|
59
162
|
}
|
|
60
163
|
|
|
61
164
|
// Handle new session (n for vim, Ctrl+N for standard)
|
|
62
|
-
if (
|
|
165
|
+
if (!isStandard && keyName === 'n') {
|
|
166
|
+
ctx.clearPendingKill()
|
|
63
167
|
ctx.setAppMode(AppMode.NewSession)
|
|
64
168
|
if (ctx.viewMode === ViewMode.Sessions) {
|
|
65
169
|
}
|
|
@@ -72,7 +176,8 @@ export function handleNormalMode(
|
|
|
72
176
|
}
|
|
73
177
|
|
|
74
178
|
// Handle opencode mode (o for vim, Ctrl+O for standard)
|
|
75
|
-
if (
|
|
179
|
+
if (!isStandard && keyName === 'o') {
|
|
180
|
+
ctx.clearPendingKill()
|
|
76
181
|
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
77
182
|
ctx.setAppMode(AppMode.OpencodeManage)
|
|
78
183
|
ctx.setOpencodeCursor(0)
|
|
@@ -81,32 +186,59 @@ export function handleNormalMode(
|
|
|
81
186
|
return
|
|
82
187
|
}
|
|
83
188
|
|
|
189
|
+
if (key.ctrl && keyName === 'p') {
|
|
190
|
+
ctx.clearPendingKill()
|
|
191
|
+
ctx.openCommandsModal()
|
|
192
|
+
return
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'l') {
|
|
196
|
+
ctx.clearPendingKill()
|
|
197
|
+
void ctx.handleLastSession()
|
|
198
|
+
return
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'g') {
|
|
202
|
+
ctx.clearPendingKill()
|
|
203
|
+
const selectedItem =
|
|
204
|
+
ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
205
|
+
void ctx.handleRootSession(selectedItem)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'e') {
|
|
210
|
+
ctx.clearPendingKill()
|
|
211
|
+
const selectedItem = ctx.viewMode === ViewMode.Sessions ? ctx.regularSessions[ctx.cursor] : ctx.items[ctx.cursor]
|
|
212
|
+
if (selectedItem?.itemKind === 'configured') {
|
|
213
|
+
void ctx.handleEditTarget(selectedItem)
|
|
214
|
+
}
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
|
|
84
218
|
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
85
|
-
if (
|
|
86
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.
|
|
87
|
-
ctx.
|
|
219
|
+
if (!isStandard && keyName === 'd') {
|
|
220
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
221
|
+
ctx.requestKillSession(ctx.regularSessions[ctx.cursor].title)
|
|
88
222
|
}
|
|
89
223
|
return
|
|
90
224
|
}
|
|
91
225
|
|
|
92
226
|
// Handle rename (r for vim, Ctrl+R for standard)
|
|
93
227
|
if (
|
|
94
|
-
|
|
95
|
-
(isStandard && key.ctrl && key.name === 'r' && !key.shift)
|
|
228
|
+
!ctx.prefixKey && !isStandard && keyName === 'r'
|
|
96
229
|
) {
|
|
97
|
-
if (ctx.viewMode === ViewMode.Sessions && ctx.
|
|
98
|
-
ctx.
|
|
99
|
-
ctx.
|
|
100
|
-
ctx.setSearchQuery(ctx.regularSessions[ctx.cursor].title)
|
|
230
|
+
if (ctx.viewMode === ViewMode.Sessions && ctx.regularSessions[ctx.cursor]?.isSession) {
|
|
231
|
+
ctx.clearPendingKill()
|
|
232
|
+
ctx.openRenameModal(ctx.regularSessions[ctx.cursor].title)
|
|
101
233
|
}
|
|
102
234
|
return
|
|
103
235
|
}
|
|
104
236
|
|
|
105
237
|
// Handle refresh (R for vim, Ctrl+Shift+R for standard)
|
|
106
238
|
if (
|
|
107
|
-
|
|
108
|
-
(isStandard && key.ctrl && key.shift && key.name === 'r')
|
|
239
|
+
!ctx.prefixKey && !isStandard && keyName === 'R'
|
|
109
240
|
) {
|
|
241
|
+
ctx.clearPendingKill()
|
|
110
242
|
ctx.refreshItems()
|
|
111
243
|
ctx.setMessage('Refreshed')
|
|
112
244
|
setTimeout(() => ctx.setMessage(''), 2000)
|
|
@@ -115,12 +247,14 @@ export function handleNormalMode(
|
|
|
115
247
|
|
|
116
248
|
// Handle view mode switches (vim only)
|
|
117
249
|
if (!isStandard) {
|
|
118
|
-
if (
|
|
250
|
+
if (keyName === 's') {
|
|
251
|
+
ctx.clearPendingKill()
|
|
119
252
|
ctx.setViewMode(ViewMode.Sessions)
|
|
120
253
|
ctx.refreshItems(ViewMode.Sessions)
|
|
121
254
|
return
|
|
122
255
|
}
|
|
123
|
-
if (
|
|
256
|
+
if (keyName === 'p') {
|
|
257
|
+
ctx.clearPendingKill()
|
|
124
258
|
ctx.setViewMode(ViewMode.Projects)
|
|
125
259
|
ctx.refreshItems(ViewMode.Projects)
|
|
126
260
|
return
|
|
@@ -128,7 +262,8 @@ export function handleNormalMode(
|
|
|
128
262
|
}
|
|
129
263
|
|
|
130
264
|
// Handle navigation
|
|
131
|
-
if (
|
|
265
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
266
|
+
ctx.clearPendingKill()
|
|
132
267
|
if (ctx.viewMode === ViewMode.Sessions) {
|
|
133
268
|
ctx.setCursor(c => Math.min(c + 1, ctx.regularSessions.length - 1))
|
|
134
269
|
} else {
|
|
@@ -137,13 +272,15 @@ export function handleNormalMode(
|
|
|
137
272
|
return
|
|
138
273
|
}
|
|
139
274
|
|
|
140
|
-
if (
|
|
275
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
276
|
+
ctx.clearPendingKill()
|
|
141
277
|
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
142
278
|
return
|
|
143
279
|
}
|
|
144
280
|
|
|
145
281
|
// Handle selection
|
|
146
|
-
if (
|
|
282
|
+
if (keyName === 'return') {
|
|
283
|
+
ctx.clearPendingKill()
|
|
147
284
|
if (ctx.regularSessions[ctx.cursor]) {
|
|
148
285
|
ctx.handleSelect(ctx.regularSessions[ctx.cursor])
|
|
149
286
|
}
|
|
@@ -151,8 +288,9 @@ export function handleNormalMode(
|
|
|
151
288
|
}
|
|
152
289
|
|
|
153
290
|
// Handle number shortcuts (vim only)
|
|
154
|
-
if (!isStandard &&
|
|
155
|
-
|
|
291
|
+
if (!isStandard && keyName >= '1' && keyName <= '9') {
|
|
292
|
+
ctx.clearPendingKill()
|
|
293
|
+
const num = parseInt(keyName, 10) - 1
|
|
156
294
|
if (num >= 0 && num < ctx.regularSessions.length) {
|
|
157
295
|
ctx.handleSelect(ctx.regularSessions[num])
|
|
158
296
|
}
|
|
@@ -160,24 +298,69 @@ export function handleNormalMode(
|
|
|
160
298
|
}
|
|
161
299
|
|
|
162
300
|
export function handleOpencodeManageMode(
|
|
163
|
-
key:
|
|
301
|
+
key: KeyboardInput,
|
|
164
302
|
ctx: KeyboardHandlerContext,
|
|
165
303
|
keybindMode: KeybindMode = 'vim'
|
|
166
304
|
) {
|
|
305
|
+
const keyName = getKeyName(key)
|
|
167
306
|
const isStandard = keybindMode === 'standard'
|
|
168
307
|
|
|
308
|
+
if (key.ctrl && keyName === 'p') {
|
|
309
|
+
ctx.clearPendingKill()
|
|
310
|
+
ctx.openCommandsModal()
|
|
311
|
+
return
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (ctx.prefixActive) {
|
|
315
|
+
if (ctx.prefixTimeoutRef.current) {
|
|
316
|
+
clearTimeout(ctx.prefixTimeoutRef.current)
|
|
317
|
+
ctx.prefixTimeoutRef.current = null
|
|
318
|
+
}
|
|
319
|
+
ctx.setPrefixActive(false)
|
|
320
|
+
|
|
321
|
+
switch (keyName) {
|
|
322
|
+
case 'o':
|
|
323
|
+
ctx.clearPendingKill()
|
|
324
|
+
ctx.setAppMode(AppMode.Normal)
|
|
325
|
+
return
|
|
326
|
+
case 'd':
|
|
327
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
328
|
+
ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
329
|
+
}
|
|
330
|
+
return
|
|
331
|
+
case 'r':
|
|
332
|
+
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
333
|
+
ctx.clearPendingKill()
|
|
334
|
+
ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
335
|
+
}
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (ctx.prefixKey && matchesPrefixKey(key, ctx.prefixKey)) {
|
|
343
|
+
ctx.setPrefixActive(true)
|
|
344
|
+
const timeout = setTimeout(() => {
|
|
345
|
+
ctx.setPrefixActive(false)
|
|
346
|
+
}, 2000)
|
|
347
|
+
ctx.prefixTimeoutRef.current = timeout
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
|
|
169
351
|
// Handle back/exit (o/Esc for vim, Ctrl+O/Esc for standard)
|
|
170
352
|
if (
|
|
171
|
-
|
|
172
|
-
(!isStandard &&
|
|
173
|
-
(isStandard && key.ctrl && key.name === 'o')
|
|
353
|
+
keyName === 'escape' ||
|
|
354
|
+
(!ctx.prefixKey && !isStandard && keyName === 'o')
|
|
174
355
|
) {
|
|
356
|
+
ctx.clearPendingKill()
|
|
175
357
|
ctx.setAppMode(AppMode.Normal)
|
|
176
358
|
return
|
|
177
359
|
}
|
|
178
360
|
|
|
179
361
|
// Handle navigation down
|
|
180
|
-
if (
|
|
362
|
+
if (keyName === 'down' || (!isStandard && keyName === 'j')) {
|
|
363
|
+
ctx.clearPendingKill()
|
|
181
364
|
ctx.setOpencodeCursor(c => {
|
|
182
365
|
const newCursor = Math.min(c + 1, ctx.opencodeSessions.length - 1)
|
|
183
366
|
if (newCursor !== c && ctx.opencodeSessions[newCursor]) {
|
|
@@ -189,7 +372,8 @@ export function handleOpencodeManageMode(
|
|
|
189
372
|
}
|
|
190
373
|
|
|
191
374
|
// Handle navigation up
|
|
192
|
-
if (
|
|
375
|
+
if (keyName === 'up' || (!isStandard && keyName === 'k')) {
|
|
376
|
+
ctx.clearPendingKill()
|
|
193
377
|
ctx.setOpencodeCursor(c => {
|
|
194
378
|
const newCursor = Math.max(c - 1, 0)
|
|
195
379
|
if (newCursor !== c && ctx.opencodeSessions[newCursor]) {
|
|
@@ -201,28 +385,35 @@ export function handleOpencodeManageMode(
|
|
|
201
385
|
}
|
|
202
386
|
|
|
203
387
|
// Handle delete/kill (d for vim, Ctrl+D for standard)
|
|
204
|
-
if (
|
|
388
|
+
if (!isStandard && keyName === 'd') {
|
|
205
389
|
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
206
|
-
ctx.
|
|
390
|
+
ctx.requestKillSession(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
207
391
|
}
|
|
208
392
|
return
|
|
209
393
|
}
|
|
210
394
|
|
|
211
395
|
// Handle rename (r for vim, Ctrl+R for standard)
|
|
212
|
-
if (
|
|
396
|
+
if (!ctx.prefixKey && !isStandard && keyName === 'r') {
|
|
213
397
|
if (ctx.opencodeSessions[ctx.opencodeCursor]) {
|
|
214
|
-
ctx.
|
|
215
|
-
ctx.
|
|
216
|
-
ctx.setSearchQuery(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
398
|
+
ctx.clearPendingKill()
|
|
399
|
+
ctx.openRenameModal(ctx.opencodeSessions[ctx.opencodeCursor].title)
|
|
217
400
|
}
|
|
401
|
+
return
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (!ctx.prefixKey && !isStandard && keyName === ',') {
|
|
405
|
+
ctx.clearPendingKill()
|
|
406
|
+
ctx.openSettingsModal()
|
|
407
|
+
return
|
|
218
408
|
}
|
|
219
409
|
}
|
|
220
410
|
|
|
221
411
|
export function handleSearchMode(
|
|
222
|
-
key:
|
|
412
|
+
key: KeyboardInput,
|
|
223
413
|
ctx: KeyboardHandlerContext,
|
|
224
414
|
keybindMode: KeybindMode = 'vim'
|
|
225
415
|
) {
|
|
416
|
+
const keyName = getKeyName(key)
|
|
226
417
|
const isStandard = keybindMode === 'standard'
|
|
227
418
|
|
|
228
419
|
// Standard mode: Prefix key system with Ctrl+X
|
|
@@ -236,13 +427,14 @@ export function handleSearchMode(
|
|
|
236
427
|
}
|
|
237
428
|
ctx.setPrefixActive(false)
|
|
238
429
|
|
|
239
|
-
switch (
|
|
430
|
+
switch (keyName) {
|
|
240
431
|
case 'd': // Ctrl+X d - delete/kill
|
|
241
432
|
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
242
|
-
ctx.
|
|
433
|
+
ctx.requestKillSession(ctx.items[ctx.cursor].title)
|
|
243
434
|
}
|
|
244
435
|
return
|
|
245
436
|
case 'n': // Ctrl+X n - new session
|
|
437
|
+
ctx.clearPendingKill()
|
|
246
438
|
ctx.setSearchQuery('')
|
|
247
439
|
ctx.setAppMode(AppMode.NewSession)
|
|
248
440
|
ctx.setViewMode(ViewMode.Projects)
|
|
@@ -251,24 +443,40 @@ export function handleSearchMode(
|
|
|
251
443
|
ctx.setCursor(Math.max(0, ctx.projectItems.length - 1))
|
|
252
444
|
return
|
|
253
445
|
case 'o': // Ctrl+X o - opencode
|
|
446
|
+
ctx.clearPendingKill()
|
|
254
447
|
if (ctx.viewMode === ViewMode.Sessions && ctx.opencodeSessions.length > 0) {
|
|
255
448
|
ctx.setAppMode(AppMode.OpencodeManage)
|
|
256
449
|
ctx.setOpencodeCursor(0)
|
|
257
450
|
ctx.loadOpencodeStatsForSession(ctx.opencodeSessions[0].title)
|
|
258
451
|
}
|
|
259
452
|
return
|
|
260
|
-
case '
|
|
453
|
+
case 's':
|
|
454
|
+
ctx.clearPendingKill()
|
|
455
|
+
ctx.openSettingsModal()
|
|
456
|
+
return
|
|
457
|
+
case 'l': // Ctrl+X l - last session
|
|
458
|
+
ctx.clearPendingKill()
|
|
459
|
+
void ctx.handleLastSession()
|
|
460
|
+
return
|
|
461
|
+
case 'g': { // Ctrl+X g - root session
|
|
462
|
+
ctx.clearPendingKill()
|
|
463
|
+
const selectedItem = ctx.viewMode === ViewMode.Sessions ? ctx.items[ctx.cursor] : ctx.items[ctx.cursor]
|
|
464
|
+
void ctx.handleRootSession(selectedItem)
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
case 'r':
|
|
468
|
+
if (key.shift) {
|
|
469
|
+
ctx.refreshItems()
|
|
470
|
+
ctx.setMessage('Refreshed')
|
|
471
|
+
setTimeout(() => ctx.setMessage(''), 2000)
|
|
472
|
+
return
|
|
473
|
+
}
|
|
474
|
+
|
|
261
475
|
if (ctx.viewMode === ViewMode.Sessions && ctx.items[ctx.cursor]?.isSession) {
|
|
262
|
-
ctx.
|
|
263
|
-
ctx.
|
|
264
|
-
ctx.setSearchQuery(ctx.items[ctx.cursor].title)
|
|
476
|
+
ctx.clearPendingKill()
|
|
477
|
+
ctx.openRenameModal(ctx.items[ctx.cursor].title)
|
|
265
478
|
}
|
|
266
479
|
return
|
|
267
|
-
case 'R': // Ctrl+X R - refresh
|
|
268
|
-
ctx.refreshItems()
|
|
269
|
-
ctx.setMessage('Refreshed')
|
|
270
|
-
setTimeout(() => ctx.setMessage(''), 2000)
|
|
271
|
-
return
|
|
272
480
|
default:
|
|
273
481
|
// Not a valid prefix command, ignore
|
|
274
482
|
return
|
|
@@ -276,7 +484,7 @@ export function handleSearchMode(
|
|
|
276
484
|
}
|
|
277
485
|
|
|
278
486
|
// Handle Ctrl+X prefix activation
|
|
279
|
-
if (key
|
|
487
|
+
if (matchesPrefixKey(key, ctx.prefixKey)) {
|
|
280
488
|
ctx.setPrefixActive(true)
|
|
281
489
|
|
|
282
490
|
// Clear prefix after 2 seconds if no key pressed
|
|
@@ -288,14 +496,15 @@ export function handleSearchMode(
|
|
|
288
496
|
}
|
|
289
497
|
|
|
290
498
|
// Ctrl+Q to quit (immediate, no prefix needed)
|
|
291
|
-
if (key.ctrl &&
|
|
499
|
+
if (key.ctrl && keyName === 'q') {
|
|
292
500
|
void requestShutdown(0)
|
|
293
501
|
return
|
|
294
502
|
}
|
|
295
503
|
}
|
|
296
504
|
|
|
297
505
|
// Handle Esc differently based on mode
|
|
298
|
-
if (
|
|
506
|
+
if (keyName === 'escape') {
|
|
507
|
+
ctx.clearPendingKill()
|
|
299
508
|
if (isStandard) {
|
|
300
509
|
// Standard mode: just clear search, stay in search mode
|
|
301
510
|
ctx.setSearchQuery('')
|
|
@@ -309,32 +518,37 @@ export function handleSearchMode(
|
|
|
309
518
|
return
|
|
310
519
|
}
|
|
311
520
|
|
|
312
|
-
switch (
|
|
521
|
+
switch (keyName) {
|
|
313
522
|
case 'return':
|
|
523
|
+
ctx.clearPendingKill()
|
|
314
524
|
if (ctx.items.length > 0) {
|
|
315
525
|
ctx.handleSelect(ctx.items[0])
|
|
316
526
|
}
|
|
317
527
|
break
|
|
318
528
|
case 'down':
|
|
529
|
+
ctx.clearPendingKill()
|
|
319
530
|
ctx.setCursor(c => Math.min(c + 1, ctx.items.length - 1))
|
|
320
531
|
break
|
|
321
532
|
case 'up':
|
|
533
|
+
ctx.clearPendingKill()
|
|
322
534
|
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
323
535
|
break
|
|
324
536
|
}
|
|
325
537
|
}
|
|
326
538
|
|
|
327
539
|
export function handleNewSessionMode(
|
|
328
|
-
key:
|
|
540
|
+
key: KeyboardInput,
|
|
329
541
|
ctx: KeyboardHandlerContext,
|
|
330
542
|
keybindMode: KeybindMode = 'vim'
|
|
331
543
|
) {
|
|
544
|
+
const keyName = getKeyName(key)
|
|
332
545
|
const isStandard = keybindMode === 'standard'
|
|
333
546
|
|
|
334
547
|
// Handle Ctrl keybinds in standard mode
|
|
335
548
|
if (isStandard && key.ctrl) {
|
|
336
549
|
// Ctrl+I to switch to search mode
|
|
337
|
-
if (
|
|
550
|
+
if (keyName === 'i') {
|
|
551
|
+
ctx.clearPendingKill()
|
|
338
552
|
ctx.setAppMode(AppMode.Search)
|
|
339
553
|
ctx.setViewMode(ViewMode.Sessions)
|
|
340
554
|
ctx.setAllItems(ctx.sessionItems)
|
|
@@ -344,14 +558,15 @@ export function handleNewSessionMode(
|
|
|
344
558
|
}
|
|
345
559
|
|
|
346
560
|
// Ctrl+D to delete session (if on sessions view)
|
|
347
|
-
|
|
348
|
-
ctx.
|
|
561
|
+
if (keyName === 'd' && ctx.items[ctx.cursor]?.isSession) {
|
|
562
|
+
ctx.requestKillSession(ctx.items[ctx.cursor].title)
|
|
349
563
|
return
|
|
350
564
|
}
|
|
351
565
|
}
|
|
352
566
|
|
|
353
567
|
// Handle Esc differently based on mode
|
|
354
|
-
if (
|
|
568
|
+
if (keyName === 'escape') {
|
|
569
|
+
ctx.clearPendingKill()
|
|
355
570
|
if (isStandard) {
|
|
356
571
|
// Standard mode: return to search mode (always in insert mode)
|
|
357
572
|
ctx.setAppMode(AppMode.Search)
|
|
@@ -370,29 +585,33 @@ export function handleNewSessionMode(
|
|
|
370
585
|
return
|
|
371
586
|
}
|
|
372
587
|
|
|
373
|
-
switch (
|
|
588
|
+
switch (keyName) {
|
|
374
589
|
case 'return':
|
|
375
590
|
break
|
|
376
591
|
case 'down':
|
|
592
|
+
ctx.clearPendingKill()
|
|
377
593
|
ctx.setCursor(c => Math.min(c + 1, ctx.items.length - 1))
|
|
378
594
|
break
|
|
379
595
|
case 'up':
|
|
596
|
+
ctx.clearPendingKill()
|
|
380
597
|
ctx.setCursor(c => Math.max(c - 1, 0))
|
|
381
598
|
break
|
|
382
599
|
}
|
|
383
600
|
}
|
|
384
601
|
|
|
385
602
|
export function handleRenameMode(
|
|
386
|
-
key:
|
|
603
|
+
key: KeyboardInput,
|
|
387
604
|
ctx: KeyboardHandlerContext,
|
|
388
605
|
keybindMode: KeybindMode = 'vim'
|
|
389
606
|
) {
|
|
607
|
+
const keyName = getKeyName(key)
|
|
390
608
|
const isStandard = keybindMode === 'standard'
|
|
391
609
|
|
|
392
610
|
// Handle Ctrl keybinds in standard mode
|
|
393
611
|
if (isStandard && key.ctrl) {
|
|
394
612
|
// Ctrl+I to switch to search mode
|
|
395
|
-
if (
|
|
613
|
+
if (keyName === 'i') {
|
|
614
|
+
ctx.clearPendingKill()
|
|
396
615
|
ctx.setAppMode(AppMode.Search)
|
|
397
616
|
ctx.setSearchQuery('')
|
|
398
617
|
ctx.setRenameTarget('')
|
|
@@ -400,8 +619,8 @@ export function handleRenameMode(
|
|
|
400
619
|
}
|
|
401
620
|
|
|
402
621
|
// Ctrl+D to delete the rename target session
|
|
403
|
-
|
|
404
|
-
ctx.
|
|
622
|
+
if (keyName === 'd' && ctx.renameTarget) {
|
|
623
|
+
ctx.requestKillSession(ctx.renameTarget)
|
|
405
624
|
ctx.setAppMode(AppMode.Search)
|
|
406
625
|
ctx.setSearchQuery('')
|
|
407
626
|
ctx.setRenameTarget('')
|
|
@@ -410,7 +629,8 @@ export function handleRenameMode(
|
|
|
410
629
|
}
|
|
411
630
|
|
|
412
631
|
// Handle Esc differently based on mode
|
|
413
|
-
if (
|
|
632
|
+
if (keyName === 'escape') {
|
|
633
|
+
ctx.clearPendingKill()
|
|
414
634
|
if (isStandard) {
|
|
415
635
|
// Standard mode: return to search mode (always in insert mode)
|
|
416
636
|
ctx.setAppMode(AppMode.Search)
|
|
@@ -427,7 +647,7 @@ export function handleRenameMode(
|
|
|
427
647
|
return
|
|
428
648
|
}
|
|
429
649
|
|
|
430
|
-
switch (
|
|
650
|
+
switch (keyName) {
|
|
431
651
|
case 'return':
|
|
432
652
|
break
|
|
433
653
|
}
|