mepcli 0.5.0 → 0.6.0
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/README.md +182 -6
- package/dist/ansi.d.ts +1 -0
- package/dist/ansi.js +1 -0
- package/dist/base.d.ts +1 -1
- package/dist/base.js +1 -10
- package/dist/core.d.ts +26 -1
- package/dist/core.js +72 -0
- package/dist/highlight.d.ts +1 -0
- package/dist/highlight.js +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/input.js +26 -14
- package/dist/prompts/autocomplete.d.ts +1 -1
- package/dist/prompts/autocomplete.js +2 -7
- package/dist/prompts/calendar.d.ts +20 -0
- package/dist/prompts/calendar.js +329 -0
- package/dist/prompts/checkbox.d.ts +1 -1
- package/dist/prompts/checkbox.js +38 -8
- package/dist/prompts/code.d.ts +17 -0
- package/dist/prompts/code.js +210 -0
- package/dist/prompts/color.d.ts +14 -0
- package/dist/prompts/color.js +147 -0
- package/dist/prompts/confirm.d.ts +1 -1
- package/dist/prompts/confirm.js +1 -1
- package/dist/prompts/cron.d.ts +13 -0
- package/dist/prompts/cron.js +176 -0
- package/dist/prompts/date.d.ts +1 -1
- package/dist/prompts/date.js +15 -5
- package/dist/prompts/editor.d.ts +14 -0
- package/dist/prompts/editor.js +207 -0
- package/dist/prompts/file.d.ts +7 -0
- package/dist/prompts/file.js +56 -60
- package/dist/prompts/form.d.ts +17 -0
- package/dist/prompts/form.js +225 -0
- package/dist/prompts/grid.d.ts +14 -0
- package/dist/prompts/grid.js +178 -0
- package/dist/prompts/keypress.d.ts +7 -0
- package/dist/prompts/keypress.js +57 -0
- package/dist/prompts/list.d.ts +1 -1
- package/dist/prompts/list.js +42 -22
- package/dist/prompts/multi-select.d.ts +1 -1
- package/dist/prompts/multi-select.js +39 -4
- package/dist/prompts/number.d.ts +1 -1
- package/dist/prompts/number.js +2 -2
- package/dist/prompts/range.d.ts +9 -0
- package/dist/prompts/range.js +140 -0
- package/dist/prompts/rating.d.ts +1 -1
- package/dist/prompts/rating.js +1 -1
- package/dist/prompts/select.d.ts +1 -1
- package/dist/prompts/select.js +1 -1
- package/dist/prompts/slider.d.ts +1 -1
- package/dist/prompts/slider.js +1 -1
- package/dist/prompts/snippet.d.ts +18 -0
- package/dist/prompts/snippet.js +203 -0
- package/dist/prompts/sort.d.ts +1 -1
- package/dist/prompts/sort.js +1 -4
- package/dist/prompts/spam.d.ts +17 -0
- package/dist/prompts/spam.js +62 -0
- package/dist/prompts/table.d.ts +1 -1
- package/dist/prompts/table.js +1 -1
- package/dist/prompts/text.d.ts +1 -0
- package/dist/prompts/text.js +14 -32
- package/dist/prompts/toggle.d.ts +1 -1
- package/dist/prompts/toggle.js +1 -1
- package/dist/prompts/transfer.d.ts +18 -0
- package/dist/prompts/transfer.js +203 -0
- package/dist/prompts/tree-select.d.ts +32 -0
- package/dist/prompts/tree-select.js +277 -0
- package/dist/prompts/tree.d.ts +20 -0
- package/dist/prompts/tree.js +231 -0
- package/dist/prompts/wait.d.ts +18 -0
- package/dist/prompts/wait.js +62 -0
- package/dist/types.d.ts +105 -0
- package/dist/utils.js +6 -2
- package/example.ts +213 -27
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
# Mep
|
|
2
2
|
|
|
3
|
-
**Mep** is a
|
|
3
|
+
**Mep** is a lightweight and zero-dependency library for creating interactive command-line prompts in Node.js. It focuses on simplicity, modern design, and robust input handling, including support for cursor movement and input validation.
|
|
4
|
+
|
|
5
|
+
A **CodeTease** project.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
9
|
- **Zero Dependency:** Keeps your project clean and fast.
|
|
8
|
-
- **Comprehensive Prompts:** Includes `text`, `password`, `select`, `checkbox`, `confirm`, `number`, `toggle`, `list`, `slider`, `date`, `file`, `multiSelect`, `autocomplete`, `sort`, `table`, and `
|
|
9
|
-
- **Mouse Support:** Built-in support for mouse interaction (SGR 1006 protocol). Scroll to navigate lists or change values
|
|
10
|
+
- **Comprehensive Prompts:** Includes `text`, `password`, `secret`, `select`, `checkbox`, `confirm`, `number`, `toggle`, `list`, `slider`, `range`, `date`, `file`, `multiSelect`, `autocomplete`, `sort`, `transfer`, `cron`, `table`, `rating`, `editor`, `tree`, `keypress`, `color`, `grid`, and `calendar`.
|
|
11
|
+
- **Mouse Support:** Built-in support for mouse interaction (SGR 1006 protocol). Scroll to navigate lists or change values.
|
|
10
12
|
- **Responsive Input:** Supports cursor movement (Left/Right) and character insertion/deletion in text-based prompts.
|
|
11
13
|
- **Validation:** Built-in support for input validation (sync and async) with custom error messages.
|
|
12
14
|
- **Elegant Look:** Uses ANSI colors for a clean, modern CLI experience.
|
|
@@ -104,7 +106,79 @@ async function main() {
|
|
|
104
106
|
]
|
|
105
107
|
});
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
// Color (RGB Picker)
|
|
110
|
+
const color = await MepCLI.color({
|
|
111
|
+
message: "Choose theme color:",
|
|
112
|
+
initial: "#3B82F6"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Grid (Matrix Selection)
|
|
116
|
+
const permissions = await MepCLI.grid({
|
|
117
|
+
message: "Manage Permissions:",
|
|
118
|
+
rows: ["Admin", "User", "Guest"],
|
|
119
|
+
columns: ["Read", "Write", "Delete"]
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Calendar (Date/Range Picker)
|
|
123
|
+
const booking = await MepCLI.calendar({
|
|
124
|
+
message: "Select dates:",
|
|
125
|
+
mode: "range"
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Editor (External text editor)
|
|
129
|
+
const bio = await MepCLI.editor({
|
|
130
|
+
message: "Write your biography:",
|
|
131
|
+
extension: ".md"
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Form (Multi-field input)
|
|
135
|
+
const userDetails = await MepCLI.form({
|
|
136
|
+
message: "User Details:",
|
|
137
|
+
fields: [
|
|
138
|
+
{ name: "firstname", message: "First Name", initial: "John" },
|
|
139
|
+
{ name: "lastname", message: "Last Name", validate: (v) => v.length > 0 ? true : "Required" },
|
|
140
|
+
{ name: "email", message: "Email", validate: (v) => v.includes("@") || "Invalid email" }
|
|
141
|
+
]
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Snippet (Template filling)
|
|
145
|
+
const commitMsg = await MepCLI.snippet({
|
|
146
|
+
message: "Commit Message:",
|
|
147
|
+
template: "feat(${scope}): ${message}",
|
|
148
|
+
values: {
|
|
149
|
+
scope: "core"
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// Code Prompt (JSON/YAML Editing)
|
|
154
|
+
const config = await MepCLI.code({
|
|
155
|
+
message: "Configure Server:",
|
|
156
|
+
language: "json",
|
|
157
|
+
template: `
|
|
158
|
+
{
|
|
159
|
+
"host": "\${host}",
|
|
160
|
+
"port": \${port},
|
|
161
|
+
"debug": \${debug}
|
|
162
|
+
}
|
|
163
|
+
`
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Tree Select (Hierarchical Multi-Select)
|
|
167
|
+
const selectedFiles = await MepCLI.treeSelect({
|
|
168
|
+
message: "Select files to backup:",
|
|
169
|
+
data: [
|
|
170
|
+
{
|
|
171
|
+
title: "src",
|
|
172
|
+
value: "src",
|
|
173
|
+
children: [
|
|
174
|
+
{ title: "index.ts", value: "src/index.ts" },
|
|
175
|
+
{ title: "utils.ts", value: "src/utils.ts" }
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
console.log({ name, age, newsletter, lang, tools, stars, city, priorities, user, color, permissions, booking, bio, userDetails, commitMsg, config, selectedFiles });
|
|
108
182
|
}
|
|
109
183
|
|
|
110
184
|
main();
|
|
@@ -116,6 +190,7 @@ main();
|
|
|
116
190
|
|
|
117
191
|
* `text(options)` - Single line or multiline text input.
|
|
118
192
|
* `password(options)` - Masked text input.
|
|
193
|
+
* `secret(options)` - Completely hidden text input.
|
|
119
194
|
* `number(options)` - Numeric input with increment/decrement support.
|
|
120
195
|
* `confirm(options)` - Yes/No question.
|
|
121
196
|
* `toggle(options)` - On/Off switch.
|
|
@@ -124,12 +199,27 @@ main();
|
|
|
124
199
|
* `checkbox(options)` - Classic checkbox selection.
|
|
125
200
|
* `list(options)` - Enter a list of tags/strings.
|
|
126
201
|
* `slider(options)` - Select a number within a range using a visual slider.
|
|
202
|
+
* `range(options)` - Select a numerical range (min/max) using a dual-handle slider.
|
|
127
203
|
* `rating(options)` - Star rating input.
|
|
128
204
|
* `date(options)` - Date and time picker.
|
|
205
|
+
* `color(options)` - RGB color picker with hex output and TrueColor preview.
|
|
206
|
+
* `grid(options)` - 2D matrix selection (rows x columns).
|
|
207
|
+
* `calendar(options)` - Interactive monthly calendar for single dates or ranges.
|
|
129
208
|
* `file(options)` - File system navigator and selector.
|
|
130
209
|
* `autocomplete(options)` - Searchable selection with async suggestions.
|
|
131
210
|
* `sort(options)` - Reorder a list of items.
|
|
211
|
+
* `transfer(options)` - Move items between two lists (Source/Target).
|
|
212
|
+
* `cron(options)` - Visually build a cron schedule (Minute, Hour, Day, Month, Weekday).
|
|
132
213
|
* `table(options)` - Display data in columns and select rows.
|
|
214
|
+
* `tree(options)` - Navigate and select from a hierarchical tree structure.
|
|
215
|
+
* `keypress(options)` - Wait for a specific key press or any key.
|
|
216
|
+
* `editor(options)` - Launch an external editor (Vim, Nano, Notepad, etc.) to capture multi-line content.
|
|
217
|
+
* `form(options)` - Multi-field input form with navigation.
|
|
218
|
+
* `snippet(options)` - Template string filling with variable navigation.
|
|
219
|
+
* `code(options)` - Edit variables within a code block (JSON/YAML). Syntax highlighting is supported (Experimental).
|
|
220
|
+
* `treeSelect(options)` - Hierarchical multi-selection with cascading checkboxes.
|
|
221
|
+
* `spam(options)` - Confirm a dangerous action or fun.
|
|
222
|
+
* `wait(options)` - Wait for a specified number of seconds.
|
|
133
223
|
* `spinner(message)` - Returns a `Spinner` instance for manual control (`start`, `stop`, `update`, `success`, `error`).
|
|
134
224
|
|
|
135
225
|
## Mouse Support
|
|
@@ -137,14 +227,100 @@ main();
|
|
|
137
227
|
MepCLI automatically detects modern terminals and enables **Mouse Tracking** (using SGR 1006 protocol).
|
|
138
228
|
|
|
139
229
|
* **Scrolling:**
|
|
140
|
-
* `select`, `multiSelect`, `checkbox`, `autocomplete`, `table`: Scroll to navigate the list.
|
|
141
|
-
* `
|
|
230
|
+
* `select`, `multiSelect`, `checkbox`, `autocomplete`, `table`, `tree`, `transfer`: Scroll to navigate the list.
|
|
231
|
+
* `form`, `snippet`, `cron`: Scroll to navigate between fields or values.
|
|
232
|
+
* `number`, `slider`, `range`, `rating`, `date`: Scroll to increment/decrement values or fields.
|
|
142
233
|
* `sort`: Scroll to navigate or reorder items (when grabbed).
|
|
143
234
|
* `toggle`, `confirm`: Scroll to toggle the state.
|
|
235
|
+
* `calendar`: Scroll to switch months.
|
|
236
|
+
* `color`: Scroll to adjust RGB channels.
|
|
237
|
+
* `grid`: Scroll to move selection.
|
|
144
238
|
* **Configuration:**
|
|
145
239
|
* Mouse support is enabled by default if the terminal supports it.
|
|
146
240
|
* You can explicitly disable it per prompt by setting `mouse: false` in the options.
|
|
147
241
|
|
|
242
|
+
## Advanced Shortcuts
|
|
243
|
+
|
|
244
|
+
### Calendar Prompt
|
|
245
|
+
|
|
246
|
+
Mep's Calendar prompt supports advanced navigation and selection shortcuts for power users.
|
|
247
|
+
|
|
248
|
+
* **Keyboard:**
|
|
249
|
+
* `Arrow Keys`: Move cursor day by day.
|
|
250
|
+
* `PageUp` / `PageDown`: Jump to previous/next **Month**.
|
|
251
|
+
* `Ctrl + Up` / `Ctrl + Down`: Jump to previous/next **Year**.
|
|
252
|
+
* `Home` / `End`: Jump to the first/last day of the current month.
|
|
253
|
+
* `t`: Jump immediately to **Today**.
|
|
254
|
+
* `Enter`: Select date (or start/end of range).
|
|
255
|
+
|
|
256
|
+
* **Mouse:**
|
|
257
|
+
* `Scroll`: Navigate **Months**.
|
|
258
|
+
* `Ctrl + Scroll`: Adjust the selected **Day** (cursor movement).
|
|
259
|
+
|
|
260
|
+
### Color Prompt
|
|
261
|
+
|
|
262
|
+
* **Keyboard:**
|
|
263
|
+
* `Tab`: Switch between RGB channels.
|
|
264
|
+
* `Up` / `Down`: Move between channels.
|
|
265
|
+
* `Left` / `Right`: Adjust current channel value.
|
|
266
|
+
* `Shift + Left` / `Shift + Right`: Fast adjust current channel value.
|
|
267
|
+
|
|
268
|
+
* **Mouse:**
|
|
269
|
+
* `Scroll`: Adjust the current channel value.
|
|
270
|
+
* `Ctrl + Scroll`: Fast adjust.
|
|
271
|
+
|
|
272
|
+
### Checkbox Prompt
|
|
273
|
+
|
|
274
|
+
* **Keyboard:**
|
|
275
|
+
* `Space`: Toggle selection.
|
|
276
|
+
* `a`: Select **All**.
|
|
277
|
+
* `x` / `n`: Select **None**.
|
|
278
|
+
* `i`: **Invert** selection.
|
|
279
|
+
|
|
280
|
+
### MultiSelect Prompt
|
|
281
|
+
|
|
282
|
+
* **Keyboard:**
|
|
283
|
+
* `Space`: Toggle selection.
|
|
284
|
+
* `Ctrl + A`: Select **All** (Visible).
|
|
285
|
+
* `Ctrl + X`: Deselect **All** (Visible).
|
|
286
|
+
* `Typing`: Filter list.
|
|
287
|
+
|
|
288
|
+
### Transfer Prompt
|
|
289
|
+
|
|
290
|
+
* **Keyboard:**
|
|
291
|
+
* `Tab` / `Left` / `Right`: Switch focus between Source and Target.
|
|
292
|
+
* `Space`: Move selected item.
|
|
293
|
+
* `a` / `>`: Move **All** to Target.
|
|
294
|
+
* `r` / `<`: Move **All** to Source (Reset).
|
|
295
|
+
|
|
296
|
+
### Tree & TreeSelect Prompt
|
|
297
|
+
|
|
298
|
+
* **Keyboard:**
|
|
299
|
+
* `Right`: Expand folder or jump to child.
|
|
300
|
+
* `Left`: Collapse folder or jump to parent.
|
|
301
|
+
* `Space`: Toggle expansion (Tree) or Checkbox (TreeSelect).
|
|
302
|
+
* `e`: **Expand** all recursively.
|
|
303
|
+
* `c`: **Collapse** all recursively.
|
|
304
|
+
|
|
305
|
+
### Grid Prompt
|
|
306
|
+
|
|
307
|
+
The Grid prompt (Matrix selection) includes robust shortcuts for bulk actions.
|
|
308
|
+
|
|
309
|
+
* **Keyboard:**
|
|
310
|
+
* `Arrow Keys`: Move cursor.
|
|
311
|
+
* `PageUp` / `PageDown`: Jump to the first/last **Row**.
|
|
312
|
+
* `Home` / `End`: Jump to the first/last **Column**.
|
|
313
|
+
* `Space`: Toggle current cell.
|
|
314
|
+
* `r`: Toggle entire **Row**.
|
|
315
|
+
* `c`: Toggle entire **Column**.
|
|
316
|
+
* `a`: Select **All**.
|
|
317
|
+
* `x`: Deselect **All** (None).
|
|
318
|
+
* `i`: **Invert** selection.
|
|
319
|
+
|
|
320
|
+
* **Mouse:**
|
|
321
|
+
* `Scroll`: Vertical navigation (Rows).
|
|
322
|
+
* `Shift + Scroll`: Horizontal navigation (Columns).
|
|
323
|
+
|
|
148
324
|
## License
|
|
149
325
|
|
|
150
326
|
This project is under the **MIT License**.
|
package/dist/ansi.d.ts
CHANGED
package/dist/ansi.js
CHANGED
package/dist/base.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare abstract class Prompt<T, O> {
|
|
|
34
34
|
* Optional method to handle mouse events.
|
|
35
35
|
* Subclasses can override this to implement mouse interaction.
|
|
36
36
|
*/
|
|
37
|
-
protected handleMouse(
|
|
37
|
+
protected handleMouse(_event: MouseEvent): void;
|
|
38
38
|
protected print(text: string): void;
|
|
39
39
|
/**
|
|
40
40
|
* Starts the prompt interaction.
|
package/dist/base.js
CHANGED
|
@@ -24,7 +24,7 @@ class Prompt {
|
|
|
24
24
|
* Optional method to handle mouse events.
|
|
25
25
|
* Subclasses can override this to implement mouse interaction.
|
|
26
26
|
*/
|
|
27
|
-
handleMouse(
|
|
27
|
+
handleMouse(_event) { }
|
|
28
28
|
print(text) {
|
|
29
29
|
this.stdout.write(text);
|
|
30
30
|
}
|
|
@@ -88,7 +88,6 @@ class Prompt {
|
|
|
88
88
|
if (this._onKeyHandler) {
|
|
89
89
|
this._inputParser.removeListener('keypress', this._onKeyHandler);
|
|
90
90
|
}
|
|
91
|
-
// Cleanup mouse listener - though InputParser is instance specific, so it's fine.
|
|
92
91
|
// Disable Mouse Tracking
|
|
93
92
|
this.print(ansi_1.ANSI.DISABLE_MOUSE);
|
|
94
93
|
if (typeof this.stdin.setRawMode === 'function') {
|
|
@@ -169,11 +168,6 @@ class Prompt {
|
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
else {
|
|
172
|
-
// Width check
|
|
173
|
-
// Handle surrogates roughly (we don't need perfect width here during loop, just enough to stop)
|
|
174
|
-
// But wait, we imported `stringWidth`.
|
|
175
|
-
// We can't easily use `stringWidth` incrementally without re-parsing.
|
|
176
|
-
// Let's just trust the loop for cut index.
|
|
177
171
|
// Re-implement basic width logic here for the cut index finding
|
|
178
172
|
let charWidth = 1;
|
|
179
173
|
let cp = code;
|
|
@@ -185,9 +179,6 @@ class Prompt {
|
|
|
185
179
|
// We'll handle i increment in the loop
|
|
186
180
|
}
|
|
187
181
|
}
|
|
188
|
-
// Check range (simplified or call helper)
|
|
189
|
-
// We don't have isWideCodePoint exported.
|
|
190
|
-
// But generally, we can just say:
|
|
191
182
|
if (cp >= 0x1100) { // Quick check for potentially wide
|
|
192
183
|
// It's acceptable to be slightly aggressive on wide chars for truncation
|
|
193
184
|
charWidth = 2;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextOptions, SelectOptions, ConfirmOptions, CheckboxOptions, ThemeConfig, NumberOptions, ToggleOptions, ListOptions, SliderOptions, DateOptions, FileOptions, MultiSelectOptions, RatingOptions, AutocompleteOptions, SortOptions, TableOptions } from './types';
|
|
1
|
+
import { TextOptions, SelectOptions, ConfirmOptions, CheckboxOptions, ThemeConfig, NumberOptions, ToggleOptions, ListOptions, SliderOptions, DateOptions, FileOptions, MultiSelectOptions, RatingOptions, AutocompleteOptions, SortOptions, TableOptions, EditorOptions, TreeOptions, KeypressOptions, FormOptions, SnippetOptions, SpamOptions, WaitOptions, CodeOptions, TreeSelectOptions, RangeOptions, TransferOptions, CronOptions, ColorOptions, GridOptions, CalendarOptions } from './types';
|
|
2
2
|
import { Spinner } from './spinner';
|
|
3
3
|
/**
|
|
4
4
|
* Public Facade for MepCLI
|
|
@@ -14,10 +14,14 @@ export declare class MepCLI {
|
|
|
14
14
|
static checkbox<const V>(options: CheckboxOptions<V>): Promise<V[]>;
|
|
15
15
|
static confirm(options: ConfirmOptions): Promise<boolean>;
|
|
16
16
|
static password(options: TextOptions): Promise<string>;
|
|
17
|
+
static secret(options: TextOptions): Promise<string>;
|
|
17
18
|
static number(options: NumberOptions): Promise<number>;
|
|
18
19
|
static toggle(options: ToggleOptions): Promise<boolean>;
|
|
19
20
|
static list(options: ListOptions): Promise<string[]>;
|
|
20
21
|
static slider(options: SliderOptions): Promise<number>;
|
|
22
|
+
static range(options: RangeOptions): Promise<[number, number]>;
|
|
23
|
+
static transfer<const V>(options: TransferOptions<V>): Promise<[V[], V[]]>;
|
|
24
|
+
static cron(options: CronOptions): Promise<string>;
|
|
21
25
|
static date(options: DateOptions): Promise<Date>;
|
|
22
26
|
static file(options: FileOptions): Promise<string>;
|
|
23
27
|
static multiSelect<const V>(options: MultiSelectOptions<V>): Promise<V[]>;
|
|
@@ -25,4 +29,25 @@ export declare class MepCLI {
|
|
|
25
29
|
static autocomplete<const V>(options: AutocompleteOptions<V>): Promise<V>;
|
|
26
30
|
static sort(options: SortOptions): Promise<string[]>;
|
|
27
31
|
static table<const V>(options: TableOptions<V>): Promise<V>;
|
|
32
|
+
static editor(options: EditorOptions): Promise<string>;
|
|
33
|
+
static tree<const V>(options: TreeOptions<V>): Promise<V>;
|
|
34
|
+
static keypress(options: KeypressOptions): Promise<string>;
|
|
35
|
+
static form(options: FormOptions): Promise<Record<string, string>>;
|
|
36
|
+
static snippet(options: SnippetOptions): Promise<string>;
|
|
37
|
+
static spam(options: SpamOptions): Promise<boolean>;
|
|
38
|
+
static wait(options: WaitOptions): Promise<void>;
|
|
39
|
+
static code(options: CodeOptions): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Tree Select Prompt (Multi-selection)
|
|
42
|
+
* * @param options Configuration for the tree selection
|
|
43
|
+
* @returns A promise that resolves to an array of selected values
|
|
44
|
+
* * @notice Windows Compatibility:
|
|
45
|
+
* When used in a long sequence of prompts, this component may experience
|
|
46
|
+
* an input delay. If it feels "blocked", simply press 'Enter' once
|
|
47
|
+
* to refresh the TTY stream.
|
|
48
|
+
*/
|
|
49
|
+
static treeSelect<const V>(options: TreeSelectOptions<V>): Promise<V[]>;
|
|
50
|
+
static color(options: ColorOptions): Promise<string>;
|
|
51
|
+
static grid(options: GridOptions): Promise<boolean[][]>;
|
|
52
|
+
static calendar(options: CalendarOptions): Promise<Date | [Date, Date]>;
|
|
28
53
|
}
|
package/dist/core.js
CHANGED
|
@@ -11,6 +11,9 @@ const toggle_1 = require("./prompts/toggle");
|
|
|
11
11
|
const number_1 = require("./prompts/number");
|
|
12
12
|
const list_1 = require("./prompts/list");
|
|
13
13
|
const slider_1 = require("./prompts/slider");
|
|
14
|
+
const range_1 = require("./prompts/range");
|
|
15
|
+
const transfer_1 = require("./prompts/transfer");
|
|
16
|
+
const cron_1 = require("./prompts/cron");
|
|
14
17
|
const date_1 = require("./prompts/date");
|
|
15
18
|
const file_1 = require("./prompts/file");
|
|
16
19
|
const multi_select_1 = require("./prompts/multi-select");
|
|
@@ -18,6 +21,18 @@ const rating_1 = require("./prompts/rating");
|
|
|
18
21
|
const autocomplete_1 = require("./prompts/autocomplete");
|
|
19
22
|
const sort_1 = require("./prompts/sort");
|
|
20
23
|
const table_1 = require("./prompts/table");
|
|
24
|
+
const editor_1 = require("./prompts/editor");
|
|
25
|
+
const tree_1 = require("./prompts/tree");
|
|
26
|
+
const keypress_1 = require("./prompts/keypress");
|
|
27
|
+
const form_1 = require("./prompts/form");
|
|
28
|
+
const snippet_1 = require("./prompts/snippet");
|
|
29
|
+
const spam_1 = require("./prompts/spam");
|
|
30
|
+
const wait_1 = require("./prompts/wait");
|
|
31
|
+
const code_1 = require("./prompts/code");
|
|
32
|
+
const tree_select_1 = require("./prompts/tree-select");
|
|
33
|
+
const color_1 = require("./prompts/color");
|
|
34
|
+
const grid_1 = require("./prompts/grid");
|
|
35
|
+
const calendar_1 = require("./prompts/calendar");
|
|
21
36
|
/**
|
|
22
37
|
* Public Facade for MepCLI
|
|
23
38
|
*/
|
|
@@ -43,6 +58,9 @@ class MepCLI {
|
|
|
43
58
|
static password(options) {
|
|
44
59
|
return new text_1.TextPrompt({ ...options, isPassword: true }).run();
|
|
45
60
|
}
|
|
61
|
+
static secret(options) {
|
|
62
|
+
return new text_1.TextPrompt({ ...options, mask: '' }).run();
|
|
63
|
+
}
|
|
46
64
|
static number(options) {
|
|
47
65
|
return new number_1.NumberPrompt(options).run();
|
|
48
66
|
}
|
|
@@ -55,6 +73,15 @@ class MepCLI {
|
|
|
55
73
|
static slider(options) {
|
|
56
74
|
return new slider_1.SliderPrompt(options).run();
|
|
57
75
|
}
|
|
76
|
+
static range(options) {
|
|
77
|
+
return new range_1.RangePrompt(options).run();
|
|
78
|
+
}
|
|
79
|
+
static transfer(options) {
|
|
80
|
+
return new transfer_1.TransferPrompt(options).run();
|
|
81
|
+
}
|
|
82
|
+
static cron(options) {
|
|
83
|
+
return new cron_1.CronPrompt(options).run();
|
|
84
|
+
}
|
|
58
85
|
static date(options) {
|
|
59
86
|
return new date_1.DatePrompt(options).run();
|
|
60
87
|
}
|
|
@@ -76,6 +103,51 @@ class MepCLI {
|
|
|
76
103
|
static table(options) {
|
|
77
104
|
return new table_1.TablePrompt(options).run();
|
|
78
105
|
}
|
|
106
|
+
static editor(options) {
|
|
107
|
+
return new editor_1.EditorPrompt(options).run();
|
|
108
|
+
}
|
|
109
|
+
static tree(options) {
|
|
110
|
+
return new tree_1.TreePrompt(options).run();
|
|
111
|
+
}
|
|
112
|
+
static keypress(options) {
|
|
113
|
+
return new keypress_1.KeypressPrompt(options).run();
|
|
114
|
+
}
|
|
115
|
+
static form(options) {
|
|
116
|
+
return new form_1.FormPrompt(options).run();
|
|
117
|
+
}
|
|
118
|
+
static snippet(options) {
|
|
119
|
+
return new snippet_1.SnippetPrompt(options).run();
|
|
120
|
+
}
|
|
121
|
+
static spam(options) {
|
|
122
|
+
return new spam_1.SpamPrompt(options).run();
|
|
123
|
+
}
|
|
124
|
+
static wait(options) {
|
|
125
|
+
return new wait_1.WaitPrompt(options).run();
|
|
126
|
+
}
|
|
127
|
+
static code(options) {
|
|
128
|
+
return new code_1.CodePrompt(options).run();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Tree Select Prompt (Multi-selection)
|
|
132
|
+
* * @param options Configuration for the tree selection
|
|
133
|
+
* @returns A promise that resolves to an array of selected values
|
|
134
|
+
* * @notice Windows Compatibility:
|
|
135
|
+
* When used in a long sequence of prompts, this component may experience
|
|
136
|
+
* an input delay. If it feels "blocked", simply press 'Enter' once
|
|
137
|
+
* to refresh the TTY stream.
|
|
138
|
+
*/
|
|
139
|
+
static treeSelect(options) {
|
|
140
|
+
return new tree_select_1.TreeSelectPrompt(options).run();
|
|
141
|
+
}
|
|
142
|
+
static color(options) {
|
|
143
|
+
return new color_1.ColorPrompt(options).run();
|
|
144
|
+
}
|
|
145
|
+
static grid(options) {
|
|
146
|
+
return new grid_1.GridPrompt(options).run();
|
|
147
|
+
}
|
|
148
|
+
static calendar(options) {
|
|
149
|
+
return new calendar_1.CalendarPrompt(options).run();
|
|
150
|
+
}
|
|
79
151
|
}
|
|
80
152
|
exports.MepCLI = MepCLI;
|
|
81
153
|
MepCLI.theme = theme_1.theme;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function highlightJson(json: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.highlightJson = highlightJson;
|
|
4
|
+
const ansi_1 = require("./ansi");
|
|
5
|
+
function highlightJson(json) {
|
|
6
|
+
if (!json)
|
|
7
|
+
return '';
|
|
8
|
+
// Regex for JSON tokens
|
|
9
|
+
// Captures:
|
|
10
|
+
// 1. Strings (potentially keys if followed by :)
|
|
11
|
+
// 2. Numbers
|
|
12
|
+
// 3. Booleans/Null
|
|
13
|
+
// 4. Punctuation
|
|
14
|
+
const tokenRegex = /("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?)|(-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)|(true|false|null)|([{}[\],:])/g;
|
|
15
|
+
return json.replace(tokenRegex, (match) => {
|
|
16
|
+
// String
|
|
17
|
+
if (match.startsWith('"')) {
|
|
18
|
+
// Check if it's a key (ends with :)
|
|
19
|
+
if (match.trim().endsWith(':')) {
|
|
20
|
+
const colonIndex = match.lastIndexOf(':');
|
|
21
|
+
const keyPart = match.substring(0, colonIndex);
|
|
22
|
+
const colonPart = match.substring(colonIndex);
|
|
23
|
+
// Key in Cyan
|
|
24
|
+
return `${ansi_1.ANSI.FG_CYAN}${keyPart}${ansi_1.ANSI.RESET}${colonPart}`;
|
|
25
|
+
}
|
|
26
|
+
// String value in Green
|
|
27
|
+
return `${ansi_1.ANSI.FG_GREEN}${match}${ansi_1.ANSI.RESET}`;
|
|
28
|
+
}
|
|
29
|
+
// Number in Yellow
|
|
30
|
+
if (/^-?\d/.test(match)) {
|
|
31
|
+
return `${ansi_1.ANSI.FG_YELLOW}${match}${ansi_1.ANSI.RESET}`;
|
|
32
|
+
}
|
|
33
|
+
// Boolean/Null in Red (or Magenta if available, using Red for now)
|
|
34
|
+
if (/^(true|false|null)$/.test(match)) {
|
|
35
|
+
return `${ansi_1.ANSI.FG_RED}${match}${ansi_1.ANSI.RESET}`;
|
|
36
|
+
}
|
|
37
|
+
// Punctuation in White (or default)
|
|
38
|
+
return `${ansi_1.ANSI.FG_WHITE}${match}${ansi_1.ANSI.RESET}`;
|
|
39
|
+
});
|
|
40
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/input.js
CHANGED
|
@@ -92,23 +92,32 @@ class InputParser extends events_1.EventEmitter {
|
|
|
92
92
|
if (parts.length >= 3) {
|
|
93
93
|
const [b, x, y] = parts;
|
|
94
94
|
let action = 'press';
|
|
95
|
+
// Extract modifiers
|
|
96
|
+
const shift = !!(b & 4);
|
|
97
|
+
const meta = !!(b & 8);
|
|
98
|
+
const ctrl = !!(b & 16);
|
|
95
99
|
// Interpret button codes
|
|
96
100
|
// 0: Left, 1: Middle, 2: Right
|
|
97
101
|
// +32: Motion
|
|
98
|
-
// 64: Scroll
|
|
99
|
-
|
|
100
|
-
if (b === 64) {
|
|
102
|
+
// 64: Scroll (bit 6)
|
|
103
|
+
if (b & 64) {
|
|
101
104
|
action = 'scroll';
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
const scroll = (b & 1) ? 'down' : 'up';
|
|
106
|
+
this.emit('mouse', {
|
|
107
|
+
name: 'mouse',
|
|
108
|
+
x,
|
|
109
|
+
y,
|
|
110
|
+
button: 0,
|
|
111
|
+
action,
|
|
112
|
+
scroll,
|
|
113
|
+
shift,
|
|
114
|
+
ctrl,
|
|
115
|
+
meta
|
|
116
|
+
});
|
|
117
|
+
if (scroll === 'up')
|
|
118
|
+
this.emit('scrollup');
|
|
119
|
+
else
|
|
120
|
+
this.emit('scrolldown');
|
|
112
121
|
return;
|
|
113
122
|
}
|
|
114
123
|
if (type === 'm') {
|
|
@@ -126,7 +135,10 @@ class InputParser extends events_1.EventEmitter {
|
|
|
126
135
|
x,
|
|
127
136
|
y,
|
|
128
137
|
button: b & 3, // Strip modifiers to get raw button 0-2
|
|
129
|
-
action
|
|
138
|
+
action,
|
|
139
|
+
shift,
|
|
140
|
+
ctrl,
|
|
141
|
+
meta
|
|
130
142
|
});
|
|
131
143
|
}
|
|
132
144
|
}
|
|
@@ -16,7 +16,7 @@ export declare class AutocompletePrompt<V> extends Prompt<V, AutocompleteOptions
|
|
|
16
16
|
private startSpinner;
|
|
17
17
|
private stopSpinner;
|
|
18
18
|
protected cleanup(): void;
|
|
19
|
-
protected render(
|
|
19
|
+
protected render(_firstRender: boolean): void;
|
|
20
20
|
protected handleInput(char: string): void;
|
|
21
21
|
protected handleMouse(event: MouseEvent): void;
|
|
22
22
|
}
|
|
@@ -36,7 +36,7 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
36
36
|
this.scrollTop = 0;
|
|
37
37
|
this.hasSearched = true;
|
|
38
38
|
}
|
|
39
|
-
catch (
|
|
39
|
+
catch (_err) {
|
|
40
40
|
this.choices = [];
|
|
41
41
|
}
|
|
42
42
|
finally {
|
|
@@ -64,15 +64,10 @@ class AutocompletePrompt extends base_1.Prompt {
|
|
|
64
64
|
this.stopSpinner();
|
|
65
65
|
super.cleanup();
|
|
66
66
|
}
|
|
67
|
-
render(
|
|
68
|
-
// --- FIX START: Restore cursor position ---
|
|
69
|
-
// renderFrame() in Base assumes the cursor is at the bottom of the output.
|
|
70
|
-
// Since Autocomplete moves the cursor to the top (for input) after rendering,
|
|
71
|
-
// we must manually move it back down before the next render cycle.
|
|
67
|
+
render(_firstRender) {
|
|
72
68
|
if (this.lastRenderHeight > 1) {
|
|
73
69
|
this.print(`\x1b[${this.lastRenderHeight - 1}B`); // Move down
|
|
74
70
|
}
|
|
75
|
-
// --- FIX END ---
|
|
76
71
|
let output = '';
|
|
77
72
|
// Header
|
|
78
73
|
const icon = this.loading ? `${theme_1.theme.main}${symbols_1.symbols.spinner[this.spinnerFrame]}${ansi_1.ANSI.RESET}` : `${theme_1.theme.success}?${ansi_1.ANSI.RESET}`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { CalendarOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class CalendarPrompt extends Prompt<Date | [Date, Date], CalendarOptions> {
|
|
4
|
+
private cursor;
|
|
5
|
+
private viewDate;
|
|
6
|
+
private selection;
|
|
7
|
+
private selectingRange;
|
|
8
|
+
constructor(options: CalendarOptions);
|
|
9
|
+
private getDaysInMonth;
|
|
10
|
+
private getDayOfWeek;
|
|
11
|
+
private generateMonthGrid;
|
|
12
|
+
private isSameDay;
|
|
13
|
+
private isSelected;
|
|
14
|
+
private isRangeStart;
|
|
15
|
+
protected render(_firstRender: boolean): void;
|
|
16
|
+
private syncViewDate;
|
|
17
|
+
private alignCursorToViewDate;
|
|
18
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
19
|
+
protected handleMouse(event: MouseEvent): void;
|
|
20
|
+
}
|