create-skaff 0.0.3 → 0.0.4
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/package.json
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useKeyboard } from "@opentui/react";
|
|
2
|
+
import { useState } from "react";
|
|
2
3
|
import { type PackageManager, packageManagers } from "../lib/package-manager";
|
|
3
4
|
|
|
4
|
-
type PackageManagerPromptProps = { onSelect: (packageManager: PackageManager) => void };
|
|
5
|
+
type PackageManagerPromptProps = { initialValue: PackageManager; onSelect: (packageManager: PackageManager) => void };
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
export function PackageManagerPrompt({ initialValue, onSelect }: PackageManagerPromptProps) {
|
|
8
|
+
const [index, setIndex] = useState(Math.max(0, packageManagers.indexOf(initialValue)));
|
|
9
|
+
|
|
10
|
+
useKeyboard((key) => {
|
|
11
|
+
if (key.name === "up" || key.name === "k") {
|
|
12
|
+
setIndex((current) => (current + packageManagers.length - 1) % packageManagers.length);
|
|
13
|
+
} else if (key.name === "down" || key.name === "j") {
|
|
14
|
+
setIndex((current) => (current + 1) % packageManagers.length);
|
|
15
|
+
} else if (key.name === "return") {
|
|
16
|
+
onSelect(packageManagers[index]);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
7
19
|
|
|
8
|
-
export function PackageManagerPrompt({ onSelect }: PackageManagerPromptProps) {
|
|
9
20
|
return (
|
|
10
21
|
<box flexDirection="column">
|
|
11
22
|
<text>
|
|
12
23
|
<span fg="#a78bfa">◆</span> <strong>Package manager</strong>
|
|
13
24
|
</text>
|
|
14
|
-
|
|
15
|
-
<text
|
|
16
|
-
|
|
17
|
-
<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
selectedIndex={1}
|
|
22
|
-
onSelect={(_index, option) => {
|
|
23
|
-
if (option && packageManagers.includes(option.value as PackageManager)) {
|
|
24
|
-
onSelect(option.value as PackageManager);
|
|
25
|
-
}
|
|
26
|
-
}}
|
|
27
|
-
/>
|
|
28
|
-
</box>
|
|
29
|
-
</box>
|
|
25
|
+
{packageManagers.map((value, i) => (
|
|
26
|
+
<text key={value}>
|
|
27
|
+
<span fg="#a78bfa">│ </span>
|
|
28
|
+
{i === index ? <span fg="#4ade80">◉ </span> : <span fg="#555555">○ </span>}
|
|
29
|
+
<span fg={i === index ? "#ffffff" : "#888888"}>{value}</span>
|
|
30
|
+
</text>
|
|
31
|
+
))}
|
|
30
32
|
<text>
|
|
31
33
|
<span fg="#a78bfa">│ </span>
|
|
32
34
|
<span fg="#666666">↑↓ to move · Enter to continue · Esc to go back</span>
|