letmecook 0.0.16 → 0.0.17

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,6 +1,6 @@
1
1
  {
2
2
  "name": "letmecook",
3
- "version": "0.0.16",
3
+ "version": "0.0.17",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/rustydotwtf/letmecook.git"
@@ -0,0 +1,196 @@
1
+ import {
2
+ type CliRenderer,
3
+ TextRenderable,
4
+ SelectRenderable,
5
+ SelectRenderableEvents,
6
+ type KeyEvent,
7
+ } from "@opentui/core";
8
+ import { createBaseLayout, clearLayout } from "./renderer";
9
+ import { showFooter, hideFooter } from "./common/footer";
10
+ import { isEscape } from "./common/keyboard";
11
+ import type { BackgroundProcess } from "../process-registry";
12
+
13
+ export type QuitWarningChoice = "continue" | "kill" | "cancel";
14
+
15
+ export function showQuitWarning(
16
+ renderer: CliRenderer,
17
+ processes: BackgroundProcess[],
18
+ ): Promise<QuitWarningChoice> {
19
+ return new Promise((resolve) => {
20
+ clearLayout(renderer);
21
+
22
+ const { content } = createBaseLayout(renderer, "Background processes running");
23
+
24
+ const warning = new TextRenderable(renderer, {
25
+ id: "warning",
26
+ content: `${processes.length} background process${processes.length > 1 ? "es" : ""} still running:`,
27
+ fg: "#f59e0b",
28
+ marginBottom: 1,
29
+ });
30
+ content.add(warning);
31
+
32
+ // List the running processes
33
+ processes.forEach((proc, i) => {
34
+ const processInfo = new TextRenderable(renderer, {
35
+ id: `process-${i}`,
36
+ content: ` • ${proc.description}`,
37
+ fg: "#94a3b8",
38
+ });
39
+ content.add(processInfo);
40
+ });
41
+
42
+ const question = new TextRenderable(renderer, {
43
+ id: "question",
44
+ content: "What would you like to do?",
45
+ fg: "#e2e8f0",
46
+ marginTop: 1,
47
+ });
48
+ content.add(question);
49
+
50
+ const select = new SelectRenderable(renderer, {
51
+ id: "quit-warning-select",
52
+ width: 38,
53
+ height: 3,
54
+ options: [
55
+ { name: "Keep running & quit", description: "", value: "continue" },
56
+ { name: "Kill all & quit", description: "", value: "kill" },
57
+ { name: "Cancel", description: "", value: "cancel" },
58
+ ],
59
+ showDescription: false,
60
+ backgroundColor: "transparent",
61
+ focusedBackgroundColor: "transparent",
62
+ selectedBackgroundColor: "#334155",
63
+ textColor: "#e2e8f0",
64
+ selectedTextColor: "#38bdf8",
65
+ marginTop: 1,
66
+ });
67
+ content.add(select);
68
+
69
+ select.focus();
70
+
71
+ const handleSelect = (_index: number, option: { value: string }) => {
72
+ cleanup();
73
+ resolve(option.value as QuitWarningChoice);
74
+ };
75
+
76
+ const handleKeypress = (key: KeyEvent) => {
77
+ if (isEscape(key)) {
78
+ cleanup();
79
+ resolve("cancel");
80
+ }
81
+ };
82
+
83
+ const cleanup = () => {
84
+ select.off(SelectRenderableEvents.ITEM_SELECTED, handleSelect);
85
+ renderer.keyInput.off("keypress", handleKeypress);
86
+ select.blur();
87
+ hideFooter(renderer);
88
+ clearLayout(renderer);
89
+ };
90
+
91
+ showFooter(renderer, content, {
92
+ navigate: true,
93
+ select: true,
94
+ back: true,
95
+ });
96
+
97
+ select.on(SelectRenderableEvents.ITEM_SELECTED, handleSelect);
98
+ renderer.keyInput.on("keypress", handleKeypress);
99
+ });
100
+ }
101
+
102
+ export type SessionStartWarningChoice = "continue" | "cancel";
103
+
104
+ export function showSessionStartWarning(
105
+ renderer: CliRenderer,
106
+ processes: BackgroundProcess[],
107
+ ): Promise<SessionStartWarningChoice> {
108
+ return new Promise((resolve) => {
109
+ clearLayout(renderer);
110
+
111
+ const { content } = createBaseLayout(renderer, "Background processes detected");
112
+
113
+ const warning = new TextRenderable(renderer, {
114
+ id: "warning",
115
+ content: `${processes.length} background process${processes.length > 1 ? "es" : ""} still running for this session:`,
116
+ fg: "#f59e0b",
117
+ marginBottom: 1,
118
+ });
119
+ content.add(warning);
120
+
121
+ // List the running processes
122
+ processes.forEach((proc, i) => {
123
+ const processInfo = new TextRenderable(renderer, {
124
+ id: `process-${i}`,
125
+ content: ` • ${proc.description}`,
126
+ fg: "#94a3b8",
127
+ });
128
+ content.add(processInfo);
129
+ });
130
+
131
+ const note = new TextRenderable(renderer, {
132
+ id: "note",
133
+ content: "Some repositories may not be fully cloned yet.",
134
+ fg: "#94a3b8",
135
+ marginTop: 1,
136
+ });
137
+ content.add(note);
138
+
139
+ const question = new TextRenderable(renderer, {
140
+ id: "question",
141
+ content: "Continue with session?",
142
+ fg: "#e2e8f0",
143
+ marginTop: 1,
144
+ });
145
+ content.add(question);
146
+
147
+ const select = new SelectRenderable(renderer, {
148
+ id: "session-warning-select",
149
+ width: 38,
150
+ height: 2,
151
+ options: [
152
+ { name: "Continue anyway", description: "", value: "continue" },
153
+ { name: "Cancel", description: "", value: "cancel" },
154
+ ],
155
+ showDescription: false,
156
+ backgroundColor: "transparent",
157
+ focusedBackgroundColor: "transparent",
158
+ selectedBackgroundColor: "#334155",
159
+ textColor: "#e2e8f0",
160
+ selectedTextColor: "#38bdf8",
161
+ marginTop: 1,
162
+ });
163
+ content.add(select);
164
+
165
+ select.focus();
166
+
167
+ const handleSelect = (_index: number, option: { value: string }) => {
168
+ cleanup();
169
+ resolve(option.value as SessionStartWarningChoice);
170
+ };
171
+
172
+ const handleKeypress = (key: KeyEvent) => {
173
+ if (isEscape(key)) {
174
+ cleanup();
175
+ resolve("cancel");
176
+ }
177
+ };
178
+
179
+ const cleanup = () => {
180
+ select.off(SelectRenderableEvents.ITEM_SELECTED, handleSelect);
181
+ renderer.keyInput.off("keypress", handleKeypress);
182
+ select.blur();
183
+ hideFooter(renderer);
184
+ clearLayout(renderer);
185
+ };
186
+
187
+ showFooter(renderer, content, {
188
+ navigate: true,
189
+ select: true,
190
+ back: true,
191
+ });
192
+
193
+ select.on(SelectRenderableEvents.ITEM_SELECTED, handleSelect);
194
+ renderer.keyInput.on("keypress", handleKeypress);
195
+ });
196
+ }