mepcli 2.0.0-beta.2 → 2.0.0-beta.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/dist/ansi.d.ts +36 -0
- package/dist/ansi.js +1 -0
- package/dist/base.d.ts +60 -0
- package/dist/base.js +1 -0
- package/dist/{src/core.js → core.d.ts} +175 -345
- package/dist/core.js +1 -0
- package/dist/data/countries.d.ts +2 -0
- package/dist/data/countries.js +1 -0
- package/dist/data/licenses.d.ts +2 -0
- package/dist/data/licenses.js +1 -0
- package/dist/highlight.d.ts +7 -0
- package/dist/highlight.js +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +1 -0
- package/dist/input.d.ts +14 -0
- package/dist/input.js +1 -0
- package/dist/pipeline.d.ts +90 -0
- package/dist/pipeline.js +1 -0
- package/dist/prompts/autocomplete.d.ts +22 -0
- package/dist/prompts/autocomplete.js +1 -0
- package/dist/prompts/box.d.ts +21 -0
- package/dist/prompts/box.js +4 -0
- package/dist/prompts/breadcrumb-search.d.ts +14 -0
- package/dist/prompts/breadcrumb-search.js +2 -0
- package/dist/prompts/breadcrumb.d.ts +32 -0
- package/dist/prompts/breadcrumb.js +3 -0
- package/dist/prompts/byte.d.ts +13 -0
- package/dist/prompts/byte.js +5 -0
- package/dist/prompts/calculator.d.ts +17 -0
- package/dist/prompts/calculator.js +3 -0
- package/dist/prompts/calendar.d.ts +33 -0
- package/dist/prompts/calendar.js +3 -0
- package/dist/prompts/checkbox.d.ts +13 -0
- package/dist/prompts/checkbox.js +2 -0
- package/dist/prompts/code.d.ts +19 -0
- package/dist/prompts/code.js +4 -0
- package/dist/prompts/color.d.ts +14 -0
- package/dist/prompts/color.js +10 -0
- package/dist/prompts/confirm.d.ts +8 -0
- package/dist/prompts/confirm.js +1 -0
- package/dist/prompts/connection-string.d.ts +18 -0
- package/dist/prompts/connection-string.js +1 -0
- package/dist/prompts/cron.d.ts +13 -0
- package/dist/prompts/cron.js +4 -0
- package/dist/prompts/curl-utils.d.ts +25 -0
- package/dist/prompts/curl-utils.js +1 -0
- package/dist/prompts/curl.d.ts +41 -0
- package/dist/prompts/curl.js +12 -0
- package/dist/prompts/data-inspector.d.ts +22 -0
- package/dist/prompts/data-inspector.js +5 -0
- package/dist/prompts/date.d.ts +12 -0
- package/dist/prompts/date.js +2 -0
- package/dist/prompts/dependency.d.ts +16 -0
- package/dist/prompts/dependency.js +3 -0
- package/dist/prompts/dial.d.ts +10 -0
- package/dist/prompts/dial.js +3 -0
- package/dist/prompts/diff.d.ts +10 -0
- package/dist/prompts/diff.js +10 -0
- package/dist/prompts/draw.d.ts +20 -0
- package/dist/prompts/draw.js +6 -0
- package/dist/prompts/editor.d.ts +14 -0
- package/dist/prompts/editor.js +2 -0
- package/dist/prompts/emoji.d.ts +18 -0
- package/dist/prompts/emoji.js +5 -0
- package/dist/prompts/exec.d.ts +17 -0
- package/dist/prompts/exec.js +1 -0
- package/dist/prompts/file.d.ts +21 -0
- package/dist/prompts/file.js +2 -0
- package/dist/prompts/form.d.ts +18 -0
- package/dist/prompts/form.js +1 -0
- package/dist/prompts/fuzzy-multi-column.d.ts +12 -0
- package/dist/prompts/fuzzy-multi-column.js +2 -0
- package/dist/prompts/fuzzy.d.ts +12 -0
- package/dist/prompts/fuzzy.js +2 -0
- package/dist/prompts/gauge.d.ts +21 -0
- package/dist/prompts/gauge.js +4 -0
- package/dist/prompts/grid.d.ts +14 -0
- package/dist/prompts/grid.js +2 -0
- package/dist/prompts/heatmap.d.ts +13 -0
- package/dist/prompts/heatmap.js +2 -0
- package/dist/prompts/ip.d.ts +11 -0
- package/dist/prompts/ip.js +3 -0
- package/dist/prompts/kanban.d.ts +17 -0
- package/dist/prompts/kanban.js +4 -0
- package/dist/prompts/keypress.d.ts +7 -0
- package/dist/prompts/keypress.js +1 -0
- package/dist/prompts/license.d.ts +9 -0
- package/dist/prompts/license.js +13 -0
- package/dist/prompts/list.d.ts +9 -0
- package/dist/prompts/list.js +1 -0
- package/dist/prompts/map.d.ts +17 -0
- package/dist/prompts/map.js +5 -0
- package/dist/prompts/match.d.ts +19 -0
- package/dist/prompts/match.js +7 -0
- package/dist/prompts/miller.d.ts +15 -0
- package/dist/prompts/miller.js +2 -0
- package/dist/prompts/multi-column-select.d.ts +10 -0
- package/dist/prompts/multi-column-select.js +2 -0
- package/dist/prompts/multi-range.d.ts +9 -0
- package/dist/prompts/multi-range.js +3 -0
- package/dist/prompts/multi-select.d.ts +15 -0
- package/dist/prompts/multi-select.js +4 -0
- package/dist/prompts/number.d.ts +11 -0
- package/dist/prompts/number.js +2 -0
- package/dist/prompts/otp.d.ts +10 -0
- package/dist/prompts/otp.js +2 -0
- package/dist/prompts/pattern.d.ts +22 -0
- package/dist/prompts/pattern.js +4 -0
- package/dist/prompts/phone.d.ts +41 -0
- package/dist/prompts/phone.js +3 -0
- package/dist/prompts/quiz-select.d.ts +10 -0
- package/dist/prompts/quiz-select.js +7 -0
- package/dist/prompts/quiz-text.d.ts +11 -0
- package/dist/prompts/quiz-text.js +8 -0
- package/dist/prompts/range.d.ts +9 -0
- package/dist/prompts/range.js +1 -0
- package/dist/prompts/rating.d.ts +8 -0
- package/dist/prompts/rating.js +1 -0
- package/dist/prompts/regex.d.ts +13 -0
- package/dist/prompts/regex.js +5 -0
- package/dist/prompts/region.d.ts +11 -0
- package/dist/prompts/region.js +5 -0
- package/dist/prompts/schedule.d.ts +20 -0
- package/dist/prompts/schedule.js +5 -0
- package/dist/prompts/scroll.d.ts +13 -0
- package/dist/prompts/scroll.js +1 -0
- package/dist/prompts/seat.d.ts +17 -0
- package/dist/prompts/seat.js +5 -0
- package/dist/prompts/select-range.d.ts +8 -0
- package/dist/prompts/select-range.js +3 -0
- package/dist/prompts/select.d.ts +15 -0
- package/dist/prompts/select.js +2 -0
- package/dist/prompts/semver.d.ts +6 -0
- package/dist/prompts/semver.js +1 -0
- package/dist/prompts/shortcut.d.ts +9 -0
- package/dist/prompts/shortcut.js +1 -0
- package/dist/prompts/slider.d.ts +8 -0
- package/dist/prompts/slider.js +1 -0
- package/dist/prompts/slot.d.ts +16 -0
- package/dist/prompts/slot.js +8 -0
- package/dist/prompts/snippet.d.ts +19 -0
- package/dist/prompts/snippet.js +4 -0
- package/dist/prompts/sort-grid.d.ts +16 -0
- package/dist/prompts/sort-grid.js +2 -0
- package/dist/prompts/sort.d.ts +14 -0
- package/dist/prompts/sort.js +2 -0
- package/dist/prompts/spam.d.ts +17 -0
- package/dist/prompts/spam.js +2 -0
- package/dist/prompts/spreadsheet.d.ts +21 -0
- package/dist/prompts/spreadsheet.js +7 -0
- package/dist/prompts/table.d.ts +14 -0
- package/dist/prompts/table.js +3 -0
- package/dist/prompts/text.d.ts +17 -0
- package/dist/prompts/text.js +2 -0
- package/dist/prompts/time.d.ts +12 -0
- package/dist/prompts/time.js +2 -0
- package/dist/prompts/toggle.d.ts +8 -0
- package/dist/prompts/toggle.js +1 -0
- package/dist/prompts/transfer.d.ts +18 -0
- package/dist/prompts/transfer.js +5 -0
- package/dist/prompts/tree-select.d.ts +31 -0
- package/dist/prompts/tree-select.js +3 -0
- package/dist/prompts/tree.d.ts +20 -0
- package/dist/prompts/tree.js +3 -0
- package/dist/prompts/wait.d.ts +18 -0
- package/dist/prompts/wait.js +1 -0
- package/dist/spinner.d.ts +33 -0
- package/dist/spinner.js +3 -0
- package/dist/symbols.d.ts +33 -0
- package/dist/symbols.js +1 -0
- package/dist/tasks.d.ts +57 -0
- package/dist/tasks.js +1 -0
- package/dist/theme.d.ts +2 -0
- package/dist/theme.js +1 -0
- package/dist/types.d.ts +503 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +81 -0
- package/dist/utils.js +1 -0
- package/package.json +8 -9
- package/dist/src/ansi.js +0 -50
- package/dist/src/ansi.js.map +0 -1
- package/dist/src/base.js +0 -258
- package/dist/src/base.js.map +0 -1
- package/dist/src/core.js.map +0 -1
- package/dist/src/data/countries.js +0 -569
- package/dist/src/data/countries.js.map +0 -1
- package/dist/src/data/licenses.js +0 -480
- package/dist/src/data/licenses.js.map +0 -1
- package/dist/src/highlight.js +0 -185
- package/dist/src/highlight.js.map +0 -1
- package/dist/src/index.js +0 -66
- package/dist/src/index.js.map +0 -1
- package/dist/src/input.js +0 -158
- package/dist/src/input.js.map +0 -1
- package/dist/src/pipeline.js +0 -273
- package/dist/src/pipeline.js.map +0 -1
- package/dist/src/prompts/autocomplete.js +0 -171
- package/dist/src/prompts/autocomplete.js.map +0 -1
- package/dist/src/prompts/box.js +0 -225
- package/dist/src/prompts/box.js.map +0 -1
- package/dist/src/prompts/breadcrumb-search.js +0 -260
- package/dist/src/prompts/breadcrumb-search.js.map +0 -1
- package/dist/src/prompts/breadcrumb.js +0 -307
- package/dist/src/prompts/breadcrumb.js.map +0 -1
- package/dist/src/prompts/byte.js +0 -176
- package/dist/src/prompts/byte.js.map +0 -1
- package/dist/src/prompts/calculator.js +0 -243
- package/dist/src/prompts/calculator.js.map +0 -1
- package/dist/src/prompts/calendar.js +0 -430
- package/dist/src/prompts/calendar.js.map +0 -1
- package/dist/src/prompts/checkbox.js +0 -159
- package/dist/src/prompts/checkbox.js.map +0 -1
- package/dist/src/prompts/code.js +0 -271
- package/dist/src/prompts/code.js.map +0 -1
- package/dist/src/prompts/color.js +0 -165
- package/dist/src/prompts/color.js.map +0 -1
- package/dist/src/prompts/confirm.js +0 -55
- package/dist/src/prompts/confirm.js.map +0 -1
- package/dist/src/prompts/connection-string.js +0 -120
- package/dist/src/prompts/connection-string.js.map +0 -1
- package/dist/src/prompts/cron.js +0 -207
- package/dist/src/prompts/cron.js.map +0 -1
- package/dist/src/prompts/curl-utils.js +0 -71
- package/dist/src/prompts/curl-utils.js.map +0 -1
- package/dist/src/prompts/curl.js +0 -431
- package/dist/src/prompts/curl.js.map +0 -1
- package/dist/src/prompts/data-inspector.js +0 -261
- package/dist/src/prompts/data-inspector.js.map +0 -1
- package/dist/src/prompts/date.js +0 -185
- package/dist/src/prompts/date.js.map +0 -1
- package/dist/src/prompts/dependency.js +0 -283
- package/dist/src/prompts/dependency.js.map +0 -1
- package/dist/src/prompts/dial.js +0 -124
- package/dist/src/prompts/dial.js.map +0 -1
- package/dist/src/prompts/diff.js +0 -118
- package/dist/src/prompts/diff.js.map +0 -1
- package/dist/src/prompts/draw.js +0 -191
- package/dist/src/prompts/draw.js.map +0 -1
- package/dist/src/prompts/editor.js +0 -234
- package/dist/src/prompts/editor.js.map +0 -1
- package/dist/src/prompts/emoji.js +0 -226
- package/dist/src/prompts/emoji.js.map +0 -1
- package/dist/src/prompts/exec.js +0 -151
- package/dist/src/prompts/exec.js.map +0 -1
- package/dist/src/prompts/file.js +0 -217
- package/dist/src/prompts/file.js.map +0 -1
- package/dist/src/prompts/form.js +0 -241
- package/dist/src/prompts/form.js.map +0 -1
- package/dist/src/prompts/fuzzy-multi-column.js +0 -161
- package/dist/src/prompts/fuzzy-multi-column.js.map +0 -1
- package/dist/src/prompts/fuzzy.js +0 -147
- package/dist/src/prompts/fuzzy.js.map +0 -1
- package/dist/src/prompts/gauge.js +0 -137
- package/dist/src/prompts/gauge.js.map +0 -1
- package/dist/src/prompts/grid.js +0 -191
- package/dist/src/prompts/grid.js.map +0 -1
- package/dist/src/prompts/heatmap.js +0 -147
- package/dist/src/prompts/heatmap.js.map +0 -1
- package/dist/src/prompts/ip.js +0 -138
- package/dist/src/prompts/ip.js.map +0 -1
- package/dist/src/prompts/kanban.js +0 -233
- package/dist/src/prompts/kanban.js.map +0 -1
- package/dist/src/prompts/keypress.js +0 -54
- package/dist/src/prompts/keypress.js.map +0 -1
- package/dist/src/prompts/license.js +0 -144
- package/dist/src/prompts/license.js.map +0 -1
- package/dist/src/prompts/list.js +0 -124
- package/dist/src/prompts/list.js.map +0 -1
- package/dist/src/prompts/map.js +0 -262
- package/dist/src/prompts/map.js.map +0 -1
- package/dist/src/prompts/match.js +0 -271
- package/dist/src/prompts/match.js.map +0 -1
- package/dist/src/prompts/miller.js +0 -228
- package/dist/src/prompts/miller.js.map +0 -1
- package/dist/src/prompts/multi-column-select.js +0 -176
- package/dist/src/prompts/multi-column-select.js.map +0 -1
- package/dist/src/prompts/multi-range.js +0 -189
- package/dist/src/prompts/multi-range.js.map +0 -1
- package/dist/src/prompts/multi-select.js +0 -183
- package/dist/src/prompts/multi-select.js.map +0 -1
- package/dist/src/prompts/number.js +0 -166
- package/dist/src/prompts/number.js.map +0 -1
- package/dist/src/prompts/otp.js +0 -107
- package/dist/src/prompts/otp.js.map +0 -1
- package/dist/src/prompts/pattern.js +0 -252
- package/dist/src/prompts/pattern.js.map +0 -1
- package/dist/src/prompts/phone.js +0 -398
- package/dist/src/prompts/phone.js.map +0 -1
- package/dist/src/prompts/quiz-select.js +0 -114
- package/dist/src/prompts/quiz-select.js.map +0 -1
- package/dist/src/prompts/quiz-text.js +0 -98
- package/dist/src/prompts/quiz-text.js.map +0 -1
- package/dist/src/prompts/range.js +0 -164
- package/dist/src/prompts/range.js.map +0 -1
- package/dist/src/prompts/rating.js +0 -83
- package/dist/src/prompts/rating.js.map +0 -1
- package/dist/src/prompts/regex.js +0 -145
- package/dist/src/prompts/regex.js.map +0 -1
- package/dist/src/prompts/region.js +0 -170
- package/dist/src/prompts/region.js.map +0 -1
- package/dist/src/prompts/schedule.js +0 -270
- package/dist/src/prompts/schedule.js.map +0 -1
- package/dist/src/prompts/scroll.js +0 -155
- package/dist/src/prompts/scroll.js.map +0 -1
- package/dist/src/prompts/seat.js +0 -164
- package/dist/src/prompts/seat.js.map +0 -1
- package/dist/src/prompts/select-range.js +0 -148
- package/dist/src/prompts/select-range.js.map +0 -1
- package/dist/src/prompts/select.js +0 -163
- package/dist/src/prompts/select.js.map +0 -1
- package/dist/src/prompts/semver.js +0 -43
- package/dist/src/prompts/semver.js.map +0 -1
- package/dist/src/prompts/shortcut.js +0 -133
- package/dist/src/prompts/shortcut.js.map +0 -1
- package/dist/src/prompts/slider.js +0 -69
- package/dist/src/prompts/slider.js.map +0 -1
- package/dist/src/prompts/slot.js +0 -117
- package/dist/src/prompts/slot.js.map +0 -1
- package/dist/src/prompts/snippet.js +0 -228
- package/dist/src/prompts/snippet.js.map +0 -1
- package/dist/src/prompts/sort-grid.js +0 -151
- package/dist/src/prompts/sort-grid.js.map +0 -1
- package/dist/src/prompts/sort.js +0 -166
- package/dist/src/prompts/sort.js.map +0 -1
- package/dist/src/prompts/spam.js +0 -80
- package/dist/src/prompts/spam.js.map +0 -1
- package/dist/src/prompts/spreadsheet.js +0 -240
- package/dist/src/prompts/spreadsheet.js.map +0 -1
- package/dist/src/prompts/table.js +0 -120
- package/dist/src/prompts/table.js.map +0 -1
- package/dist/src/prompts/text.js +0 -317
- package/dist/src/prompts/text.js.map +0 -1
- package/dist/src/prompts/time.js +0 -211
- package/dist/src/prompts/time.js.map +0 -1
- package/dist/src/prompts/toggle.js +0 -53
- package/dist/src/prompts/toggle.js.map +0 -1
- package/dist/src/prompts/transfer.js +0 -207
- package/dist/src/prompts/transfer.js.map +0 -1
- package/dist/src/prompts/tree-select.js +0 -270
- package/dist/src/prompts/tree-select.js.map +0 -1
- package/dist/src/prompts/tree.js +0 -233
- package/dist/src/prompts/tree.js.map +0 -1
- package/dist/src/prompts/wait.js +0 -79
- package/dist/src/prompts/wait.js.map +0 -1
- package/dist/src/spinner.js +0 -105
- package/dist/src/spinner.js.map +0 -1
- package/dist/src/symbols.js +0 -66
- package/dist/src/symbols.js.map +0 -1
- package/dist/src/tasks.js +0 -231
- package/dist/src/tasks.js.map +0 -1
- package/dist/src/theme.js +0 -29
- package/dist/src/theme.js.map +0 -1
- package/dist/src/types.js +0 -8
- package/dist/src/types.js.map +0 -1
- package/dist/src/utils.js +0 -480
- package/dist/src/utils.js.map +0 -1
package/dist/src/prompts/text.js
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TextPrompt", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TextPrompt;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _ansi = require("../ansi");
|
|
12
|
-
const _base = require("../base");
|
|
13
|
-
const _theme = require("../theme");
|
|
14
|
-
const _symbols = require("../symbols");
|
|
15
|
-
const _utils = require("../utils");
|
|
16
|
-
function _define_property(obj, key, value) {
|
|
17
|
-
if (key in obj) {
|
|
18
|
-
Object.defineProperty(obj, key, {
|
|
19
|
-
value: value,
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
obj[key] = value;
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
let TextPrompt = class TextPrompt extends _base.Prompt {
|
|
30
|
-
triggerSuggest() {
|
|
31
|
-
if (!this.options.suggest || this.cursor !== this.segments.length) {
|
|
32
|
-
this.ghost = '';
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const currentValue = this.segments.join('');
|
|
36
|
-
const result = this.options.suggest(currentValue);
|
|
37
|
-
if (result instanceof Promise) {
|
|
38
|
-
result.then((suggestion)=>{
|
|
39
|
-
// Check if value is still the same (avoid race condition)
|
|
40
|
-
if (this.segments.join('') === currentValue) {
|
|
41
|
-
if (suggestion.startsWith(currentValue) && suggestion.length > currentValue.length) {
|
|
42
|
-
this.ghost = suggestion.slice(currentValue.length);
|
|
43
|
-
} else {
|
|
44
|
-
this.ghost = '';
|
|
45
|
-
}
|
|
46
|
-
this.render(false);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
} else {
|
|
50
|
-
if (result.startsWith(currentValue) && result.length > currentValue.length) {
|
|
51
|
-
this.ghost = result.slice(currentValue.length);
|
|
52
|
-
} else {
|
|
53
|
-
this.ghost = '';
|
|
54
|
-
}
|
|
55
|
-
// render will be called by the caller of triggerSuggest usually, but here we might need to ensure it
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
render(firstRender) {
|
|
59
|
-
if (!firstRender && this.lastLinesUp > 0) {
|
|
60
|
-
this.print(`\x1b[${this.lastLinesUp}B`);
|
|
61
|
-
}
|
|
62
|
-
this.lastLinesUp = 0;
|
|
63
|
-
// Calculate available width
|
|
64
|
-
// 1. Prepare Prompt Label
|
|
65
|
-
const icon = this.errorMsg ? `${_theme.theme.error}${_symbols.symbols.cross}` : `${_theme.theme.success}?`;
|
|
66
|
-
const hint = this.options.multiline ? ` ${_theme.theme.muted}(Press Ctrl+D to submit)${_ansi.ANSI.RESET}` : '';
|
|
67
|
-
const prefix = `${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}${hint} `;
|
|
68
|
-
// We need visual length of prefix to calculate available space for input on the first line
|
|
69
|
-
const prefixVisualLen = this.stripAnsi(prefix).length;
|
|
70
|
-
// 2. Prepare Value Display
|
|
71
|
-
let displayValueLines = [];
|
|
72
|
-
let cursorRelativeRow = 0;
|
|
73
|
-
let cursorRelativeCol = 0; // Visual column index
|
|
74
|
-
// Reconstruct value from segments for logic that needs raw string
|
|
75
|
-
this.value = this.segments.join('');
|
|
76
|
-
if (this.segments.length === 0 && this.options.placeholder && !this.errorMsg && !this.hasTyped) {
|
|
77
|
-
// Placeholder case
|
|
78
|
-
const placeholder = `${_theme.theme.muted}${this.options.placeholder}${_ansi.ANSI.RESET}`;
|
|
79
|
-
displayValueLines = [
|
|
80
|
-
placeholder
|
|
81
|
-
];
|
|
82
|
-
cursorRelativeRow = 0;
|
|
83
|
-
cursorRelativeCol = 0;
|
|
84
|
-
} else {
|
|
85
|
-
const maskChar = this.options.mask ?? (this.options.isPassword ? '*' : undefined);
|
|
86
|
-
// Note: password masking replaces each grapheme with '*'
|
|
87
|
-
// Split by lines (for multiline support)
|
|
88
|
-
// Determine which line the cursor is on
|
|
89
|
-
// We need to map 'cursor' (segments index) to line/col.
|
|
90
|
-
// This is tricky because segments might contain '\n'.
|
|
91
|
-
// safeSplit treats '\n' as a segment.
|
|
92
|
-
let cursorLineIndex = 0;
|
|
93
|
-
// Let's iterate segments to find cursor position (row, col)
|
|
94
|
-
cursorLineIndex = 0;
|
|
95
|
-
// If we want visual cursor position, we need visual width of segments.
|
|
96
|
-
let visualColIndex = 0;
|
|
97
|
-
for(let i = 0; i < this.cursor; i++){
|
|
98
|
-
const seg = this.segments[i];
|
|
99
|
-
if (seg === '\n') {
|
|
100
|
-
cursorLineIndex++;
|
|
101
|
-
visualColIndex = 0;
|
|
102
|
-
} else {
|
|
103
|
-
if (maskChar !== undefined) {
|
|
104
|
-
visualColIndex += maskChar.length;
|
|
105
|
-
} else {
|
|
106
|
-
visualColIndex += this.getSegmentWidth(seg);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
cursorRelativeRow = cursorLineIndex;
|
|
111
|
-
cursorRelativeCol = visualColIndex;
|
|
112
|
-
// Now prepare lines for display (scrolling/truncation)
|
|
113
|
-
// We need to reconstruct lines from segments to apply styling/truncation logic per line.
|
|
114
|
-
let currentLineSegments = [];
|
|
115
|
-
const processedLines = []; // Array of segment arrays
|
|
116
|
-
for (const seg of this.segments){
|
|
117
|
-
if (seg === '\n') {
|
|
118
|
-
processedLines.push(currentLineSegments);
|
|
119
|
-
currentLineSegments = [];
|
|
120
|
-
} else {
|
|
121
|
-
currentLineSegments.push(seg);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
processedLines.push(currentLineSegments); // Last line
|
|
125
|
-
processedLines.forEach((lineSegs)=>{
|
|
126
|
-
// Reconstruct line string for display calculation
|
|
127
|
-
// If password, join with *?
|
|
128
|
-
let visibleLine = '';
|
|
129
|
-
if (maskChar !== undefined) {
|
|
130
|
-
visibleLine = maskChar.repeat(lineSegs.length);
|
|
131
|
-
} else {
|
|
132
|
-
visibleLine = lineSegs.join('');
|
|
133
|
-
}
|
|
134
|
-
displayValueLines.push(_theme.theme.main + visibleLine + _ansi.ANSI.RESET);
|
|
135
|
-
});
|
|
136
|
-
// Append ghost text if applicable
|
|
137
|
-
if (this.ghost && this.cursor === this.segments.length && displayValueLines.length > 0) {
|
|
138
|
-
displayValueLines[displayValueLines.length - 1] += _theme.theme.muted + this.ghost + _ansi.ANSI.RESET;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// 3. Assemble Output
|
|
142
|
-
let output = '';
|
|
143
|
-
displayValueLines.forEach((lineStr, idx)=>{
|
|
144
|
-
if (idx === 0) {
|
|
145
|
-
output += prefix + lineStr;
|
|
146
|
-
} else {
|
|
147
|
-
output += '\n' + lineStr;
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
if (this.errorMsg) {
|
|
151
|
-
output += `\n${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`;
|
|
152
|
-
}
|
|
153
|
-
// 4. Render Frame
|
|
154
|
-
this.renderFrame(output);
|
|
155
|
-
this.print(_ansi.ANSI.SHOW_CURSOR);
|
|
156
|
-
// 5. Move Cursor
|
|
157
|
-
const errorOffset = this.errorMsg ? 1 : 0;
|
|
158
|
-
const totalRows = displayValueLines.length + errorOffset;
|
|
159
|
-
const linesUp = totalRows - 1 - cursorRelativeRow;
|
|
160
|
-
if (linesUp > 0) {
|
|
161
|
-
this.print(`\x1b[${linesUp}A`);
|
|
162
|
-
}
|
|
163
|
-
this.lastLinesUp = linesUp;
|
|
164
|
-
let targetCol = 0;
|
|
165
|
-
if (cursorRelativeRow === 0) {
|
|
166
|
-
targetCol = prefixVisualLen + cursorRelativeCol;
|
|
167
|
-
} else {
|
|
168
|
-
targetCol = cursorRelativeCol;
|
|
169
|
-
}
|
|
170
|
-
this.print(_ansi.ANSI.CURSOR_LEFT);
|
|
171
|
-
if (targetCol > 0) {
|
|
172
|
-
this.print(`\x1b[${targetCol}C`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
// Helper to get width of a segment
|
|
176
|
-
getSegmentWidth(seg) {
|
|
177
|
-
return (0, _utils.stringWidth)(seg);
|
|
178
|
-
}
|
|
179
|
-
cleanup() {
|
|
180
|
-
if (this.lastLinesUp > 0) {
|
|
181
|
-
this.print(`\x1b[${this.lastLinesUp}B`);
|
|
182
|
-
this.lastLinesUp = 0;
|
|
183
|
-
}
|
|
184
|
-
super.cleanup();
|
|
185
|
-
}
|
|
186
|
-
handleInput(char) {
|
|
187
|
-
// Tab (Accept Suggestion)
|
|
188
|
-
if (char === '\t') {
|
|
189
|
-
if (this.ghost) {
|
|
190
|
-
const ghostSegments = (0, _utils.safeSplit)(this.ghost);
|
|
191
|
-
this.segments.splice(this.cursor, 0, ...ghostSegments);
|
|
192
|
-
this.cursor += ghostSegments.length;
|
|
193
|
-
this.ghost = '';
|
|
194
|
-
this.errorMsg = '';
|
|
195
|
-
this.triggerSuggest(); // Maybe fetch next suggestion?
|
|
196
|
-
this.render(false);
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
// Enter
|
|
201
|
-
if (char === '\r' || char === '\n') {
|
|
202
|
-
if (this.options.multiline) {
|
|
203
|
-
// Insert newline segment
|
|
204
|
-
this.segments.splice(this.cursor, 0, '\n');
|
|
205
|
-
this.cursor++;
|
|
206
|
-
this.render(false);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
this.validateAndSubmit();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
// Ctrl+D / Ctrl+S
|
|
213
|
-
if (this.options.multiline && (char === '\u0004' || char === '\u0013')) {
|
|
214
|
-
this.validateAndSubmit();
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
// Backspace
|
|
218
|
-
if (char === '\u0008' || char === '\x7f') {
|
|
219
|
-
this.hasTyped = true;
|
|
220
|
-
if (this.cursor > 0) {
|
|
221
|
-
// Remove segment at cursor - 1
|
|
222
|
-
this.segments.splice(this.cursor - 1, 1);
|
|
223
|
-
this.cursor--;
|
|
224
|
-
this.errorMsg = '';
|
|
225
|
-
this.triggerSuggest();
|
|
226
|
-
this.render(false);
|
|
227
|
-
}
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
// Arrow Left
|
|
231
|
-
if (this.isLeft(char)) {
|
|
232
|
-
if (this.cursor > 0) {
|
|
233
|
-
this.cursor--;
|
|
234
|
-
this.render(false);
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
// Arrow Right
|
|
239
|
-
if (this.isRight(char)) {
|
|
240
|
-
if (this.cursor < this.segments.length) {
|
|
241
|
-
this.cursor++;
|
|
242
|
-
this.render(false);
|
|
243
|
-
}
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
// Delete key
|
|
247
|
-
if (char === '\u001b[3~') {
|
|
248
|
-
this.hasTyped = true;
|
|
249
|
-
if (this.cursor < this.segments.length) {
|
|
250
|
-
this.segments.splice(this.cursor, 1);
|
|
251
|
-
this.errorMsg = '';
|
|
252
|
-
this.triggerSuggest();
|
|
253
|
-
this.render(false);
|
|
254
|
-
}
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
// Regular Typing & Paste
|
|
258
|
-
// safeSplit the input char(s) - could be pasted text
|
|
259
|
-
if (!/^[\x00-\x1F]/.test(char) && !char.startsWith('\x1b')) {
|
|
260
|
-
this.hasTyped = true;
|
|
261
|
-
const newSegments = (0, _utils.safeSplit)(char);
|
|
262
|
-
this.segments.splice(this.cursor, 0, ...newSegments);
|
|
263
|
-
this.cursor += newSegments.length;
|
|
264
|
-
this.errorMsg = '';
|
|
265
|
-
this.triggerSuggest();
|
|
266
|
-
this.render(false);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
validateAndSubmit() {
|
|
270
|
-
this.value = this.segments.join('');
|
|
271
|
-
if (this.options.validate) {
|
|
272
|
-
const result = this.options.validate(this.value);
|
|
273
|
-
if (result instanceof Promise) {
|
|
274
|
-
this.errorMsg = 'Validating...';
|
|
275
|
-
this.render(false);
|
|
276
|
-
result.then((valid)=>{
|
|
277
|
-
if (typeof valid === 'string' && valid.length > 0) {
|
|
278
|
-
this.errorMsg = valid;
|
|
279
|
-
this.render(false);
|
|
280
|
-
} else if (valid === false) {
|
|
281
|
-
this.errorMsg = 'Invalid input';
|
|
282
|
-
this.render(false);
|
|
283
|
-
} else {
|
|
284
|
-
this.errorMsg = '';
|
|
285
|
-
this.render(false);
|
|
286
|
-
this.submit(this.value);
|
|
287
|
-
}
|
|
288
|
-
}).catch((err)=>{
|
|
289
|
-
this.errorMsg = err.message || 'Validation failed';
|
|
290
|
-
this.render(false);
|
|
291
|
-
});
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
if (typeof result === 'string' && result.length > 0) {
|
|
295
|
-
this.errorMsg = result;
|
|
296
|
-
this.render(false);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (result === false) {
|
|
300
|
-
this.errorMsg = 'Invalid input';
|
|
301
|
-
this.render(false);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
this.submit(this.value);
|
|
306
|
-
}
|
|
307
|
-
constructor(options){
|
|
308
|
-
super(options), _define_property(this, "errorMsg", ''), // cursor is now an index into the grapheme segments array
|
|
309
|
-
_define_property(this, "cursor", 0), _define_property(this, "hasTyped", false), _define_property(this, "segments", []), _define_property(this, "lastLinesUp", 0), _define_property(this, "ghost", '');
|
|
310
|
-
this.value = options.initial || '';
|
|
311
|
-
// Initialize segments from value
|
|
312
|
-
this.segments = (0, _utils.safeSplit)(this.value);
|
|
313
|
-
this.cursor = this.segments.length;
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
//# sourceMappingURL=text.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/prompts/text.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { Prompt } from '../base';\nimport { theme } from '../theme';\nimport { symbols } from '../symbols';\nimport { TextOptions } from '../types';\nimport { safeSplit, stringWidth } from '../utils';\n\n// --- Implementation: Text Prompt ---\nexport class TextPrompt<O extends TextOptions = TextOptions> extends Prompt<string, O> {\n protected errorMsg: string = '';\n // cursor is now an index into the grapheme segments array\n protected cursor: number = 0;\n protected hasTyped: boolean = false;\n protected segments: string[] = [];\n protected lastLinesUp: number = 0;\n private ghost: string = '';\n\n constructor(options: O) {\n super(options);\n this.value = options.initial || '';\n // Initialize segments from value\n this.segments = safeSplit(this.value);\n this.cursor = this.segments.length;\n }\n\n private triggerSuggest() {\n if (!this.options.suggest || this.cursor !== this.segments.length) {\n this.ghost = '';\n return;\n }\n\n const currentValue = this.segments.join('');\n const result = this.options.suggest(currentValue);\n\n if (result instanceof Promise) {\n result.then(suggestion => {\n // Check if value is still the same (avoid race condition)\n if (this.segments.join('') === currentValue) {\n if (suggestion.startsWith(currentValue) && suggestion.length > currentValue.length) {\n this.ghost = suggestion.slice(currentValue.length);\n } else {\n this.ghost = '';\n }\n this.render(false);\n }\n });\n } else {\n if (result.startsWith(currentValue) && result.length > currentValue.length) {\n this.ghost = result.slice(currentValue.length);\n } else {\n this.ghost = '';\n }\n // render will be called by the caller of triggerSuggest usually, but here we might need to ensure it\n }\n }\n\n protected render(firstRender: boolean) {\n if (!firstRender && this.lastLinesUp > 0) {\n this.print(`\\x1b[${this.lastLinesUp}B`);\n }\n this.lastLinesUp = 0;\n\n // Calculate available width\n // 1. Prepare Prompt Label\n const icon = this.errorMsg ? `${theme.error}${symbols.cross}` : `${theme.success}?`;\n const hint = this.options.multiline ? ` ${theme.muted}(Press Ctrl+D to submit)${ANSI.RESET}` : '';\n const prefix = `${icon} ${ANSI.BOLD}${theme.title}${this.options.message}${ANSI.RESET}${hint} `;\n\n // We need visual length of prefix to calculate available space for input on the first line\n const prefixVisualLen = this.stripAnsi(prefix).length;\n\n // 2. Prepare Value Display\n let displayValueLines: string[] = [];\n let cursorRelativeRow = 0;\n let cursorRelativeCol = 0; // Visual column index\n\n // Reconstruct value from segments for logic that needs raw string\n this.value = this.segments.join('');\n\n if (this.segments.length === 0 && this.options.placeholder && !this.errorMsg && !this.hasTyped) {\n // Placeholder case\n const placeholder = `${theme.muted}${this.options.placeholder}${ANSI.RESET}`;\n displayValueLines = [placeholder];\n cursorRelativeRow = 0;\n cursorRelativeCol = 0;\n } else {\n const maskChar = this.options.mask ?? (this.options.isPassword ? '*' : undefined);\n // Note: password masking replaces each grapheme with '*'\n\n // Split by lines (for multiline support)\n\n // Determine which line the cursor is on\n // We need to map 'cursor' (segments index) to line/col.\n // This is tricky because segments might contain '\\n'.\n // safeSplit treats '\\n' as a segment.\n\n let cursorLineIndex = 0;\n\n // Let's iterate segments to find cursor position (row, col)\n cursorLineIndex = 0;\n // If we want visual cursor position, we need visual width of segments.\n let visualColIndex = 0;\n\n for (let i = 0; i < this.cursor; i++) {\n const seg = this.segments[i];\n if (seg === '\\n') {\n cursorLineIndex++;\n visualColIndex = 0;\n } else {\n if (maskChar !== undefined) {\n visualColIndex += maskChar.length;\n } else {\n visualColIndex += this.getSegmentWidth(seg);\n }\n }\n }\n\n cursorRelativeRow = cursorLineIndex;\n cursorRelativeCol = visualColIndex;\n\n // Now prepare lines for display (scrolling/truncation)\n // We need to reconstruct lines from segments to apply styling/truncation logic per line.\n\n let currentLineSegments: string[] = [];\n const processedLines: string[][] = []; // Array of segment arrays\n\n for (const seg of this.segments) {\n if (seg === '\\n') {\n processedLines.push(currentLineSegments);\n currentLineSegments = [];\n } else {\n currentLineSegments.push(seg);\n }\n }\n processedLines.push(currentLineSegments); // Last line\n\n processedLines.forEach((lineSegs: string[]) => {\n\n // Reconstruct line string for display calculation\n // If password, join with *?\n let visibleLine = '';\n if (maskChar !== undefined) {\n visibleLine = maskChar.repeat(lineSegs.length);\n } else {\n visibleLine = lineSegs.join('');\n }\n\n displayValueLines.push(theme.main + visibleLine + ANSI.RESET);\n });\n\n // Append ghost text if applicable\n if (this.ghost && this.cursor === this.segments.length && displayValueLines.length > 0) {\n displayValueLines[displayValueLines.length - 1] += theme.muted + this.ghost + ANSI.RESET;\n }\n }\n\n // 3. Assemble Output\n let output = '';\n displayValueLines.forEach((lineStr, idx) => {\n if (idx === 0) {\n output += prefix + lineStr;\n } else {\n output += '\\n' + lineStr;\n }\n });\n\n if (this.errorMsg) {\n output += `\\n${theme.error}>> ${this.errorMsg}${ANSI.RESET}`;\n }\n\n // 4. Render Frame\n this.renderFrame(output);\n\n this.print(ANSI.SHOW_CURSOR);\n\n // 5. Move Cursor\n const errorOffset = this.errorMsg ? 1 : 0;\n const totalRows = displayValueLines.length + errorOffset;\n\n const linesUp = (totalRows - 1) - cursorRelativeRow;\n if (linesUp > 0) {\n this.print(`\\x1b[${linesUp}A`);\n }\n this.lastLinesUp = linesUp;\n\n let targetCol = 0;\n if (cursorRelativeRow === 0) {\n targetCol = prefixVisualLen + cursorRelativeCol;\n } else {\n targetCol = cursorRelativeCol;\n }\n\n this.print(ANSI.CURSOR_LEFT);\n if (targetCol > 0) {\n this.print(`\\x1b[${targetCol}C`);\n }\n }\n\n // Helper to get width of a segment\n private getSegmentWidth(seg: string): number {\n return stringWidth(seg);\n }\n\n protected cleanup() {\n if (this.lastLinesUp > 0) {\n this.print(`\\x1b[${this.lastLinesUp}B`);\n this.lastLinesUp = 0;\n }\n super.cleanup();\n }\n\n protected handleInput(char: string) {\n // Tab (Accept Suggestion)\n if (char === '\\t') {\n if (this.ghost) {\n const ghostSegments = safeSplit(this.ghost);\n this.segments.splice(this.cursor, 0, ...ghostSegments);\n this.cursor += ghostSegments.length;\n this.ghost = '';\n this.errorMsg = '';\n this.triggerSuggest(); // Maybe fetch next suggestion?\n this.render(false);\n }\n return;\n }\n\n // Enter\n if (char === '\\r' || char === '\\n') {\n if (this.options.multiline) {\n // Insert newline segment\n this.segments.splice(this.cursor, 0, '\\n');\n this.cursor++;\n this.render(false);\n return;\n }\n\n this.validateAndSubmit();\n return;\n }\n\n // Ctrl+D / Ctrl+S\n if (this.options.multiline && (char === '\\u0004' || char === '\\u0013')) {\n this.validateAndSubmit();\n return;\n }\n\n // Backspace\n if (char === '\\u0008' || char === '\\x7f') {\n this.hasTyped = true;\n if (this.cursor > 0) {\n // Remove segment at cursor - 1\n this.segments.splice(this.cursor - 1, 1);\n this.cursor--;\n this.errorMsg = '';\n this.triggerSuggest();\n this.render(false);\n }\n return;\n }\n\n // Arrow Left\n if (this.isLeft(char)) {\n if (this.cursor > 0) {\n this.cursor--;\n this.render(false);\n }\n return;\n }\n\n // Arrow Right\n if (this.isRight(char)) {\n if (this.cursor < this.segments.length) {\n this.cursor++;\n this.render(false);\n }\n return;\n }\n\n // Delete key\n if (char === '\\u001b[3~') {\n this.hasTyped = true;\n if (this.cursor < this.segments.length) {\n this.segments.splice(this.cursor, 1);\n this.errorMsg = '';\n this.triggerSuggest();\n this.render(false);\n }\n return;\n }\n\n // Regular Typing & Paste\n // safeSplit the input char(s) - could be pasted text\n if (!/^[\\x00-\\x1F]/.test(char) && !char.startsWith('\\x1b')) {\n this.hasTyped = true;\n const newSegments = safeSplit(char);\n this.segments.splice(this.cursor, 0, ...newSegments);\n this.cursor += newSegments.length;\n this.errorMsg = '';\n this.triggerSuggest();\n this.render(false);\n }\n }\n\n private validateAndSubmit() {\n this.value = this.segments.join('');\n if (this.options.validate) {\n const result = this.options.validate(this.value);\n\n if (result instanceof Promise) {\n this.errorMsg = 'Validating...';\n this.render(false);\n\n result.then(valid => {\n if (typeof valid === 'string' && valid.length > 0) {\n this.errorMsg = valid;\n this.render(false);\n } else if (valid === false) {\n this.errorMsg = 'Invalid input';\n this.render(false);\n } else {\n this.errorMsg = '';\n this.render(false);\n this.submit(this.value);\n }\n }).catch(err => {\n this.errorMsg = err.message || 'Validation failed';\n this.render(false);\n });\n return;\n }\n\n if (typeof result === 'string' && result.length > 0) {\n this.errorMsg = result;\n this.render(false);\n return;\n }\n if (result === false) {\n this.errorMsg = 'Invalid input';\n this.render(false);\n return;\n }\n }\n\n this.submit(this.value);\n }\n}\n"],"names":["TextPrompt","Prompt","triggerSuggest","options","suggest","cursor","segments","length","ghost","currentValue","join","result","Promise","then","suggestion","startsWith","slice","render","firstRender","lastLinesUp","print","icon","errorMsg","theme","error","symbols","cross","success","hint","multiline","muted","ANSI","RESET","prefix","BOLD","title","message","prefixVisualLen","stripAnsi","displayValueLines","cursorRelativeRow","cursorRelativeCol","value","placeholder","hasTyped","maskChar","mask","isPassword","undefined","cursorLineIndex","visualColIndex","i","seg","getSegmentWidth","currentLineSegments","processedLines","push","forEach","lineSegs","visibleLine","repeat","main","output","lineStr","idx","renderFrame","SHOW_CURSOR","errorOffset","totalRows","linesUp","targetCol","CURSOR_LEFT","stringWidth","cleanup","handleInput","char","ghostSegments","safeSplit","splice","validateAndSubmit","isLeft","isRight","test","newSegments","validate","valid","submit","catch","err","initial"],"mappings":";;;;+BAQaA;;;eAAAA;;;sBARQ;sBACE;uBACD;yBACE;uBAEe;;;;;;;;;;;;;;AAGhC,IAAA,AAAMA,aAAN,MAAMA,mBAAwDC,YAAM;IAiB/DC,iBAAiB;QACrB,IAAI,CAAC,IAAI,CAACC,OAAO,CAACC,OAAO,IAAI,IAAI,CAACC,MAAM,KAAK,IAAI,CAACC,QAAQ,CAACC,MAAM,EAAE;YAC/D,IAAI,CAACC,KAAK,GAAG;YACb;QACJ;QAEA,MAAMC,eAAe,IAAI,CAACH,QAAQ,CAACI,IAAI,CAAC;QACxC,MAAMC,SAAS,IAAI,CAACR,OAAO,CAACC,OAAO,CAACK;QAEpC,IAAIE,kBAAkBC,SAAS;YAC3BD,OAAOE,IAAI,CAACC,CAAAA;gBACR,0DAA0D;gBAC1D,IAAI,IAAI,CAACR,QAAQ,CAACI,IAAI,CAAC,QAAQD,cAAc;oBACzC,IAAIK,WAAWC,UAAU,CAACN,iBAAiBK,WAAWP,MAAM,GAAGE,aAAaF,MAAM,EAAE;wBAChF,IAAI,CAACC,KAAK,GAAGM,WAAWE,KAAK,CAACP,aAAaF,MAAM;oBACrD,OAAO;wBACH,IA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
5
|
-
Object.defineProperty(exports, "TimePrompt", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TimePrompt;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _base = require("../base");
|
|
12
|
-
const _ansi = require("../ansi");
|
|
13
|
-
function _define_property(obj, key, value) {
|
|
14
|
-
if (key in obj) {
|
|
15
|
-
Object.defineProperty(obj, key, {
|
|
16
|
-
value: value,
|
|
17
|
-
enumerable: true,
|
|
18
|
-
configurable: true,
|
|
19
|
-
writable: true
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
obj[key] = value;
|
|
23
|
-
}
|
|
24
|
-
return obj;
|
|
25
|
-
}
|
|
26
|
-
let TimePrompt = class TimePrompt extends _base.Prompt {
|
|
27
|
-
render(_firstRender) {
|
|
28
|
-
const is12h = this.options.format === '12h';
|
|
29
|
-
const step = this.options.step || 1;
|
|
30
|
-
// Helpers
|
|
31
|
-
const getHourDisplay = (h)=>{
|
|
32
|
-
if (is12h) {
|
|
33
|
-
const val = h % 12 || 12; // 0 -> 12
|
|
34
|
-
return val.toString().padStart(2, '0');
|
|
35
|
-
}
|
|
36
|
-
return h.toString().padStart(2, '0');
|
|
37
|
-
};
|
|
38
|
-
const getMinDisplay = (m)=>m.toString().padStart(2, '0');
|
|
39
|
-
const getMeridiem = (h)=>h >= 12 ? 'PM' : 'AM';
|
|
40
|
-
// Calculate Prev/Next values for visualization
|
|
41
|
-
const adjustH = (val, delta)=>{
|
|
42
|
-
let n = val + delta;
|
|
43
|
-
if (n < 0) n = 24 + n;
|
|
44
|
-
return n % 24;
|
|
45
|
-
};
|
|
46
|
-
const adjustM = (val, delta)=>{
|
|
47
|
-
let n = val + delta;
|
|
48
|
-
if (n < 0) n = 60 + n;
|
|
49
|
-
return n % 60;
|
|
50
|
-
};
|
|
51
|
-
const curH = this.hour;
|
|
52
|
-
const curM = this.minute;
|
|
53
|
-
const prevH = adjustH(curH, -1);
|
|
54
|
-
const nextH = adjustH(curH, 1);
|
|
55
|
-
const prevM = adjustM(curM, -step);
|
|
56
|
-
const nextM = adjustM(curM, step);
|
|
57
|
-
// Build columns
|
|
58
|
-
const colHour = [
|
|
59
|
-
getHourDisplay(prevH),
|
|
60
|
-
getHourDisplay(curH),
|
|
61
|
-
getHourDisplay(nextH)
|
|
62
|
-
];
|
|
63
|
-
const colMin = [
|
|
64
|
-
getMinDisplay(prevM),
|
|
65
|
-
getMinDisplay(curM),
|
|
66
|
-
getMinDisplay(nextM)
|
|
67
|
-
];
|
|
68
|
-
let colMer = [];
|
|
69
|
-
if (is12h) {
|
|
70
|
-
const curMer = getMeridiem(curH);
|
|
71
|
-
const otherMer = curMer === 'AM' ? 'PM' : 'AM';
|
|
72
|
-
// Visually, scrolling up/down from AM goes to PM
|
|
73
|
-
colMer = [
|
|
74
|
-
otherMer,
|
|
75
|
-
curMer,
|
|
76
|
-
otherMer
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
|
-
const dim = _ansi.ANSI.FG_GRAY;
|
|
80
|
-
let output = `${_ansi.ANSI.FG_CYAN}? ${this.options.message}${_ansi.ANSI.RESET}\n`;
|
|
81
|
-
// Render 3 lines
|
|
82
|
-
for(let i = 0; i < 3; i++){
|
|
83
|
-
const isCenter = i === 1;
|
|
84
|
-
// Render Hour
|
|
85
|
-
let hStr = colHour[i];
|
|
86
|
-
if (this.activeCol === 0 && isCenter) {
|
|
87
|
-
hStr = `${_ansi.ANSI.FG_CYAN}${_ansi.ANSI.REVERSE} ${hStr} ${_ansi.ANSI.RESET}`;
|
|
88
|
-
} else if (isCenter) {
|
|
89
|
-
hStr = `${_ansi.ANSI.BOLD} ${hStr} ${_ansi.ANSI.RESET}`;
|
|
90
|
-
} else {
|
|
91
|
-
hStr = `${dim} ${hStr} ${_ansi.ANSI.RESET}`;
|
|
92
|
-
}
|
|
93
|
-
const sep = isCenter ? ':' : ' ';
|
|
94
|
-
// Render Minute
|
|
95
|
-
let mStr = colMin[i];
|
|
96
|
-
if (this.activeCol === 1 && isCenter) {
|
|
97
|
-
mStr = `${_ansi.ANSI.FG_CYAN}${_ansi.ANSI.REVERSE} ${mStr} ${_ansi.ANSI.RESET}`;
|
|
98
|
-
} else if (isCenter) {
|
|
99
|
-
mStr = `${_ansi.ANSI.BOLD} ${mStr} ${_ansi.ANSI.RESET}`;
|
|
100
|
-
} else {
|
|
101
|
-
mStr = `${dim} ${mStr} ${_ansi.ANSI.RESET}`;
|
|
102
|
-
}
|
|
103
|
-
let line = ` ${hStr} ${sep} ${mStr}`;
|
|
104
|
-
// Render Meridiem
|
|
105
|
-
if (is12h) {
|
|
106
|
-
let merStr = colMer[i];
|
|
107
|
-
if (this.activeCol === 2 && isCenter) {
|
|
108
|
-
merStr = `${_ansi.ANSI.FG_CYAN}${_ansi.ANSI.REVERSE} ${merStr} ${_ansi.ANSI.RESET}`;
|
|
109
|
-
} else if (isCenter) {
|
|
110
|
-
merStr = `${_ansi.ANSI.BOLD} ${merStr} ${_ansi.ANSI.RESET}`;
|
|
111
|
-
} else {
|
|
112
|
-
merStr = `${dim} ${merStr} ${_ansi.ANSI.RESET}`;
|
|
113
|
-
}
|
|
114
|
-
line += ` ${merStr}`;
|
|
115
|
-
}
|
|
116
|
-
output += line + '\n';
|
|
117
|
-
}
|
|
118
|
-
output += _ansi.ANSI.FG_GRAY + "(Use Arrows/Tab to navigate)" + _ansi.ANSI.RESET;
|
|
119
|
-
this.renderFrame(output);
|
|
120
|
-
}
|
|
121
|
-
handleMouse(event) {
|
|
122
|
-
if (event.action === 'scroll') {
|
|
123
|
-
if (event.scroll === 'up') {
|
|
124
|
-
this.adjustValue(-1);
|
|
125
|
-
} else if (event.scroll === 'down') {
|
|
126
|
-
this.adjustValue(1);
|
|
127
|
-
}
|
|
128
|
-
this.render(false);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
handleInput(char, _key) {
|
|
132
|
-
const is12h = this.options.format === '12h';
|
|
133
|
-
const maxCols = is12h ? 2 : 1; // 0, 1, 2 or 0, 1
|
|
134
|
-
if (char === '\r' || char === '\n') {
|
|
135
|
-
const h = this.hour.toString().padStart(2, '0');
|
|
136
|
-
const m = this.minute.toString().padStart(2, '0');
|
|
137
|
-
const result = is12h ? `${(this.hour % 12 || 12).toString().padStart(2, '0')}:${m} ${this.hour >= 12 ? 'PM' : 'AM'}` : `${h}:${m}`;
|
|
138
|
-
this.submit(result);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (char === '\t' || this.isRight(char)) {
|
|
142
|
-
this.activeCol++;
|
|
143
|
-
if (this.activeCol > maxCols) this.activeCol = 0;
|
|
144
|
-
this.render(false);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (char === '\u001b[Z' || this.isLeft(char)) {
|
|
148
|
-
this.activeCol--;
|
|
149
|
-
if (this.activeCol < 0) this.activeCol = maxCols;
|
|
150
|
-
this.render(false);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (this.isUp(char)) {
|
|
154
|
-
this.adjustValue(-1);
|
|
155
|
-
this.render(false);
|
|
156
|
-
} else if (this.isDown(char)) {
|
|
157
|
-
this.adjustValue(1);
|
|
158
|
-
this.render(false);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
adjustValue(direction) {
|
|
162
|
-
// direction: -1 (Up/Prev value, which visually is TOP, but wait...)
|
|
163
|
-
// In the UI:
|
|
164
|
-
// Prev (Top)
|
|
165
|
-
// Curr (Center)
|
|
166
|
-
// Next (Bottom)
|
|
167
|
-
// If I press DOWN arrow, I expect the list to scroll DOWN, which means "Next" becomes "Curr".
|
|
168
|
-
// So DOWN arrow means INCREMENT index/value.
|
|
169
|
-
// UP arrow means DECREMENT index/value.
|
|
170
|
-
if (this.activeCol === 0) {
|
|
171
|
-
let newH = this.hour + direction;
|
|
172
|
-
if (newH < 0) newH = 23;
|
|
173
|
-
if (newH > 23) newH = 0;
|
|
174
|
-
this.hour = newH;
|
|
175
|
-
} else if (this.activeCol === 1) {
|
|
176
|
-
const step = this.options.step || 1;
|
|
177
|
-
let newM = this.minute + direction * step;
|
|
178
|
-
if (newM < 0) newM = 60 - step; // Approx wrap
|
|
179
|
-
// Better wrap logic for arbitrary steps:
|
|
180
|
-
if (newM < 0) newM = 60 + newM; // e.g. -5 -> 55
|
|
181
|
-
if (newM >= 60) newM = newM % 60;
|
|
182
|
-
this.minute = newM;
|
|
183
|
-
} else if (this.activeCol === 2) {
|
|
184
|
-
// Toggle AM/PM
|
|
185
|
-
this.hour = (this.hour + 12) % 24;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
constructor(options){
|
|
189
|
-
super(options), _define_property(this, "hour", 0), _define_property(this, "minute", 0), _define_property(this, "activeCol", 0) // 0: Hour, 1: Minute, 2: Meridiem (if 12h)
|
|
190
|
-
;
|
|
191
|
-
const now = options.initial ? typeof options.initial === 'string' ? new Date(options.initial) : options.initial : new Date();
|
|
192
|
-
// Fallback if invalid date
|
|
193
|
-
if (isNaN(now.getTime())) {
|
|
194
|
-
this.hour = 0;
|
|
195
|
-
this.minute = 0;
|
|
196
|
-
} else {
|
|
197
|
-
this.hour = now.getHours();
|
|
198
|
-
this.minute = now.getMinutes();
|
|
199
|
-
}
|
|
200
|
-
// Round minute to nearest step
|
|
201
|
-
if (options.step) {
|
|
202
|
-
this.minute = Math.round(this.minute / options.step) * options.step;
|
|
203
|
-
if (this.minute >= 60) {
|
|
204
|
-
this.minute = 0;
|
|
205
|
-
this.hour = (this.hour + 1) % 24;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
//# sourceMappingURL=time.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/prompts/time.ts"],"sourcesContent":["import { Prompt } from '../base';\nimport { TimeOptions, MouseEvent } from '../types';\nimport { ANSI } from '../ansi';\n\nexport class TimePrompt extends Prompt<string, TimeOptions> {\n private hour: number = 0;\n private minute: number = 0;\n private activeCol: number = 0; // 0: Hour, 1: Minute, 2: Meridiem (if 12h)\n\n constructor(options: TimeOptions) {\n super(options);\n const now = options.initial ? (typeof options.initial === 'string' ? new Date(options.initial) : options.initial) : new Date();\n // Fallback if invalid date\n if (isNaN(now.getTime())) {\n this.hour = 0;\n this.minute = 0;\n } else {\n this.hour = now.getHours();\n this.minute = now.getMinutes();\n }\n\n // Round minute to nearest step\n if (options.step) {\n this.minute = Math.round(this.minute / options.step) * options.step;\n if (this.minute >= 60) {\n this.minute = 0;\n this.hour = (this.hour + 1) % 24;\n }\n }\n }\n\n protected render(_firstRender: boolean): void {\n const is12h = this.options.format === '12h';\n const step = this.options.step || 1;\n\n // Helpers\n const getHourDisplay = (h: number) => {\n if (is12h) {\n const val = h % 12 || 12; // 0 -> 12\n return val.toString().padStart(2, '0');\n }\n return h.toString().padStart(2, '0');\n };\n\n const getMinDisplay = (m: number) => m.toString().padStart(2, '0');\n const getMeridiem = (h: number) => h >= 12 ? 'PM' : 'AM';\n\n // Calculate Prev/Next values for visualization\n const adjustH = (val: number, delta: number) => {\n let n = val + delta;\n if (n < 0) n = 24 + n;\n return n % 24;\n };\n const adjustM = (val: number, delta: number) => {\n let n = val + delta;\n if (n < 0) n = 60 + n;\n return n % 60;\n };\n\n const curH = this.hour;\n const curM = this.minute;\n\n const prevH = adjustH(curH, -1);\n const nextH = adjustH(curH, 1);\n\n const prevM = adjustM(curM, -step);\n const nextM = adjustM(curM, step);\n\n // Build columns\n const colHour = [getHourDisplay(prevH), getHourDisplay(curH), getHourDisplay(nextH)];\n const colMin = [getMinDisplay(prevM), getMinDisplay(curM), getMinDisplay(nextM)];\n\n let colMer: string[] = [];\n if (is12h) {\n const curMer = getMeridiem(curH);\n const otherMer = curMer === 'AM' ? 'PM' : 'AM';\n // Visually, scrolling up/down from AM goes to PM\n colMer = [otherMer, curMer, otherMer];\n }\n\n const dim = ANSI.FG_GRAY;\n\n let output = `${ANSI.FG_CYAN}? ${this.options.message}${ANSI.RESET}\\n`;\n\n // Render 3 lines\n for (let i = 0; i < 3; i++) {\n const isCenter = i === 1;\n\n // Render Hour\n let hStr = colHour[i];\n if (this.activeCol === 0 && isCenter) {\n hStr = `${ANSI.FG_CYAN}${ANSI.REVERSE} ${hStr} ${ANSI.RESET}`;\n } else if (isCenter) {\n hStr = `${ANSI.BOLD} ${hStr} ${ANSI.RESET}`;\n } else {\n hStr = `${dim} ${hStr} ${ANSI.RESET}`;\n }\n\n const sep = isCenter ? ':' : ' ';\n\n // Render Minute\n let mStr = colMin[i];\n if (this.activeCol === 1 && isCenter) {\n mStr = `${ANSI.FG_CYAN}${ANSI.REVERSE} ${mStr} ${ANSI.RESET}`;\n } else if (isCenter) {\n mStr = `${ANSI.BOLD} ${mStr} ${ANSI.RESET}`;\n } else {\n mStr = `${dim} ${mStr} ${ANSI.RESET}`;\n }\n\n let line = ` ${hStr} ${sep} ${mStr}`;\n\n // Render Meridiem\n if (is12h) {\n let merStr = colMer[i];\n if (this.activeCol === 2 && isCenter) {\n merStr = `${ANSI.FG_CYAN}${ANSI.REVERSE} ${merStr} ${ANSI.RESET}`;\n } else if (isCenter) {\n merStr = `${ANSI.BOLD} ${merStr} ${ANSI.RESET}`;\n } else {\n merStr = `${dim} ${merStr} ${ANSI.RESET}`;\n }\n line += ` ${merStr}`;\n }\n\n output += line + '\\n';\n }\n\n output += ANSI.FG_GRAY + \"(Use Arrows/Tab to navigate)\" + ANSI.RESET;\n\n this.renderFrame(output);\n }\n\n protected handleMouse(event: MouseEvent): void {\n if (event.action === 'scroll') {\n if (event.scroll === 'up') {\n this.adjustValue(-1);\n } else if (event.scroll === 'down') {\n this.adjustValue(1);\n }\n this.render(false);\n }\n }\n\n protected handleInput(char: string, _key: Buffer): void {\n const is12h = this.options.format === '12h';\n const maxCols = is12h ? 2 : 1; // 0, 1, 2 or 0, 1\n\n if (char === '\\r' || char === '\\n') { // Enter\n const h = this.hour.toString().padStart(2, '0');\n const m = this.minute.toString().padStart(2, '0');\n const result = is12h\n ? `${((this.hour % 12) || 12).toString().padStart(2, '0')}:${m} ${this.hour >= 12 ? 'PM' : 'AM'}`\n : `${h}:${m}`;\n this.submit(result);\n return;\n }\n\n if (char === '\\t' || this.isRight(char)) {\n this.activeCol++;\n if (this.activeCol > maxCols) this.activeCol = 0;\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[Z' || this.isLeft(char)) { // Shift+Tab or Left\n this.activeCol--;\n if (this.activeCol < 0) this.activeCol = maxCols;\n this.render(false);\n return;\n }\n\n if (this.isUp(char)) {\n this.adjustValue(-1);\n this.render(false);\n } else if (this.isDown(char)) {\n this.adjustValue(1);\n this.render(false);\n }\n }\n\n private adjustValue(direction: number) {\n // direction: -1 (Up/Prev value, which visually is TOP, but wait...)\n // In the UI:\n // Prev (Top)\n // Curr (Center)\n // Next (Bottom)\n // If I press DOWN arrow, I expect the list to scroll DOWN, which means \"Next\" becomes \"Curr\".\n // So DOWN arrow means INCREMENT index/value.\n // UP arrow means DECREMENT index/value.\n\n if (this.activeCol === 0) { // Hour\n let newH = this.hour + direction;\n if (newH < 0) newH = 23;\n if (newH > 23) newH = 0;\n this.hour = newH;\n } else if (this.activeCol === 1) { // Minute\n const step = this.options.step || 1;\n let newM = this.minute + (direction * step);\n if (newM < 0) newM = 60 - step; // Approx wrap\n // Better wrap logic for arbitrary steps:\n if (newM < 0) newM = 60 + newM; // e.g. -5 -> 55\n if (newM >= 60) newM = newM % 60;\n this.minute = newM;\n } else if (this.activeCol === 2) { // Meridiem\n // Toggle AM/PM\n this.hour = (this.hour + 12) % 24;\n }\n }\n}\n"],"names":["TimePrompt","Prompt","render","_firstRender","is12h","options","format","step","getHourDisplay","h","val","toString","padStart","getMinDisplay","m","getMeridiem","adjustH","delta","n","adjustM","curH","hour","curM","minute","prevH","nextH","prevM","nextM","colHour","colMin","colMer","curMer","otherMer","dim","ANSI","FG_GRAY","output","FG_CYAN","message","RESET","i","isCenter","hStr","activeCol","REVERSE","BOLD","sep","mStr","line","merStr","renderFrame","handleMouse","event","action","scroll","adjustValue","handleInput","char","_key","maxCols","result","submit","isRight","isLeft","isUp","isDown","direction","newH","newM","now","initial","Date","isNaN","getTime","getHours","getMinutes","Math","round"],"mappings":";;;;+BAIaA;;;eAAAA;;;sBAJU;sBAEF;;;;;;;;;;;;;;AAEd,IAAA,AAAMA,aAAN,MAAMA,mBAAmBC,YAAM;IA2BxBC,OAAOC,YAAqB,EAAQ;QAC1C,MAAMC,QAAQ,IAAI,CAACC,OAAO,CAACC,MAAM,KAAK;QACtC,MAAMC,OAAO,IAAI,CAACF,OAAO,CAACE,IAAI,IAAI;QAElC,UAAU;QACV,MAAMC,iBAAiB,CAACC;YACpB,IAAIL,OAAO;gBACP,MAAMM,MAAMD,IAAI,MAAM,IAAI,UAAU;gBACpC,OAAOC,IAAIC,QAAQ,GAAGC,QAAQ,CAAC,GAAG;YACtC;YACA,OAAOH,EAAEE,QAAQ,GAAGC,QAAQ,CAAC,GAAG;QACpC;QAEA,MAAMC,gBAAgB,CAACC,IAAcA,EAAEH,QAAQ,GAAGC,QAAQ,CAAC,GAAG;QAC9D,MAAMG,cAAc,CAACN,IAAcA,KAAK,KAAK,OAAO;QAEpD,+CAA+C;QAC/C,MAAMO,UAAU,CAACN,KAAaO;YAC1B,IAAIC,IAAIR,MAAMO;YACd,IAAIC,IAAI,GAAGA,IAAI,KAAKA;YACpB,OAAOA,IAAI;QACf;QACA,MAAMC,UAAU,CAACT,KAAaO;YAC1B,IAAIC,IAAIR,MAAMO;YACd,IAAIC,IAAI,GAAGA,IAAI,KAAKA;YACpB,OAAOA,IAAI;QACf;QAEA,MAAME,OAAO,IAAI,CAACC,IAAI;QACtB,MAAMC,OAAO,IAAI,CAACC,MAAM;QAExB,MAAMC,QAAQR,QAAQI,MAAM,CAAC;QAC7B,MAAMK,QAAQT,QAAQI,MAAM;QAE5B,MAAMM,QAAQP,QAAQG,MAAM,CAACf;QAC7B,MAAMoB,QAAQR,QAAQ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QiE,OAAO,IAAIjE,QAAQiE,OAAO,GAAI,IAAIC;QACxH,2BAA2B;QAC3B,IAAIC,MAAMH,IAAII,OAAO,KAAK;YACtB,IAAI,CAACpD,IAAI,GAAG;YACZ,IAAI,CAACE,MAAM,GAAG;QAClB,OAAO;YACH,IAAI,CAACF,IAAI,GAAGgD,IAAIK,QAAQ;YACxB,IAAI,CAACnD,MAAM,GAAG8C,IAAIM,UAAU;QAChC;QAEA,+BAA+B;QAC/B,IAAItE,QAAQE,IAAI,EAAE;YACd,IAAI,CAACgB,MAAM,GAAGqD,KAAKC,KAAK,CAAC,IAAI,CAACtD,MAAM,GAAGlB,QAAQE,IAAI,IAAIF,QAAQE,IAAI;YACnE,IAAI,IAAI,CAACgB,MAAM,IAAI,IAAI;gBACnB,IAAI,CAACA,MAAM,GAAG;gBACd,IAAI,CAACF,IAAI,GAAG,AAAC,CAAA,IAAI,CAACA,IAAI,GAAG,CAAA,IAAK;YAClC;QACJ;IACJ;AAoLJ"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TogglePrompt", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TogglePrompt;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _ansi = require("../ansi");
|
|
12
|
-
const _base = require("../base");
|
|
13
|
-
const _theme = require("../theme");
|
|
14
|
-
let TogglePrompt = class TogglePrompt extends _base.Prompt {
|
|
15
|
-
render(_firstRender) {
|
|
16
|
-
const activeText = this.options.activeText || 'ON';
|
|
17
|
-
const inactiveText = this.options.inactiveText || 'OFF';
|
|
18
|
-
let toggleDisplay = '';
|
|
19
|
-
if (this.value) {
|
|
20
|
-
toggleDisplay = `${_theme.theme.main}[${_ansi.ANSI.BOLD}${activeText}${_ansi.ANSI.RESET}${_theme.theme.main}]${_ansi.ANSI.RESET} ${_theme.theme.muted}${inactiveText}${_ansi.ANSI.RESET}`;
|
|
21
|
-
} else {
|
|
22
|
-
toggleDisplay = `${_theme.theme.muted}${activeText}${_ansi.ANSI.RESET} ${_theme.theme.main}[${_ansi.ANSI.BOLD}${inactiveText}${_ansi.ANSI.RESET}${_theme.theme.main}]${_ansi.ANSI.RESET}`;
|
|
23
|
-
}
|
|
24
|
-
const output = `${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} ${toggleDisplay}`;
|
|
25
|
-
this.renderFrame(output);
|
|
26
|
-
}
|
|
27
|
-
handleInput(char) {
|
|
28
|
-
if (char === '\r' || char === '\n') {
|
|
29
|
-
this.submit(this.value);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (this.isLeft(char) || this.isRight(char) || char === 'h' || char === 'l') {
|
|
33
|
-
this.value = !this.value;
|
|
34
|
-
this.render(false);
|
|
35
|
-
}
|
|
36
|
-
if (char === ' ') {
|
|
37
|
-
this.value = !this.value;
|
|
38
|
-
this.render(false);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
handleMouse(event) {
|
|
42
|
-
if (event.action === 'scroll') {
|
|
43
|
-
this.value = !this.value;
|
|
44
|
-
this.render(false);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
constructor(options){
|
|
48
|
-
super(options);
|
|
49
|
-
this.value = options.initial ?? false;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//# sourceMappingURL=toggle.js.map
|