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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeypressPrompt = void 0;
|
|
4
|
+
const ansi_1 = require("../ansi");
|
|
5
|
+
const base_1 = require("../base");
|
|
6
|
+
const theme_1 = require("../theme");
|
|
7
|
+
class KeypressPrompt extends base_1.Prompt {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
}
|
|
11
|
+
render(_firstRender) {
|
|
12
|
+
let output = `${theme_1.theme.title}${this.options.message}${ansi_1.ANSI.RESET}`;
|
|
13
|
+
if (this.options.keys) {
|
|
14
|
+
const hint = this.options.keys.map(k => {
|
|
15
|
+
if (k === '\r' || k === '\n' || k === 'enter')
|
|
16
|
+
return 'enter';
|
|
17
|
+
if (k === ' ' || k === 'space')
|
|
18
|
+
return 'space';
|
|
19
|
+
return k;
|
|
20
|
+
}).join('/');
|
|
21
|
+
// Only show hint if it's short enough to be helpful, or always?
|
|
22
|
+
// Let's always show it if provided, or maybe just dimmed.
|
|
23
|
+
output += ` ${theme_1.theme.muted}(${hint})${ansi_1.ANSI.RESET}`;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
output += ` ${theme_1.theme.muted}(Press any key)${ansi_1.ANSI.RESET}`;
|
|
27
|
+
}
|
|
28
|
+
this.renderFrame(output);
|
|
29
|
+
}
|
|
30
|
+
handleInput(char, _key) {
|
|
31
|
+
let keyName = char;
|
|
32
|
+
if (char === '\r' || char === '\n')
|
|
33
|
+
keyName = 'enter';
|
|
34
|
+
else if (char === ' ')
|
|
35
|
+
keyName = 'space';
|
|
36
|
+
else if (char === '\u001b')
|
|
37
|
+
keyName = 'escape';
|
|
38
|
+
else if (char === '\t')
|
|
39
|
+
keyName = 'tab';
|
|
40
|
+
// Handle backspace
|
|
41
|
+
else if (char === '\x7f' || char === '\b')
|
|
42
|
+
keyName = 'backspace';
|
|
43
|
+
// Check against whitelist
|
|
44
|
+
if (this.options.keys) {
|
|
45
|
+
const allowed = this.options.keys.map(k => k.toLowerCase());
|
|
46
|
+
// Check normalized name or exact char
|
|
47
|
+
if (!allowed.includes(keyName) && !allowed.includes(char)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (this.options.showInvisible) {
|
|
52
|
+
this.print(` ${theme_1.theme.success}${keyName}${ansi_1.ANSI.RESET}`);
|
|
53
|
+
}
|
|
54
|
+
this.submit(keyName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.KeypressPrompt = KeypressPrompt;
|
package/dist/prompts/list.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare class ListPrompt extends Prompt<string[], ListOptions> {
|
|
|
4
4
|
private currentInput;
|
|
5
5
|
private errorMsg;
|
|
6
6
|
constructor(options: ListOptions);
|
|
7
|
-
protected render(
|
|
7
|
+
protected render(_firstRender: boolean): void;
|
|
8
8
|
protected handleInput(char: string): void;
|
|
9
9
|
}
|
package/dist/prompts/list.js
CHANGED
|
@@ -13,38 +13,57 @@ class ListPrompt extends base_1.Prompt {
|
|
|
13
13
|
this.errorMsg = '';
|
|
14
14
|
this.value = options.initial || [];
|
|
15
15
|
}
|
|
16
|
-
render(
|
|
17
|
-
|
|
16
|
+
render(_firstRender) {
|
|
17
|
+
const cols = process.stdout.columns || 80;
|
|
18
|
+
// 1. Prepare Prefix
|
|
18
19
|
const icon = this.errorMsg ? `${theme_1.theme.error}${symbols_1.symbols.cross}` : `${theme_1.theme.success}?`;
|
|
19
|
-
|
|
20
|
+
const prefix = `${icon} ${ansi_1.ANSI.BOLD}${theme_1.theme.title}${this.options.message}${ansi_1.ANSI.RESET} `;
|
|
21
|
+
// 2. Build Lines with Wrapping
|
|
22
|
+
const lines = [];
|
|
23
|
+
let currentLine = prefix;
|
|
24
|
+
// Helper to check width
|
|
25
|
+
const addText = (text) => {
|
|
26
|
+
const visualLen = this.stripAnsi(currentLine).length + this.stripAnsi(text).length;
|
|
27
|
+
if (visualLen > cols) {
|
|
28
|
+
lines.push(currentLine);
|
|
29
|
+
currentLine = text.trimStart(); // Start new line
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
currentLine += text;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
20
35
|
// Render Tags
|
|
21
36
|
if (this.value.length > 0) {
|
|
22
37
|
this.value.forEach((tag) => {
|
|
23
|
-
|
|
38
|
+
const tagStr = `${theme_1.theme.main}[${tag}]${ansi_1.ANSI.RESET} `;
|
|
39
|
+
addText(tagStr);
|
|
24
40
|
});
|
|
25
41
|
}
|
|
26
42
|
// Render Current Input
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
addText(this.currentInput);
|
|
44
|
+
lines.push(currentLine); // Push the last line
|
|
45
|
+
// Track where the input ends (for cursor positioning)
|
|
46
|
+
const inputLineIndex = lines.length - 1;
|
|
47
|
+
const inputVisualCol = this.stripAnsi(currentLine).length;
|
|
48
|
+
// 3. Append Error if any
|
|
29
49
|
if (this.errorMsg) {
|
|
30
|
-
|
|
50
|
+
lines.push(`${theme_1.theme.error}>> ${this.errorMsg}${ansi_1.ANSI.RESET}`);
|
|
31
51
|
}
|
|
32
|
-
|
|
52
|
+
const output = lines.join('\n');
|
|
53
|
+
// 4. Render Frame
|
|
33
54
|
this.renderFrame(output);
|
|
34
55
|
this.print(ansi_1.ANSI.SHOW_CURSOR);
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.print(`\x1b[${visualLength}C`);
|
|
47
|
-
}
|
|
56
|
+
// 5. Position Cursor
|
|
57
|
+
// If we printed lines after the input line (e.g. error msg), move up.
|
|
58
|
+
const totalRows = lines.length;
|
|
59
|
+
const linesUp = (totalRows - 1) - inputLineIndex;
|
|
60
|
+
if (linesUp > 0) {
|
|
61
|
+
this.print(`\x1b[${linesUp}A`);
|
|
62
|
+
}
|
|
63
|
+
// Move to correct column
|
|
64
|
+
this.print(ansi_1.ANSI.CURSOR_LEFT);
|
|
65
|
+
if (inputVisualCol > 0) {
|
|
66
|
+
this.print(`\x1b[${inputVisualCol}C`);
|
|
48
67
|
}
|
|
49
68
|
}
|
|
50
69
|
handleInput(char) {
|
|
@@ -75,7 +94,8 @@ class ListPrompt extends base_1.Prompt {
|
|
|
75
94
|
this.render(false);
|
|
76
95
|
}
|
|
77
96
|
else if (this.value.length > 0) {
|
|
78
|
-
this.value.pop();
|
|
97
|
+
const last = this.value.pop();
|
|
98
|
+
this.currentInput = last || '';
|
|
79
99
|
this.render(false);
|
|
80
100
|
}
|
|
81
101
|
return;
|
|
@@ -9,7 +9,7 @@ export declare class MultiSelectPrompt<V> extends Prompt<any[], MultiSelectOptio
|
|
|
9
9
|
private errorMsg;
|
|
10
10
|
constructor(options: MultiSelectOptions<V>);
|
|
11
11
|
private getFilteredChoices;
|
|
12
|
-
protected render(
|
|
12
|
+
protected render(_firstRender: boolean): void;
|
|
13
13
|
protected handleInput(char: string): void;
|
|
14
14
|
protected handleMouse(event: MouseEvent): void;
|
|
15
15
|
}
|
|
@@ -24,7 +24,7 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
24
24
|
.map((c, i) => ({ ...c, originalIndex: i }))
|
|
25
25
|
.filter(c => c.title.toLowerCase().includes(this.searchBuffer.toLowerCase()));
|
|
26
26
|
}
|
|
27
|
-
render(
|
|
27
|
+
render(_firstRender) {
|
|
28
28
|
let output = '';
|
|
29
29
|
const choices = this.getFilteredChoices();
|
|
30
30
|
// Adjust Scroll
|
|
@@ -41,7 +41,7 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
41
41
|
const searchStr = this.searchBuffer ? ` ${theme_1.theme.muted}(Filter: ${this.searchBuffer})${ansi_1.ANSI.RESET}` : '';
|
|
42
42
|
output += `${icon} ${ansi_1.ANSI.BOLD}${theme_1.theme.title}${this.options.message}${ansi_1.ANSI.RESET}${searchStr}\n`;
|
|
43
43
|
if (choices.length === 0) {
|
|
44
|
-
output += ` ${theme_1.theme.muted}No results found${ansi_1.ANSI.RESET}`;
|
|
44
|
+
output += ` ${theme_1.theme.muted}No results found${ansi_1.ANSI.RESET}`;
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
const visible = choices.slice(this.scrollTop, this.scrollTop + this.pageSize);
|
|
@@ -57,6 +57,10 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
57
57
|
output += `${cursor} ${checkbox} ${choice.title}`;
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
+
// Hints
|
|
61
|
+
if (!this.searchBuffer && !this.errorMsg) {
|
|
62
|
+
output += `\n${ansi_1.ANSI.DIM}(Ctrl+A: All, Ctrl+X: None)${ansi_1.ANSI.RESET}`;
|
|
63
|
+
}
|
|
60
64
|
if (this.errorMsg) {
|
|
61
65
|
output += `\n${theme_1.theme.error}>> ${this.errorMsg}${ansi_1.ANSI.RESET}`;
|
|
62
66
|
}
|
|
@@ -64,6 +68,7 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
64
68
|
}
|
|
65
69
|
handleInput(char) {
|
|
66
70
|
const choices = this.getFilteredChoices();
|
|
71
|
+
// Enter
|
|
67
72
|
if (char === '\r' || char === '\n') {
|
|
68
73
|
const selectedCount = this.checkedState.filter(Boolean).length;
|
|
69
74
|
const { min = 0, max } = this.options;
|
|
@@ -83,6 +88,35 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
83
88
|
this.submit(results);
|
|
84
89
|
return;
|
|
85
90
|
}
|
|
91
|
+
// --- Batch Shortcuts (Visible Items Only) ---
|
|
92
|
+
// Ctrl+A (\x01): Select All Visible
|
|
93
|
+
if (char === '\x01') {
|
|
94
|
+
const newCheckedState = [...this.checkedState];
|
|
95
|
+
let potentialAdd = 0;
|
|
96
|
+
// Calculate potential selections
|
|
97
|
+
choices.forEach(c => {
|
|
98
|
+
if (!newCheckedState[c.originalIndex])
|
|
99
|
+
potentialAdd++;
|
|
100
|
+
});
|
|
101
|
+
const currentSelected = newCheckedState.filter(Boolean).length;
|
|
102
|
+
if (this.options.max && (currentSelected + potentialAdd) > this.options.max) {
|
|
103
|
+
this.errorMsg = `Max limit ${this.options.max} reached`;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
choices.forEach(c => newCheckedState[c.originalIndex] = true);
|
|
107
|
+
this.checkedState = newCheckedState;
|
|
108
|
+
this.errorMsg = '';
|
|
109
|
+
}
|
|
110
|
+
this.render(false);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Ctrl+X (\x18): Deselect All Visible
|
|
114
|
+
if (char === '\x18') {
|
|
115
|
+
choices.forEach(c => this.checkedState[c.originalIndex] = false);
|
|
116
|
+
this.errorMsg = '';
|
|
117
|
+
this.render(false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
86
120
|
if (char === ' ') {
|
|
87
121
|
if (choices.length > 0) {
|
|
88
122
|
const choice = choices[this.selectedIndex];
|
|
@@ -92,14 +126,14 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
92
126
|
}
|
|
93
127
|
return;
|
|
94
128
|
}
|
|
95
|
-
if (this.isUp(char)) {
|
|
129
|
+
if (this.isUp(char)) {
|
|
96
130
|
if (choices.length > 0) {
|
|
97
131
|
this.selectedIndex = (this.selectedIndex - 1 + choices.length) % choices.length;
|
|
98
132
|
this.render(false);
|
|
99
133
|
}
|
|
100
134
|
return;
|
|
101
135
|
}
|
|
102
|
-
if (this.isDown(char)) {
|
|
136
|
+
if (this.isDown(char)) {
|
|
103
137
|
if (choices.length > 0) {
|
|
104
138
|
this.selectedIndex = (this.selectedIndex + 1) % choices.length;
|
|
105
139
|
this.render(false);
|
|
@@ -114,6 +148,7 @@ class MultiSelectPrompt extends base_1.Prompt {
|
|
|
114
148
|
}
|
|
115
149
|
return;
|
|
116
150
|
}
|
|
151
|
+
// Typing search
|
|
117
152
|
if (!/^[\x00-\x1F]/.test(char) && !char.startsWith('\x1b')) {
|
|
118
153
|
this.searchBuffer += char;
|
|
119
154
|
this.selectedIndex = 0;
|
package/dist/prompts/number.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class NumberPrompt extends Prompt<number, NumberOptions> {
|
|
|
5
5
|
private cursor;
|
|
6
6
|
private errorMsg;
|
|
7
7
|
constructor(options: NumberOptions);
|
|
8
|
-
protected render(
|
|
8
|
+
protected render(_firstRender: boolean): void;
|
|
9
9
|
protected handleInput(char: string): void;
|
|
10
10
|
protected handleMouse(event: MouseEvent): void;
|
|
11
11
|
}
|
package/dist/prompts/number.js
CHANGED
|
@@ -17,7 +17,7 @@ class NumberPrompt extends base_1.Prompt {
|
|
|
17
17
|
this.stringValue = options.initial !== undefined ? options.initial.toString() : '';
|
|
18
18
|
this.cursor = this.stringValue.length;
|
|
19
19
|
}
|
|
20
|
-
render(
|
|
20
|
+
render(_firstRender) {
|
|
21
21
|
// Prepare content
|
|
22
22
|
const icon = this.errorMsg ? `${theme_1.theme.error}${symbols_1.symbols.cross}` : `${theme_1.theme.success}?`;
|
|
23
23
|
// Prefix
|
|
@@ -122,7 +122,7 @@ class NumberPrompt extends base_1.Prompt {
|
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
// Numeric Input (and . and -)
|
|
125
|
-
if (/^[0-9
|
|
125
|
+
if (/^[0-9.-]+$/.test(char)) {
|
|
126
126
|
// Allow if it looks like a number part
|
|
127
127
|
this.stringValue = this.stringValue.slice(0, this.cursor) + char + this.stringValue.slice(this.cursor);
|
|
128
128
|
this.cursor += char.length;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { RangeOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class RangePrompt extends Prompt<[number, number], RangeOptions> {
|
|
4
|
+
private activeHandle;
|
|
5
|
+
constructor(options: RangeOptions);
|
|
6
|
+
protected render(_firstRender: boolean): void;
|
|
7
|
+
protected handleInput(char: string): void;
|
|
8
|
+
protected handleMouse(event: MouseEvent): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RangePrompt = void 0;
|
|
4
|
+
const ansi_1 = require("../ansi");
|
|
5
|
+
const base_1 = require("../base");
|
|
6
|
+
const theme_1 = require("../theme");
|
|
7
|
+
const symbols_1 = require("../symbols");
|
|
8
|
+
class RangePrompt extends base_1.Prompt {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options);
|
|
11
|
+
this.activeHandle = 'low';
|
|
12
|
+
// Ensure initial is sorted and within bounds, default to [min, max] if not provided
|
|
13
|
+
const initial = options.initial || [options.min, options.max];
|
|
14
|
+
// Basic validation for initial
|
|
15
|
+
let [low, high] = initial;
|
|
16
|
+
low = Math.max(options.min, Math.min(low, options.max));
|
|
17
|
+
high = Math.max(options.min, Math.min(high, options.max));
|
|
18
|
+
if (low > high) {
|
|
19
|
+
[low, high] = [high, low];
|
|
20
|
+
}
|
|
21
|
+
this.value = [low, high];
|
|
22
|
+
}
|
|
23
|
+
render(_firstRender) {
|
|
24
|
+
const width = 20;
|
|
25
|
+
const range = this.options.max - this.options.min;
|
|
26
|
+
const [low, high] = this.value;
|
|
27
|
+
// Calculate positions (0 to width)
|
|
28
|
+
// Avoid division by zero if min == max
|
|
29
|
+
const ratioLow = range === 0 ? 0 : (low - this.options.min) / range;
|
|
30
|
+
const posLow = Math.round(ratioLow * width);
|
|
31
|
+
const ratioHigh = range === 0 ? 1 : (high - this.options.min) / range;
|
|
32
|
+
const posHigh = Math.round(ratioHigh * width);
|
|
33
|
+
let bar = '';
|
|
34
|
+
for (let i = 0; i <= width; i++) {
|
|
35
|
+
if (i === posLow && i === posHigh) {
|
|
36
|
+
// Collision
|
|
37
|
+
bar += `${theme_1.theme.main}|${ansi_1.ANSI.RESET}`;
|
|
38
|
+
}
|
|
39
|
+
else if (i === posLow) {
|
|
40
|
+
if (this.activeHandle === 'low') {
|
|
41
|
+
// Highlight active handle
|
|
42
|
+
bar += `${theme_1.theme.main}${ansi_1.ANSI.REVERSE}O${ansi_1.ANSI.RESET}`;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
bar += `${theme_1.theme.main}O${ansi_1.ANSI.RESET}`;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (i === posHigh) {
|
|
49
|
+
if (this.activeHandle === 'high') {
|
|
50
|
+
// Highlight active handle
|
|
51
|
+
bar += `${theme_1.theme.main}${ansi_1.ANSI.REVERSE}O${ansi_1.ANSI.RESET}`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
bar += `${theme_1.theme.main}O${ansi_1.ANSI.RESET}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (i > posLow && i < posHigh) {
|
|
58
|
+
// Active range
|
|
59
|
+
bar += `${theme_1.theme.main}=${ansi_1.ANSI.RESET}`;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Dimmed
|
|
63
|
+
bar += symbols_1.symbols.line;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const unit = this.options.unit || '';
|
|
67
|
+
// Format the value display
|
|
68
|
+
let valueDisplay = '';
|
|
69
|
+
if (this.activeHandle === 'low') {
|
|
70
|
+
valueDisplay = `${ansi_1.ANSI.UNDERLINE}${low}${ansi_1.ANSI.RESET}-${high}`;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
valueDisplay = `${low}-${ansi_1.ANSI.UNDERLINE}${high}${ansi_1.ANSI.RESET}`;
|
|
74
|
+
}
|
|
75
|
+
const output = `${theme_1.theme.success}?${ansi_1.ANSI.RESET} ${ansi_1.ANSI.BOLD}${theme_1.theme.title}${this.options.message}${ansi_1.ANSI.RESET} [${bar}] ${valueDisplay}${unit}`;
|
|
76
|
+
this.renderFrame(output);
|
|
77
|
+
}
|
|
78
|
+
handleInput(char) {
|
|
79
|
+
if (char === '\r' || char === '\n') {
|
|
80
|
+
this.submit(this.value);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (char === ' ' || char === '\t') {
|
|
84
|
+
this.activeHandle = this.activeHandle === 'low' ? 'high' : 'low';
|
|
85
|
+
this.render(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const step = this.options.step || 1;
|
|
89
|
+
let [low, high] = this.value;
|
|
90
|
+
if (this.isLeft(char)) { // Left
|
|
91
|
+
if (this.activeHandle === 'low') {
|
|
92
|
+
low = Math.max(this.options.min, low - step);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
high = Math.max(low, high - step);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (this.isRight(char)) { // Right
|
|
99
|
+
if (this.activeHandle === 'low') {
|
|
100
|
+
low = Math.min(high, low + step);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
high = Math.min(this.options.max, high + step);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Rounding to avoid floating point errors
|
|
107
|
+
low = Math.round(low * 10000) / 10000;
|
|
108
|
+
high = Math.round(high * 10000) / 10000;
|
|
109
|
+
this.value = [low, high];
|
|
110
|
+
this.render(false);
|
|
111
|
+
}
|
|
112
|
+
handleMouse(event) {
|
|
113
|
+
if (event.action === 'scroll') {
|
|
114
|
+
const step = this.options.step || 1;
|
|
115
|
+
let [low, high] = this.value;
|
|
116
|
+
if (event.scroll === 'up') { // Increase
|
|
117
|
+
if (this.activeHandle === 'low') {
|
|
118
|
+
low = Math.min(high, low + step);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
high = Math.min(this.options.max, high + step);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (event.scroll === 'down') { // Decrease
|
|
125
|
+
if (this.activeHandle === 'low') {
|
|
126
|
+
low = Math.max(this.options.min, low - step);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
high = Math.max(low, high - step);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Rounding
|
|
133
|
+
low = Math.round(low * 10000) / 10000;
|
|
134
|
+
high = Math.round(high * 10000) / 10000;
|
|
135
|
+
this.value = [low, high];
|
|
136
|
+
this.render(false);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.RangePrompt = RangePrompt;
|
package/dist/prompts/rating.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Prompt } from '../base';
|
|
|
2
2
|
import { RatingOptions, MouseEvent } from '../types';
|
|
3
3
|
export declare class RatingPrompt extends Prompt<number, RatingOptions> {
|
|
4
4
|
constructor(options: RatingOptions);
|
|
5
|
-
protected render(
|
|
5
|
+
protected render(_firstRender: boolean): void;
|
|
6
6
|
protected handleInput(char: string): void;
|
|
7
7
|
protected handleMouse(event: MouseEvent): void;
|
|
8
8
|
}
|
package/dist/prompts/rating.js
CHANGED
|
@@ -11,7 +11,7 @@ class RatingPrompt extends base_1.Prompt {
|
|
|
11
11
|
// Default to min if initial is not provided
|
|
12
12
|
this.value = options.initial ?? (options.min || 1);
|
|
13
13
|
}
|
|
14
|
-
render(
|
|
14
|
+
render(_firstRender) {
|
|
15
15
|
const min = this.options.min || 1;
|
|
16
16
|
const max = this.options.max || 5;
|
|
17
17
|
// Render stars
|
package/dist/prompts/select.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare class SelectPrompt<V> extends Prompt<any, SelectOptions<V>> {
|
|
|
9
9
|
private isSeparator;
|
|
10
10
|
private findNextSelectableIndex;
|
|
11
11
|
private getFilteredChoices;
|
|
12
|
-
protected render(
|
|
12
|
+
protected render(_firstRender: boolean): void;
|
|
13
13
|
protected handleInput(char: string): void;
|
|
14
14
|
protected handleMouse(event: MouseEvent): void;
|
|
15
15
|
}
|
package/dist/prompts/select.js
CHANGED
|
@@ -50,7 +50,7 @@ class SelectPrompt extends base_1.Prompt {
|
|
|
50
50
|
return c.title.toLowerCase().includes(this.searchBuffer.toLowerCase());
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
render(
|
|
53
|
+
render(_firstRender) {
|
|
54
54
|
let output = '';
|
|
55
55
|
const choices = this.getFilteredChoices();
|
|
56
56
|
// Adjust Scroll Top
|
package/dist/prompts/slider.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Prompt } from '../base';
|
|
|
2
2
|
import { SliderOptions, MouseEvent } from '../types';
|
|
3
3
|
export declare class SliderPrompt extends Prompt<number, SliderOptions> {
|
|
4
4
|
constructor(options: SliderOptions);
|
|
5
|
-
protected render(
|
|
5
|
+
protected render(_firstRender: boolean): void;
|
|
6
6
|
protected handleInput(char: string): void;
|
|
7
7
|
protected handleMouse(event: MouseEvent): void;
|
|
8
8
|
}
|
package/dist/prompts/slider.js
CHANGED
|
@@ -11,7 +11,7 @@ class SliderPrompt extends base_1.Prompt {
|
|
|
11
11
|
super(options);
|
|
12
12
|
this.value = options.initial ?? options.min;
|
|
13
13
|
}
|
|
14
|
-
render(
|
|
14
|
+
render(_firstRender) {
|
|
15
15
|
const width = 20;
|
|
16
16
|
const range = this.options.max - this.options.min;
|
|
17
17
|
const ratio = (this.value - this.options.min) / range;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Prompt } from '../base';
|
|
2
|
+
import { SnippetOptions, MouseEvent } from '../types';
|
|
3
|
+
export declare class SnippetPrompt extends Prompt<string, SnippetOptions> {
|
|
4
|
+
private tokens;
|
|
5
|
+
private variableTokens;
|
|
6
|
+
private values;
|
|
7
|
+
private activeVarIndex;
|
|
8
|
+
private cursor;
|
|
9
|
+
private errorMsg;
|
|
10
|
+
private lastLinesUp;
|
|
11
|
+
constructor(options: SnippetOptions);
|
|
12
|
+
private parseTemplate;
|
|
13
|
+
protected render(firstRender: boolean): void;
|
|
14
|
+
protected handleInput(char: string, _key: Buffer): void;
|
|
15
|
+
protected handleMouse(event: MouseEvent): void;
|
|
16
|
+
private moveFocus;
|
|
17
|
+
private submitSnippet;
|
|
18
|
+
}
|