mux-sesh 1.4.1 → 1.5.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 +176 -34
- package/src/components/KeybindHelp.tsx +48 -2
- package/src/config/index.ts +206 -19
- 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 +114 -64
- 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/tmux/index.ts +58 -14
- package/src/tmux/projects.ts +151 -20
- package/src/tmux/workflows.ts +22 -0
- package/src/types/index.ts +49 -0
- package/src/ui/ItemList.tsx +21 -14
- package/src/ui/OpencodeSessionGroup.tsx +48 -42
- package/src/ui/SessionDetailsPanel.tsx +179 -45
- package/src/ui/SessionList.tsx +67 -33
- package/src/ui/item-icon.ts +77 -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
|
@@ -1,64 +1,116 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
|
+
import { getProjectPreview, type ProjectPreview } from '../preview/project'
|
|
2
3
|
import { getSessionDetails } from '../tmux'
|
|
3
4
|
import { colors, detailPanelStyle } from '../styles/theme'
|
|
4
|
-
import type { Item, SessionDetails } from '../types'
|
|
5
|
+
import type { Config, Item, SessionDetails } from '../types'
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
selectedItem?: Item
|
|
9
|
+
config: Config | null
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
type DetailState =
|
|
13
|
+
| { status: 'idle' }
|
|
14
|
+
| { status: 'loading' }
|
|
15
|
+
| { status: 'session'; details: SessionDetails }
|
|
16
|
+
| { status: 'project'; details: ProjectPreview }
|
|
17
|
+
| { status: 'error'; message: string }
|
|
13
18
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
setDetails(null)
|
|
23
|
-
}
|
|
24
|
-
}, [selectedItem])
|
|
25
|
-
|
|
26
|
-
const panelStyle = {
|
|
27
|
-
...detailPanelStyle,
|
|
28
|
-
flexGrow: 1,
|
|
29
|
-
flexShrink: 1,
|
|
30
|
-
minWidth: 40,
|
|
19
|
+
function formatSourceLabel(source: ProjectPreview['source']): string {
|
|
20
|
+
switch (source) {
|
|
21
|
+
case 'project':
|
|
22
|
+
return 'Project Rule'
|
|
23
|
+
case 'wildcard':
|
|
24
|
+
return 'Wildcard Rule'
|
|
25
|
+
case 'default':
|
|
26
|
+
return 'Default Rule'
|
|
31
27
|
}
|
|
28
|
+
}
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
<text style={{ fg: colors.
|
|
30
|
+
function ProjectPreviewView({ preview }: { preview: ProjectPreview }) {
|
|
31
|
+
return (
|
|
32
|
+
<>
|
|
33
|
+
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
34
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{preview.sessionName}</text>
|
|
38
35
|
</box>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
36
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
<text style={{ fg: colors.
|
|
37
|
+
<box style={{ flexDirection: 'column', marginBottom: 1, marginLeft: 2 }}>
|
|
38
|
+
<text>
|
|
39
|
+
Source: <span style={{ fg: colors.action }}>{formatSourceLabel(preview.source)}</span>
|
|
40
|
+
</text>
|
|
41
|
+
<text style={{ fg: colors.fileTree, marginTop: 1 }}>{preview.path}</text>
|
|
42
|
+
{preview.gitRoot && preview.gitRoot !== preview.path && (
|
|
43
|
+
<text>
|
|
44
|
+
Git Root: <span style={{ fg: colors.fileTree }}>{preview.gitRoot}</span>
|
|
45
|
+
</text>
|
|
46
|
+
)}
|
|
47
|
+
{preview.gitBranch && (
|
|
48
|
+
<text>
|
|
49
|
+
Branch: <span style={{ fg: colors.active }}>{preview.gitBranch}</span>
|
|
50
|
+
</text>
|
|
51
|
+
)}
|
|
52
|
+
{preview.startupCommand && (
|
|
53
|
+
<text style={{ marginTop: 1 }}>
|
|
54
|
+
Startup: <span style={{ fg: colors.program }}>{preview.startupCommand}</span>
|
|
55
|
+
</text>
|
|
56
|
+
)}
|
|
57
|
+
{preview.previewCommand && (
|
|
58
|
+
<text>
|
|
59
|
+
Preview Cmd: <span style={{ fg: colors.action }}>{preview.previewCommand}</span>
|
|
60
|
+
</text>
|
|
61
|
+
)}
|
|
47
62
|
</box>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
{preview.linkedSession && (
|
|
65
|
+
<>
|
|
66
|
+
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
67
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}> Live Session</text>
|
|
68
|
+
</box>
|
|
69
|
+
|
|
70
|
+
<box style={{ flexDirection: 'column', marginBottom: 1, marginLeft: 2 }}>
|
|
71
|
+
<text>
|
|
72
|
+
Status:{' '}
|
|
73
|
+
<span style={{ fg: preview.linkedSession.isAttached ? colors.active : colors.inactive }}>
|
|
74
|
+
{preview.linkedSession.isAttached ? '● Attached' : '○ Detached'}
|
|
75
|
+
</span>
|
|
76
|
+
</text>
|
|
77
|
+
<text>Windows: {preview.linkedSession.windowCount}</text>
|
|
78
|
+
{preview.linkedSession.windows.slice(0, 4).map(window => (
|
|
79
|
+
<text key={`${window.index}:${window.name}`} style={{ marginLeft: 2, fg: colors.inactive }}>
|
|
80
|
+
{window.index}: {window.name}
|
|
81
|
+
</text>
|
|
82
|
+
))}
|
|
83
|
+
</box>
|
|
84
|
+
</>
|
|
85
|
+
)}
|
|
86
|
+
|
|
87
|
+
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
88
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}> {preview.previewLabel}</text>
|
|
56
89
|
</box>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
90
|
|
|
91
|
+
<box style={{ flexDirection: 'column', marginLeft: 2 }}>
|
|
92
|
+
{preview.previewNotice && (
|
|
93
|
+
<text style={{ fg: colors.inactive, marginBottom: 1 }}>{preview.previewNotice}</text>
|
|
94
|
+
)}
|
|
95
|
+
{preview.previewLines.map((line, index) => (
|
|
96
|
+
<text
|
|
97
|
+
key={`${preview.previewKind}:${index}:${line}`}
|
|
98
|
+
style={{
|
|
99
|
+
fg: preview.previewKind === 'directory' && line.endsWith('/') ? colors.fileTree : colors.text,
|
|
100
|
+
marginBottom: 1,
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{line}
|
|
104
|
+
</text>
|
|
105
|
+
))}
|
|
106
|
+
</box>
|
|
107
|
+
</>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function SessionDetailsView({ details }: { details: SessionDetails }) {
|
|
60
112
|
return (
|
|
61
|
-
|
|
113
|
+
<>
|
|
62
114
|
<box style={{ alignItems: 'center', justifyContent: 'center' }}>
|
|
63
115
|
<text style={{ fg: colors.primary, marginBottom: 1 }}>{details.name}</text>
|
|
64
116
|
</box>
|
|
@@ -81,8 +133,8 @@ export default function SessionDetailsPanel({ selectedItem }: Props) {
|
|
|
81
133
|
{details.windows.length === 0 ? (
|
|
82
134
|
<text style={{ fg: colors.inactive }}>No windows found</text>
|
|
83
135
|
) : (
|
|
84
|
-
details.windows.map(
|
|
85
|
-
<box key={
|
|
136
|
+
details.windows.map(win => (
|
|
137
|
+
<box key={`${win.index}:${win.name}`} style={{ flexDirection: 'column', marginBottom: 1 }}>
|
|
86
138
|
<text>
|
|
87
139
|
{win.index}: {win.name}
|
|
88
140
|
</text>
|
|
@@ -96,6 +148,88 @@ export default function SessionDetailsPanel({ selectedItem }: Props) {
|
|
|
96
148
|
))
|
|
97
149
|
)}
|
|
98
150
|
</box>
|
|
151
|
+
</>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default function SessionDetailsPanel({ selectedItem, config }: Props) {
|
|
156
|
+
const [detailState, setDetailState] = useState<DetailState>({ status: 'idle' })
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
let cancelled = false
|
|
160
|
+
|
|
161
|
+
async function loadDetails() {
|
|
162
|
+
if (!selectedItem) {
|
|
163
|
+
setDetailState({ status: 'idle' })
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
setDetailState({ status: 'loading' })
|
|
168
|
+
|
|
169
|
+
try {
|
|
170
|
+
if (selectedItem.isSession) {
|
|
171
|
+
const details = await getSessionDetails(selectedItem.title)
|
|
172
|
+
if (!cancelled) {
|
|
173
|
+
setDetailState({ status: 'session', details })
|
|
174
|
+
}
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!config) {
|
|
179
|
+
if (!cancelled) {
|
|
180
|
+
setDetailState({ status: 'error', message: 'Config is not loaded yet' })
|
|
181
|
+
}
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const details = await getProjectPreview(selectedItem.path, config, selectedItem.linkedSessionName)
|
|
186
|
+
if (!cancelled) {
|
|
187
|
+
setDetailState({ status: 'project', details })
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
const message = error instanceof Error ? error.message : 'Unable to load details'
|
|
191
|
+
if (!cancelled) {
|
|
192
|
+
setDetailState({ status: 'error', message })
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
void loadDetails()
|
|
198
|
+
|
|
199
|
+
return () => {
|
|
200
|
+
cancelled = true
|
|
201
|
+
}
|
|
202
|
+
}, [config, selectedItem])
|
|
203
|
+
|
|
204
|
+
const panelStyle = {
|
|
205
|
+
...detailPanelStyle,
|
|
206
|
+
flexGrow: 1,
|
|
207
|
+
flexShrink: 1,
|
|
208
|
+
minWidth: 40,
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<box style={panelStyle}>
|
|
213
|
+
{detailState.status === 'idle' ? (
|
|
214
|
+
<>
|
|
215
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>Details</text>
|
|
216
|
+
<text style={{ fg: colors.inactive }}>No session or project selected</text>
|
|
217
|
+
</>
|
|
218
|
+
) : detailState.status === 'loading' ? (
|
|
219
|
+
<>
|
|
220
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{selectedItem?.title ?? 'Details'}</text>
|
|
221
|
+
<text style={{ fg: colors.inactive }}>Loading...</text>
|
|
222
|
+
</>
|
|
223
|
+
) : detailState.status === 'error' ? (
|
|
224
|
+
<>
|
|
225
|
+
<text style={{ fg: colors.primary, marginBottom: 1 }}>{selectedItem?.title ?? 'Details'}</text>
|
|
226
|
+
<text style={{ fg: colors.action }}>{detailState.message}</text>
|
|
227
|
+
</>
|
|
228
|
+
) : detailState.status === 'session' ? (
|
|
229
|
+
<SessionDetailsView details={detailState.details} />
|
|
230
|
+
) : (
|
|
231
|
+
<ProjectPreviewView preview={detailState.details} />
|
|
232
|
+
)}
|
|
99
233
|
</box>
|
|
100
234
|
)
|
|
101
235
|
}
|
package/src/ui/SessionList.tsx
CHANGED
|
@@ -1,54 +1,88 @@
|
|
|
1
1
|
import { colors } from '../styles/theme'
|
|
2
2
|
import { formatSessionAge } from '../util/time'
|
|
3
|
+
import type { IconConfig, Item } from '../types'
|
|
4
|
+
import { getSessionSection } from '../items/order'
|
|
3
5
|
import HighlightedText from './HighlightedText'
|
|
4
|
-
import
|
|
6
|
+
import { formatSectionHeader, getItemIconPresentation } from './item-icon'
|
|
7
|
+
import { getVisibleWindow } from './list-window'
|
|
5
8
|
|
|
6
9
|
interface Props {
|
|
7
10
|
items: Item[]
|
|
8
11
|
cursor: number
|
|
9
12
|
maxItems?: number
|
|
10
13
|
searchQuery?: string
|
|
14
|
+
icons?: IconConfig
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export default function SessionList({ items, cursor, maxItems = 20, searchQuery = '' }: Props) {
|
|
17
|
+
export default function SessionList({ items, cursor, maxItems = 20, searchQuery = '', icons }: Props) {
|
|
14
18
|
const isSearching = searchQuery.trim().length > 0
|
|
19
|
+
const visibleWindow = getVisibleWindow(items, cursor, maxItems)
|
|
15
20
|
|
|
16
21
|
return (
|
|
17
22
|
<>
|
|
18
|
-
{items.
|
|
19
|
-
const
|
|
23
|
+
{visibleWindow.items.map((item, i) => {
|
|
24
|
+
const absoluteIndex = visibleWindow.startIndex + i
|
|
25
|
+
const matchIndices = item.searchMatch?.titleIndices
|
|
20
26
|
const titlePadded = item.title.padEnd(20)
|
|
21
|
-
const
|
|
27
|
+
const itemMeta = item.isSession
|
|
28
|
+
? item.createdAt
|
|
29
|
+
? formatSessionAge(item.createdAt)
|
|
30
|
+
: ''
|
|
31
|
+
: item.desc
|
|
32
|
+
const icon = getItemIconPresentation(item, icons)
|
|
33
|
+
const currentSection = getSessionSection(item)
|
|
34
|
+
const previousItem = absoluteIndex > 0 ? items[absoluteIndex - 1] : undefined
|
|
35
|
+
const previousSection = previousItem ? getSessionSection(previousItem) : undefined
|
|
36
|
+
const showSectionHeader = i === 0 || currentSection !== previousSection
|
|
37
|
+
const sectionHeader = formatSectionHeader(currentSection, icons)
|
|
22
38
|
|
|
23
39
|
return (
|
|
24
|
-
<box
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{item.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
<box key={i} style={{ flexDirection: 'column' }}>
|
|
41
|
+
{showSectionHeader && (
|
|
42
|
+
<text style={{ fg: colors.separator, marginTop: absoluteIndex === 0 ? 0 : 1, marginBottom: 1 }}>
|
|
43
|
+
<span style={{ fg: sectionHeader.color }}>{sectionHeader.text}</span>
|
|
44
|
+
</text>
|
|
45
|
+
)}
|
|
46
|
+
<box
|
|
47
|
+
style={{
|
|
48
|
+
backgroundColor: absoluteIndex === cursor ? colors.backgroundAlt : 'transparent',
|
|
49
|
+
height: 1,
|
|
50
|
+
paddingLeft: 2,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{absoluteIndex === cursor && <text> </text>}
|
|
54
|
+
<text>
|
|
55
|
+
{absoluteIndex + 1}{' '}
|
|
56
|
+
{item.isSession ? (
|
|
57
|
+
<>
|
|
58
|
+
<span style={{ fg: item.isAttached ? colors.active : colors.inactive }}>
|
|
59
|
+
{item.isAttached ? '●' : '○'}
|
|
60
|
+
</span>{' '}
|
|
61
|
+
{isSearching && matchIndices && matchIndices.length > 0 ? (
|
|
62
|
+
<>
|
|
63
|
+
<HighlightedText text={item.title} matchIndices={matchIndices} />
|
|
64
|
+
{' '.repeat(20 - item.title.length)}
|
|
65
|
+
</>
|
|
66
|
+
) : (
|
|
67
|
+
titlePadded
|
|
68
|
+
)}{' '}
|
|
69
|
+
</>
|
|
70
|
+
) : (
|
|
71
|
+
<>
|
|
72
|
+
<span style={{ fg: icon.color }}>{icon.glyph}</span>{' '}
|
|
73
|
+
{isSearching && matchIndices && matchIndices.length > 0 ? (
|
|
74
|
+
<>
|
|
75
|
+
<HighlightedText text={item.title} matchIndices={matchIndices} />
|
|
76
|
+
{' '.repeat(20 - item.title.length)}
|
|
77
|
+
</>
|
|
78
|
+
) : (
|
|
79
|
+
titlePadded
|
|
80
|
+
)}{' '}
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
83
|
+
<span style={{ fg: colors.inactive }}>{itemMeta}</span>
|
|
84
|
+
</text>
|
|
85
|
+
</box>
|
|
52
86
|
</box>
|
|
53
87
|
)
|
|
54
88
|
})}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { colors } from '../styles/theme'
|
|
2
|
+
import type { IconConfig, Item } from '../types'
|
|
3
|
+
|
|
4
|
+
export interface ItemIconPresentation {
|
|
5
|
+
glyph: string
|
|
6
|
+
color: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getIconConfig(icons?: IconConfig): IconConfig {
|
|
10
|
+
return {
|
|
11
|
+
tmux: icons?.tmux ?? '',
|
|
12
|
+
configured: icons?.configured ?? '',
|
|
13
|
+
project: icons?.project ?? '',
|
|
14
|
+
opencode: icons?.opencode ?? '',
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getItemIconPresentation(item: Item, icons?: IconConfig): ItemIconPresentation {
|
|
19
|
+
const resolvedIcons = getIconConfig(icons)
|
|
20
|
+
|
|
21
|
+
if (item.itemKind === 'configured') {
|
|
22
|
+
return {
|
|
23
|
+
glyph: item.icon ?? resolvedIcons.configured,
|
|
24
|
+
color: colors.action,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (item.isSession) {
|
|
29
|
+
return {
|
|
30
|
+
glyph:
|
|
31
|
+
item.icon ??
|
|
32
|
+
(item.title.startsWith('opencode-') ? resolvedIcons.opencode : resolvedIcons.tmux),
|
|
33
|
+
color: item.isAttached ? colors.active : colors.inactive,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (item.linkedSessionName) {
|
|
38
|
+
return {
|
|
39
|
+
glyph: resolvedIcons.tmux,
|
|
40
|
+
color: item.linkedSessionAttached ? colors.active : colors.inactive,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
glyph: item.icon ?? resolvedIcons.project,
|
|
46
|
+
color: colors.fileTree,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getSessionSectionPresentation(
|
|
51
|
+
section: 'live' | 'configured' | 'opencode',
|
|
52
|
+
icons?: IconConfig
|
|
53
|
+
): ItemIconPresentation & { label: string } {
|
|
54
|
+
const resolvedIcons = getIconConfig(icons)
|
|
55
|
+
|
|
56
|
+
switch (section) {
|
|
57
|
+
case 'configured':
|
|
58
|
+
return { glyph: resolvedIcons.configured, color: colors.action, label: 'Configured Sessions' }
|
|
59
|
+
case 'opencode':
|
|
60
|
+
return { glyph: resolvedIcons.opencode, color: colors.action, label: 'Opencode Sessions' }
|
|
61
|
+
case 'live':
|
|
62
|
+
return { glyph: resolvedIcons.tmux, color: colors.inactive, label: 'Live Sessions' }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function formatSectionHeader(
|
|
67
|
+
section: 'live' | 'configured' | 'opencode',
|
|
68
|
+
icons?: IconConfig
|
|
69
|
+
): ItemIconPresentation & { text: string } {
|
|
70
|
+
const presentation = getSessionSectionPresentation(section, icons)
|
|
71
|
+
const prefix = presentation.glyph.length > 0 ? `${presentation.glyph} ` : ''
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
...presentation,
|
|
75
|
+
text: `─ ${prefix}${presentation.label} ─`,
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface VisibleWindow<T> {
|
|
2
|
+
items: T[]
|
|
3
|
+
startIndex: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function getVisibleWindow<T>(items: T[], cursor: number, maxItems: number): VisibleWindow<T> {
|
|
7
|
+
if (items.length === 0) {
|
|
8
|
+
return {
|
|
9
|
+
items: [],
|
|
10
|
+
startIndex: 0,
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const visibleCount = Math.max(1, Math.min(maxItems, items.length))
|
|
15
|
+
const maxStartIndex = Math.max(0, items.length - visibleCount)
|
|
16
|
+
const startIndex = Math.min(Math.max(0, cursor - Math.floor(visibleCount / 2)), maxStartIndex)
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
items: items.slice(startIndex, startIndex + visibleCount),
|
|
20
|
+
startIndex,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import { spawn } from 'bun'
|
|
2
1
|
import type { InstallMethod } from '../types'
|
|
3
2
|
|
|
4
3
|
export async function detectInstallMethod(): Promise<InstallMethod> {
|
|
5
|
-
const execPath = process.execPath.toLowerCase()
|
|
6
|
-
|
|
7
4
|
const checks = [
|
|
8
5
|
{
|
|
9
6
|
name: 'npm' as const,
|
|
10
|
-
command: () => spawn(['npm', 'list', '-g', '--depth=0']),
|
|
7
|
+
command: () => Bun.spawn(['npm', 'list', '-g', '--depth=0']),
|
|
11
8
|
},
|
|
12
9
|
{
|
|
13
10
|
name: 'bun' as const,
|
|
14
|
-
command: () => spawn(['bun', 'pm', 'ls', '-g']),
|
|
11
|
+
command: () => Bun.spawn(['bun', 'pm', 'ls', '-g']),
|
|
15
12
|
},
|
|
16
13
|
{
|
|
17
14
|
name: 'brew' as const,
|
|
18
|
-
command: () => spawn(['brew', 'list', '--formula']),
|
|
15
|
+
command: () => Bun.spawn(['brew', 'list', '--formula']),
|
|
19
16
|
},
|
|
20
17
|
]
|
|
21
18
|
|
|
22
|
-
checks.sort((a, b) => {
|
|
23
|
-
const aMatch = execPath.includes(a.name)
|
|
24
|
-
const bMatch = execPath.includes(b.name)
|
|
25
|
-
if (aMatch && !bMatch) return -1
|
|
26
|
-
if (!aMatch && bMatch) return 1
|
|
27
|
-
return 0
|
|
28
|
-
})
|
|
29
|
-
|
|
30
19
|
for (const check of checks) {
|
|
31
20
|
try {
|
|
32
21
|
const proc = check.command()
|
|
@@ -62,7 +51,7 @@ export async function performUpgrade(
|
|
|
62
51
|
break
|
|
63
52
|
}
|
|
64
53
|
try {
|
|
65
|
-
const proc = spawn(command)
|
|
54
|
+
const proc = Bun.spawn(command)
|
|
66
55
|
await proc.exited
|
|
67
56
|
return proc.exitCode === 0
|
|
68
57
|
} catch (error) {
|
package/src/update/version.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import packageJson from '../../package.json'
|
|
2
2
|
|
|
3
3
|
export const CURRENT_VERSION = packageJson.version
|
|
4
|
+
const PACKAGE_NAME = packageJson.name
|
|
4
5
|
|
|
5
6
|
export async function getLatestVersion(): Promise<string | null> {
|
|
6
7
|
try {
|
|
7
|
-
const response = await fetch(
|
|
8
|
+
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`)
|
|
8
9
|
|
|
9
10
|
if (!response.ok) {
|
|
10
11
|
throw new Error(`HTTP error! status: ${response.status}`)
|
package/src/util/glob.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface MatchGlobOptions {
|
|
2
|
+
pathSeparatorAware?: boolean
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function escapeRegexCharacter(value: string): string {
|
|
6
|
+
return /[|\\{}()[\]^$+?.]/.test(value) ? `\\${value}` : value
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function normalizePathForMatching(value: string): string {
|
|
10
|
+
return value.replaceAll('\\', '/').replace(/\/+/g, '/').replace(/\/$/, '') || '/'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function globToRegExp(pattern: string, options: MatchGlobOptions = {}): RegExp {
|
|
14
|
+
const { pathSeparatorAware = false } = options
|
|
15
|
+
let regex = '^'
|
|
16
|
+
|
|
17
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
18
|
+
const char = pattern[index]
|
|
19
|
+
const next = pattern[index + 1]
|
|
20
|
+
|
|
21
|
+
if (char === '*' && next === '*') {
|
|
22
|
+
regex += '.*'
|
|
23
|
+
index += 1
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (char === '*') {
|
|
28
|
+
regex += pathSeparatorAware ? '[^/]*' : '.*'
|
|
29
|
+
continue
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (char === '?') {
|
|
33
|
+
regex += pathSeparatorAware ? '[^/]' : '.'
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
regex += escapeRegexCharacter(char)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
regex += '$'
|
|
41
|
+
|
|
42
|
+
return new RegExp(regex)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function matchesGlob(value: string, pattern: string, options: MatchGlobOptions = {}): boolean {
|
|
46
|
+
return globToRegExp(pattern, options).test(value)
|
|
47
|
+
}
|
package/src/util/terminal.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useTerminalDimensions } from '@opentui/react'
|
|
2
2
|
|
|
3
3
|
export interface TerminalSize {
|
|
4
4
|
columns: number
|
|
@@ -8,26 +8,12 @@ export interface TerminalSize {
|
|
|
8
8
|
export type LayoutMode = 'compact' | 'normal' | 'wide'
|
|
9
9
|
|
|
10
10
|
export function useTerminalSize(): TerminalSize {
|
|
11
|
-
const
|
|
12
|
-
columns: process.stdout.columns || 80,
|
|
13
|
-
rows: process.stdout.rows || 24,
|
|
14
|
-
})
|
|
11
|
+
const { width, height } = useTerminalDimensions()
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rows: process.stdout.rows || 24,
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
process.stdout.on('resize', handler)
|
|
25
|
-
return () => {
|
|
26
|
-
process.stdout.off('resize', handler)
|
|
27
|
-
}
|
|
28
|
-
}, [])
|
|
29
|
-
|
|
30
|
-
return size
|
|
13
|
+
return {
|
|
14
|
+
columns: width,
|
|
15
|
+
rows: height,
|
|
16
|
+
}
|
|
31
17
|
}
|
|
32
18
|
|
|
33
19
|
export function getLayoutMode(columns: number): LayoutMode {
|