@nexusbloom/cli 0.3.2 → 0.3.3
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 +1 -1
- package/src/ui.js +45 -11
package/package.json
CHANGED
package/src/ui.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
|
|
18
18
|
// ─── Constants ───────────────────────────────────────────────────────────────
|
|
19
19
|
|
|
20
|
-
export const PAGE_SIZE =
|
|
20
|
+
export const PAGE_SIZE = 30;
|
|
21
21
|
|
|
22
22
|
// ─── Simple helpers ──────────────────────────────────────────────────────────
|
|
23
23
|
|
|
@@ -42,13 +42,17 @@ export function renderHeader(title, { subtitle, color = "cyan" } = {}) {
|
|
|
42
42
|
*/
|
|
43
43
|
export function renderBox(title, lines = [], { width = 60 } = {}) {
|
|
44
44
|
const inner = Math.max(width - 4, 30);
|
|
45
|
-
const top = chalk.gray(
|
|
45
|
+
const top = chalk.gray(
|
|
46
|
+
`┌─ ${chalk.bold(title)} ${"─".repeat(Math.max(0, inner - title.length - 2))}┐`,
|
|
47
|
+
);
|
|
46
48
|
console.log(`\n${top}`);
|
|
47
49
|
for (const line of lines) {
|
|
48
50
|
if (line === "") {
|
|
49
51
|
console.log(chalk.gray(`│ ${" ".repeat(inner)} │`));
|
|
50
52
|
} else {
|
|
51
|
-
console.log(
|
|
53
|
+
console.log(
|
|
54
|
+
`${chalk.gray("│ ")}${String(line).padEnd(inner)}${chalk.gray(" │")}`,
|
|
55
|
+
);
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
const bottom = chalk.gray(`└${"─".repeat(inner + 2)}┘\n`);
|
|
@@ -113,7 +117,12 @@ export function paginate(items, pageSize = PAGE_SIZE, currentPage = 1) {
|
|
|
113
117
|
* Interactive paginator: renders via `renderPage`, offers prev/next/done/cancel.
|
|
114
118
|
* Returns the last page result or null on cancel.
|
|
115
119
|
*/
|
|
116
|
-
export async function paginateInteractive(
|
|
120
|
+
export async function paginateInteractive(
|
|
121
|
+
items,
|
|
122
|
+
pageSize,
|
|
123
|
+
renderPage,
|
|
124
|
+
options = {},
|
|
125
|
+
) {
|
|
117
126
|
const all = items || [];
|
|
118
127
|
if (all.length === 0) {
|
|
119
128
|
renderPage(paginate([], pageSize, 1));
|
|
@@ -135,7 +144,9 @@ export async function paginateInteractive(items, pageSize, renderPage, options =
|
|
|
135
144
|
nav.push({ name: "✕ Cancel", value: "cancel" });
|
|
136
145
|
|
|
137
146
|
const action = await select({
|
|
138
|
-
message: chalk.gray(
|
|
147
|
+
message: chalk.gray(
|
|
148
|
+
`Page ${result.page}/${result.totalPages} · ${result.total} items`,
|
|
149
|
+
),
|
|
139
150
|
choices: [new Separator(), ...nav],
|
|
140
151
|
pageSize: 8,
|
|
141
152
|
});
|
|
@@ -151,11 +162,24 @@ export async function paginateInteractive(items, pageSize, renderPage, options =
|
|
|
151
162
|
// ─── Prompt wrappers ─────────────────────────────────────────────────────────
|
|
152
163
|
|
|
153
164
|
export async function promptSelect(message, choices, opts = {}) {
|
|
154
|
-
return select({
|
|
165
|
+
return select({
|
|
166
|
+
message: chalk.cyan(message),
|
|
167
|
+
choices,
|
|
168
|
+
pageSize: opts.pageSize || 10,
|
|
169
|
+
...opts,
|
|
170
|
+
});
|
|
155
171
|
}
|
|
156
172
|
|
|
157
|
-
export async function promptInput(
|
|
158
|
-
|
|
173
|
+
export async function promptInput(
|
|
174
|
+
message,
|
|
175
|
+
{ defaultValue, validate, ...opts } = {},
|
|
176
|
+
) {
|
|
177
|
+
return input({
|
|
178
|
+
message: chalk.cyan(message),
|
|
179
|
+
default: defaultValue,
|
|
180
|
+
...(validate ? { validate } : {}),
|
|
181
|
+
...opts,
|
|
182
|
+
});
|
|
159
183
|
}
|
|
160
184
|
|
|
161
185
|
export async function promptConfirm(message, { default: def = true } = {}) {
|
|
@@ -163,13 +187,23 @@ export async function promptConfirm(message, { default: def = true } = {}) {
|
|
|
163
187
|
}
|
|
164
188
|
|
|
165
189
|
export async function promptNumber(message, { min, max, ...opts } = {}) {
|
|
166
|
-
return number({
|
|
190
|
+
return number({
|
|
191
|
+
message: chalk.cyan(message),
|
|
192
|
+
...(min != null ? { min } : {}),
|
|
193
|
+
...(max != null ? { max } : {}),
|
|
194
|
+
...opts,
|
|
195
|
+
});
|
|
167
196
|
}
|
|
168
197
|
|
|
169
198
|
export async function promptCheckbox(message, choices, opts = {}) {
|
|
170
|
-
return checkbox({
|
|
199
|
+
return checkbox({
|
|
200
|
+
message: chalk.cyan(message),
|
|
201
|
+
choices,
|
|
202
|
+
pageSize: opts.pageSize || 10,
|
|
203
|
+
...opts,
|
|
204
|
+
});
|
|
171
205
|
}
|
|
172
206
|
|
|
173
207
|
export function sep(label = "") {
|
|
174
208
|
return new Separator(label ? ` — ${label} — ` : "");
|
|
175
|
-
}
|
|
209
|
+
}
|