-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.tsx
More file actions
225 lines (207 loc) · 6.49 KB
/
Copy pathMainMenu.tsx
File metadata and controls
225 lines (207 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import React from "react";
import { Box, Text, useInput, useApp } from "ink";
import figures from "figures";
import { Banner } from "./Banner.js";
import { Breadcrumb } from "./Breadcrumb.js";
import { VERSION } from "../version.js";
import { colors } from "../utils/theme.js";
import { execCommand } from "../utils/exec.js";
import { useViewportHeight } from "../hooks/useViewportHeight.js";
import { useExitOnCtrlC } from "../hooks/useExitOnCtrlC.js";
import { useUpdateCheck } from "../hooks/useUpdateCheck.js";
interface MenuItem {
key: string;
label: string;
description: string;
icon: string;
color: string;
}
const menuItems: MenuItem[] = [
{
key: "devboxes",
label: "Devboxes",
description: "Manage cloud development environments",
icon: "◉",
color: colors.accent1,
},
{
key: "blueprints",
label: "Blueprints",
description: "Create and manage devbox templates",
icon: "▣",
color: colors.accent2,
},
{
key: "snapshots",
label: "Snapshots",
description: "Save and restore devbox states",
icon: "◈",
color: colors.accent3,
},
];
interface MainMenuProps {
onSelect: (key: string) => void;
}
export const MainMenu = ({ onSelect }: MainMenuProps) => {
const { exit } = useApp();
const [selectedIndex, setSelectedIndex] = React.useState(0);
// Use centralized viewport hook for consistent layout
const { terminalHeight } = useViewportHeight({ overhead: 0 });
// Check for updates
const { updateAvailable } = useUpdateCheck();
// Handle Ctrl+C to exit
useExitOnCtrlC();
useInput((input, key) => {
if (key.upArrow && selectedIndex > 0) {
setSelectedIndex(selectedIndex - 1);
} else if (key.downArrow && selectedIndex < menuItems.length - 1) {
setSelectedIndex(selectedIndex + 1);
} else if (key.return) {
onSelect(menuItems[selectedIndex].key);
} else if (key.escape) {
exit();
} else if (input === "d" || input === "1") {
onSelect("devboxes");
} else if (input === "b" || input === "2") {
onSelect("blueprints");
} else if (input === "s" || input === "3") {
onSelect("snapshots");
} else if (input === "u" && updateAvailable) {
// Release terminal and exec into update command (never returns)
execCommand("sh", [
"-c",
"npm install -g @runloop/rl-cli@latest && exec rli",
]);
}
});
// Use compact layout if terminal height is less than 20 lines (memoized)
const useCompactLayout = terminalHeight < 20;
if (useCompactLayout) {
return (
<Box flexDirection="column">
<Box paddingX={2} marginBottom={1}>
<Text color={colors.primary} bold>
RUNLOOP.ai
</Text>
<Text color={colors.textDim} dimColor>
{" "}
• Cloud development environments • v{VERSION}
</Text>
</Box>
<Box flexDirection="column" paddingX={2}>
{menuItems.map((item, index) => {
const isSelected = index === selectedIndex;
return (
<Box key={item.key} marginBottom={0}>
<Text color={isSelected ? item.color : colors.textDim}>
{isSelected ? figures.pointer : " "}
</Text>
<Text> </Text>
<Text color={item.color} bold>
{item.icon}
</Text>
<Text> </Text>
<Text
color={isSelected ? item.color : colors.text}
bold={isSelected}
>
{item.label}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
- {item.description}
</Text>
<Text color={colors.textDim} dimColor>
{" "}
[{index + 1}]
</Text>
</Box>
);
})}
</Box>
<Box paddingX={2} marginTop={1}>
<Text color={colors.textDim} dimColor>
{figures.arrowUp}
{figures.arrowDown} Navigate • [1-3] Quick select • [Enter] Select •
[Esc] Quit
{updateAvailable && " • [u] Update"}
</Text>
</Box>
</Box>
);
}
return (
<Box flexDirection="column">
<Breadcrumb
items={[{ label: "Home", active: true }]}
showVersionCheck={true}
/>
<Banner />
<Box flexDirection="column" paddingX={2} flexShrink={0}>
<Box paddingX={1}>
<Text color={colors.textDim} dimColor>
Cloud development environments for your team • v{VERSION}
</Text>
</Box>
</Box>
<Box flexDirection="column" paddingX={2} marginTop={1} flexGrow={1}>
<Box paddingX={1} flexShrink={0}>
<Text color={colors.text} bold>
Select a resource:
</Text>
</Box>
{menuItems.map((item, index) => {
const isSelected = index === selectedIndex;
return (
<Box
key={item.key}
paddingX={2}
paddingY={0}
borderStyle="single"
borderColor={isSelected ? item.color : colors.border}
marginTop={index === 0 ? 1 : 0}
flexShrink={0}
>
{isSelected && (
<>
<Text color={item.color} bold>
{figures.pointer}
</Text>
<Text> </Text>
</>
)}
<Text color={item.color} bold>
{item.icon}
</Text>
<Text> </Text>
<Text
color={isSelected ? item.color : colors.text}
bold={isSelected}
>
{item.label}
</Text>
<Text color={colors.textDim}> </Text>
<Text color={colors.textDim} dimColor>
{item.description}
</Text>
<Text> </Text>
<Text color={colors.textDim} dimColor>
[{index + 1}]
</Text>
</Box>
);
})}
</Box>
<Box paddingX={2} flexShrink={0}>
<Box paddingX={1}>
<Text color={colors.textDim} dimColor>
{figures.arrowUp}
{figures.arrowDown} Navigate • [1-3] Quick select • [Enter] Select •
[Esc] Quit
{updateAvailable && " • [u] Update"}
</Text>
</Box>
</Box>
</Box>
);
};