@semos-labs/create-glyph 0.1.74 → 0.1.76
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/dist/index.js +25 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ function templateTsconfig() {
|
|
|
95
95
|
}
|
|
96
96
|
function templateMainTsx(name) {
|
|
97
97
|
const displayName = name.replace(/[-_]/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
|
|
98
|
-
return `import React, { useState, useCallback } from "react";
|
|
98
|
+
return `import React, { useState, useCallback, useRef } from "react";
|
|
99
99
|
import {
|
|
100
100
|
render,
|
|
101
101
|
Box,
|
|
@@ -108,6 +108,7 @@ import {
|
|
|
108
108
|
Spacer,
|
|
109
109
|
useApp,
|
|
110
110
|
} from "@semos-labs/glyph";
|
|
111
|
+
import type { Key, InputHandle } from "@semos-labs/glyph";
|
|
111
112
|
|
|
112
113
|
// \u2500\u2500 Types \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
113
114
|
|
|
@@ -123,6 +124,7 @@ let nextId = 1;
|
|
|
123
124
|
|
|
124
125
|
function App() {
|
|
125
126
|
const { exit } = useApp();
|
|
127
|
+
const inputRef = useRef<InputHandle>(null);
|
|
126
128
|
|
|
127
129
|
const [todos, setTodos] = useState<Todo[]>([
|
|
128
130
|
{ id: nextId++, text: "Learn Glyph basics", done: true },
|
|
@@ -139,8 +141,20 @@ function App() {
|
|
|
139
141
|
if (!text) return;
|
|
140
142
|
setTodos((prev) => [...prev, { id: nextId++, text, done: false }]);
|
|
141
143
|
setNewTodo("");
|
|
144
|
+
// Re-focus the input after adding
|
|
145
|
+
setTimeout(() => inputRef.current?.focus(), 0);
|
|
142
146
|
}, [newTodo]);
|
|
143
147
|
|
|
148
|
+
const handleInputKey = useCallback(
|
|
149
|
+
(key: Key) => {
|
|
150
|
+
if (key.name === "return") {
|
|
151
|
+
handleAdd();
|
|
152
|
+
return true; // Consume the key
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
[handleAdd],
|
|
156
|
+
);
|
|
157
|
+
|
|
144
158
|
const handleToggle = useCallback((id: number) => {
|
|
145
159
|
setTodos((prev) =>
|
|
146
160
|
prev.map((t) => (t.id === id ? { ...t, done: !t.done } : t)),
|
|
@@ -180,19 +194,20 @@ function App() {
|
|
|
180
194
|
<Box style={{ flexDirection: "row", gap: 1 }}>
|
|
181
195
|
<Box style={{ flexGrow: 1 }}>
|
|
182
196
|
<Input
|
|
197
|
+
ref={inputRef}
|
|
183
198
|
value={newTodo}
|
|
184
199
|
onChange={setNewTodo}
|
|
200
|
+
onKeyPress={handleInputKey}
|
|
185
201
|
placeholder="What needs to be done?"
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
focusedStyle={{ bg: "white", color: "black", paddingX: 1 }}
|
|
202
|
+
style={{ border: "round", borderColor: "blackBright", paddingX: 1 }}
|
|
203
|
+
focusedStyle={{ border: "round", borderColor: "cyan", color: "white", paddingX: 1 }}
|
|
189
204
|
/>
|
|
190
205
|
</Box>
|
|
191
206
|
<Button
|
|
192
207
|
label=" add "
|
|
193
208
|
onPress={handleAdd}
|
|
194
|
-
style={{
|
|
195
|
-
focusedStyle={{ bg: "cyan", color: "black", paddingX: 1 }}
|
|
209
|
+
style={{ border: "round", borderColor: "blackBright", paddingX: 1 }}
|
|
210
|
+
focusedStyle={{ border: "round", borderColor: "cyan", bg: "cyan", color: "black", paddingX: 1 }}
|
|
196
211
|
/>
|
|
197
212
|
</Box>
|
|
198
213
|
|
|
@@ -207,15 +222,15 @@ function App() {
|
|
|
207
222
|
checked={todo.done}
|
|
208
223
|
onChange={() => handleToggle(todo.id)}
|
|
209
224
|
label={todo.text}
|
|
210
|
-
style={todo.done ? { dim: true } : {}}
|
|
225
|
+
style={todo.done ? { dim: true, color: "blackBright" } : { color: "white" }}
|
|
211
226
|
focusedStyle={{ color: "cyanBright" }}
|
|
212
227
|
/>
|
|
213
228
|
<Spacer />
|
|
214
229
|
<Button
|
|
215
230
|
label=" \xD7 "
|
|
216
231
|
onPress={() => handleDelete(todo.id)}
|
|
217
|
-
style={{
|
|
218
|
-
focusedStyle={{ color: "
|
|
232
|
+
style={{ color: "blackBright" }}
|
|
233
|
+
focusedStyle={{ color: "redBright" }}
|
|
219
234
|
/>
|
|
220
235
|
</Box>
|
|
221
236
|
))}
|
|
@@ -224,7 +239,7 @@ function App() {
|
|
|
224
239
|
{/* Footer */}
|
|
225
240
|
<Spacer />
|
|
226
241
|
<Text style={{ dim: true }}>
|
|
227
|
-
tab navigate \xB7 space toggle \xB7 enter
|
|
242
|
+
tab navigate \xB7 space toggle \xB7 enter add \xB7 q quit
|
|
228
243
|
</Text>
|
|
229
244
|
</Box>
|
|
230
245
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semos-labs/create-glyph",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.76",
|
|
4
4
|
"description": "Scaffold a new Glyph terminal UI app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/
|
|
34
|
+
"url": "git+https://github.com/semos-labs/glyph.git"
|
|
35
35
|
}
|
|
36
36
|
}
|