Skip to content

Commit 86c0aae

Browse files
committed
improve spinner & task management
1 parent 6eed31c commit 86c0aae

64 files changed

Lines changed: 2060 additions & 720 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 136 additions & 151 deletions
Large diffs are not rendered by default.

bun.lockb

13.9 KB
Binary file not shown.

cspell.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"ignorePaths": ["examples/deprecated", "dist-jsr", "dist-npm"],
66
"words": [
77
"alacritty",
8+
"alcalzone",
89
"alternar",
910
"anims",
1011
"anykey",
@@ -18,6 +19,7 @@
1819
"ausgewählt",
1920
"avez",
2021
"Baratheon",
22+
"bitflag",
2123
"blefnk",
2224
"browserlist",
2325
"browserlistrc",
@@ -54,13 +56,16 @@
5456
"figliolia",
5557
"Fireship",
5658
"Focusable",
59+
"focusables",
5760
"forgetme",
61+
"Gawf",
5862
"Geralt",
5963
"goroutines",
6064
"Greyjoy",
6165
"Gyllenhaal",
6266
"haben",
6367
"Haha",
68+
"hotmail",
6469
"hoverable",
6570
"iife",
6671
"invertir",
@@ -105,15 +110,19 @@
105110
"sbuf",
106111
"scelto",
107112
"scule",
113+
"segs",
108114
"selección",
109115
"seleccionar",
110116
"sentencer",
111117
"shadcn",
118+
"shoutout",
112119
"signup",
113120
"Silverhand",
114121
"sisteransi",
122+
"Speedrun",
115123
"Sprache",
116124
"subchoices",
125+
"suped",
117126
"Targ",
118127
"Targaryen",
119128
"terkelg",
@@ -126,13 +135,16 @@
126135
"typesafety",
127136
"typestat",
128137
"Tyrell",
138+
"unclip",
129139
"unjs",
130140
"unpub",
131141
"unstub",
132142
"valign",
143+
"valtio",
133144
"venv",
134145
"Vous",
135146
"vsprintf",
147+
"WCAG",
136148
"wezterm",
137149
"Whoo",
138150
"Wybrałeś",

example.png

-59.8 KB
Binary file not shown.

examples/launcher.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,81 @@ async function examplesRunner() {
99

1010
const exampleToRun = await selectPrompt({
1111
title: "Choose an example to run",
12+
titleColor: "passionGradient",
1213
options: [
1314
{
14-
label: "✨ The Most Full-Featured Example",
15-
value: "1-main",
15+
label: "✨ Full-Featured Example",
16+
value: "main",
1617
hint: "recommended",
1718
},
1819
{
19-
label: pc.dim("Mono Component Example"),
20-
value: "2-mono",
20+
label: "Spinner Example",
21+
value: "spinner",
22+
hint: "experimental",
23+
},
24+
{
25+
label: pc.dim("Task Example"),
26+
value: "task",
27+
hint: pc.dim("not finished"),
28+
},
29+
{
30+
label: pc.dim("Progressbar Example"),
31+
value: "progressbar",
2132
hint: pc.dim("not finished"),
2233
},
2334
{
2435
label: pc.dim("Simple Example"),
25-
value: "3-simple",
36+
value: "simple",
2637
hint: pc.dim("not finished"),
2738
},
2839
{
2940
label: pc.dim("with flags 1 Example"),
30-
value: "4-cmd-a",
41+
value: "cmd-a",
3142
hint: pc.dim("not finished"),
3243
},
3344
{
3445
label: pc.dim("with flags 2 Example"),
35-
value: "5-cmd-b",
46+
value: "cmd-b",
3647
hint: pc.dim("not finished"),
3748
},
3849
{ label: "🗝️ Exit", value: "exit" },
3950
] as const,
40-
defaultValue: "1-main",
51+
defaultValue: "main",
4152
});
4253

4354
switch (exampleToRun) {
44-
case "1-main":
45-
await import("./1-main.js");
55+
case "main":
56+
await import("./main.js");
57+
break;
58+
case "spinner":
59+
await import("./other/spinner.js");
60+
break;
61+
case "task":
62+
await import("./other/task.js");
4663
break;
47-
case "2-mono":
48-
await import("./2-mono.js");
64+
case "progressbar":
65+
await import("./other/progress.js");
4966
break;
50-
case "3-simple":
51-
await import("./3-simple.js");
67+
case "simple":
68+
await import("./other/simple.js");
5269
break;
53-
case "4-cmd-a":
70+
case "cmd-a":
5471
console.clear();
5572
console.log(
56-
"`bun examples/4-args-a.ts Alice --friendly --age 22 --adj cool`",
73+
"`bun examples/other/args-a.ts Alice --friendly --age 22 --adj cool`",
5774
);
5875
console.log("Run without any arguments to see the help message.");
5976
break;
60-
case "5-cmd-b":
77+
case "cmd-b":
6178
console.clear();
6279
console.log(
63-
"1. [BUILD] `bun examples/5-args-b.ts build ./src --workDir ./src`",
80+
"1. [BUILD] `bun examples/other/args-b.ts build ./src --workDir ./src`",
6481
);
6582
console.log(
66-
"2. [DEBUG] `bun examples/5-args-b.ts debug --feature database-query`",
83+
"2. [DEBUG] `bun examples/other/args-b.ts debug --feature database-query`",
6784
);
6885
console.log(
69-
"3. [DEPLOY] `bun examples/5-args-b.ts deploy --include '*.js' --exclude '*.d.ts'`",
86+
"3. [DEPLOY] `bun examples/other/args-b.ts deploy --include '*.js' --exclude '*.d.ts'`",
7087
);
7188
console.log("Run without any arguments to see the help message.");
7289
break;

examples/main.png

73.6 KB
Loading
File renamed without changes.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineCommand, runMain } from "~/main.js";
22

3-
import packageJson from "../package.json" with { type: "json" };
3+
import packageJson from "../../package.json" with { type: "json" };
44

55
const main = defineCommand({
66
meta: {
@@ -15,9 +15,9 @@ const main = defineCommand({
1515
console.info("✅ Cleanup");
1616
},
1717
subCommands: {
18-
build: () => import("./src/commands/build.js").then((r) => r.default),
19-
deploy: () => import("./src/commands/deploy.js").then((r) => r.default),
20-
debug: () => import("./src/commands/debug.js").then((r) => r.default),
18+
build: () => import("../src/commands/build.js").then((r) => r.default),
19+
deploy: () => import("../src/commands/deploy.js").then((r) => r.default),
20+
debug: () => import("../src/commands/debug.js").then((r) => r.default),
2121
},
2222
});
2323

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// 2-mono-example.ts: A fun example of a quiz game. Inspired by CLI-game created by Fireship. The example demonstrates how to use a mono prompt() component.
22

3-
import { animateText, inputPrompt, task } from "~/main.js";
3+
import {
4+
animateText,
5+
inputPrompt,
6+
advancedTaskPrompt,
7+
endPrompt,
8+
msg,
9+
} from "~/main.js";
410
import { prompt } from "~/mono/mono.js";
511
import { colorize } from "~/utils/colorize.js";
612
import { errorHandler } from "~/utils/errors.js";
@@ -48,7 +54,7 @@ async function main() {
4854
],
4955
});
5056

51-
await task({
57+
/* await advancedTaskPrompt({
5258
initialMessage: "Checking answer...",
5359
successMessage: "Answer checked successfully.",
5460
spinnerSolution: "ora",
@@ -58,11 +64,54 @@ async function main() {
5864
updateMessage(
5965
answer === "Dec 4th, 1995"
6066
? `Nice work ${playerName}. That's a legit answer!`
61-
: `🫠 Game over, ${playerName}! You lose!`,
67+
: `🫠 Game over, ${playerName}! You lose!`,
6268
);
6369
await new Promise((resolve) => setTimeout(resolve, 1000));
6470
},
65-
});
71+
}); */
72+
73+
const result = await advancedTaskPrompt(
74+
"Check answer",
75+
{
76+
priority: "normal",
77+
displayType: "progress",
78+
},
79+
async ({ setStatus, setError, setProgress }) => {
80+
setProgress({
81+
current: 0,
82+
total: 5,
83+
message: "Starting verification...",
84+
});
85+
await new Promise((resolve) => setTimeout(resolve, 500));
86+
87+
for (let i = 0; i < 5; i++) {
88+
setProgress({
89+
current: i + 1,
90+
total: 5,
91+
message: `Step ${i + 1}: Verifying answer...`,
92+
});
93+
await new Promise((resolve) => setTimeout(resolve, 400));
94+
}
95+
96+
const isCorrect = answer === "Dec 4th, 1995";
97+
98+
if (!isCorrect) {
99+
setError(
100+
`🫠 Game over, ${playerName}! You lose!\nNo worries, you can try again!`,
101+
);
102+
// Wait a bit to ensure the message is displayed
103+
await new Promise((resolve) => setTimeout(resolve, 100));
104+
process.exit(1);
105+
}
106+
107+
setStatus(`Nice work ${playerName}. That's a legit answer!`);
108+
return isCorrect;
109+
},
110+
);
111+
112+
if (!result) {
113+
return;
114+
}
66115

67116
const message = `Congrats !\n $ 1 , 0 0 0 , 0 0 0`;
68117

@@ -81,6 +130,15 @@ async function main() {
81130
titleTypography: "bold",
82131
border: false,
83132
});
133+
134+
msg({ type: "M_BAR" });
135+
136+
await endPrompt({
137+
title: "Thanks for playing!\n",
138+
titleColor: "passionGradient",
139+
titleTypography: "bold",
140+
});
141+
84142
process.exit(0);
85143
}
86144

0 commit comments

Comments
 (0)