mepcli 1.3.2 → 2.0.0-beta.1
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 +11 -2
- package/dist/{ansi.js → src/ansi.js} +17 -9
- package/dist/src/ansi.js.map +1 -0
- package/dist/{base.js → src/base.js} +82 -70
- package/dist/src/base.js.map +1 -0
- package/dist/{core.js → src/core.js} +266 -320
- package/dist/src/core.js.map +1 -0
- package/dist/src/data/countries.js +569 -0
- package/dist/src/data/countries.js.map +1 -0
- package/dist/src/data/licenses.js +480 -0
- package/dist/src/data/licenses.js.map +1 -0
- package/dist/{highlight.js → src/highlight.js} +77 -69
- package/dist/src/highlight.js.map +1 -0
- package/dist/src/index.js +66 -0
- package/dist/src/index.js.map +1 -0
- package/dist/{input.js → src/input.js} +47 -41
- package/dist/src/input.js.map +1 -0
- package/dist/src/pipeline.js +273 -0
- package/dist/src/pipeline.js.map +1 -0
- package/dist/{prompts → src/prompts}/autocomplete.js +58 -57
- package/dist/src/prompts/autocomplete.js.map +1 -0
- package/dist/{prompts → src/prompts}/box.js +86 -53
- package/dist/src/prompts/box.js.map +1 -0
- package/dist/{prompts → src/prompts}/breadcrumb-search.js +110 -98
- package/dist/src/prompts/breadcrumb-search.js.map +1 -0
- package/dist/{prompts → src/prompts}/breadcrumb.js +126 -121
- package/dist/src/prompts/breadcrumb.js.map +1 -0
- package/dist/{prompts → src/prompts}/byte.js +69 -52
- package/dist/src/prompts/byte.js.map +1 -0
- package/dist/{prompts → src/prompts}/calculator.js +79 -56
- package/dist/src/prompts/calculator.js.map +1 -0
- package/dist/{prompts → src/prompts}/calendar.js +167 -127
- package/dist/src/prompts/calendar.js.map +1 -0
- package/dist/{prompts → src/prompts}/checkbox.js +53 -49
- package/dist/src/prompts/checkbox.js.map +1 -0
- package/dist/{prompts → src/prompts}/code.js +88 -76
- package/dist/src/prompts/code.js.map +1 -0
- package/dist/{prompts → src/prompts}/color.js +68 -50
- package/dist/src/prompts/color.js.map +1 -0
- package/dist/{prompts → src/prompts}/confirm.js +22 -15
- package/dist/src/prompts/confirm.js.map +1 -0
- package/dist/{prompts → src/prompts}/connection-string.js +59 -36
- package/dist/src/prompts/connection-string.js.map +1 -0
- package/dist/{prompts → src/prompts}/cron.js +90 -59
- package/dist/src/prompts/cron.js.map +1 -0
- package/dist/src/prompts/curl-utils.js +71 -0
- package/dist/src/prompts/curl-utils.js.map +1 -0
- package/dist/{prompts → src/prompts}/curl.js +153 -132
- package/dist/src/prompts/curl.js.map +1 -0
- package/dist/{prompts → src/prompts}/data-inspector.js +96 -91
- package/dist/src/prompts/data-inspector.js.map +1 -0
- package/dist/{prompts → src/prompts}/date.js +64 -57
- package/dist/src/prompts/date.js.map +1 -0
- package/dist/{prompts → src/prompts}/dependency.js +84 -80
- package/dist/src/prompts/dependency.js.map +1 -0
- package/dist/{prompts → src/prompts}/dial.js +49 -35
- package/dist/src/prompts/dial.js.map +1 -0
- package/dist/src/prompts/diff.js +118 -0
- package/dist/src/prompts/diff.js.map +1 -0
- package/dist/{prompts → src/prompts}/draw.js +83 -80
- package/dist/src/prompts/draw.js.map +1 -0
- package/dist/src/prompts/editor.js +234 -0
- package/dist/src/prompts/editor.js.map +1 -0
- package/dist/{prompts → src/prompts}/emoji.js +80 -82
- package/dist/src/prompts/emoji.js.map +1 -0
- package/dist/{prompts → src/prompts}/exec.js +60 -46
- package/dist/src/prompts/exec.js.map +1 -0
- package/dist/src/prompts/file.js +217 -0
- package/dist/src/prompts/file.js.map +1 -0
- package/dist/{prompts → src/prompts}/form.js +63 -54
- package/dist/src/prompts/form.js.map +1 -0
- package/dist/{prompts → src/prompts}/fuzzy-multi-column.js +65 -53
- package/dist/src/prompts/fuzzy-multi-column.js.map +1 -0
- package/dist/{prompts → src/prompts}/fuzzy.js +66 -55
- package/dist/src/prompts/fuzzy.js.map +1 -0
- package/dist/src/prompts/gauge.js +137 -0
- package/dist/src/prompts/gauge.js.map +1 -0
- package/dist/{prompts → src/prompts}/grid.js +70 -57
- package/dist/src/prompts/grid.js.map +1 -0
- package/dist/{prompts → src/prompts}/heatmap.js +70 -64
- package/dist/src/prompts/heatmap.js.map +1 -0
- package/dist/{prompts → src/prompts}/ip.js +56 -36
- package/dist/src/prompts/ip.js.map +1 -0
- package/dist/{prompts → src/prompts}/kanban.js +63 -58
- package/dist/src/prompts/kanban.js.map +1 -0
- package/dist/src/prompts/keypress.js +54 -0
- package/dist/src/prompts/keypress.js.map +1 -0
- package/dist/src/prompts/license.js +144 -0
- package/dist/src/prompts/license.js.map +1 -0
- package/dist/{prompts → src/prompts}/list.js +46 -31
- package/dist/src/prompts/list.js.map +1 -0
- package/dist/{prompts → src/prompts}/map.js +93 -77
- package/dist/src/prompts/map.js.map +1 -0
- package/dist/{prompts → src/prompts}/match.js +91 -95
- package/dist/src/prompts/match.js.map +1 -0
- package/dist/{prompts → src/prompts}/miller.js +74 -67
- package/dist/src/prompts/miller.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-column-select.js +54 -44
- package/dist/src/prompts/multi-column-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-range.js +70 -52
- package/dist/src/prompts/multi-range.js.map +1 -0
- package/dist/{prompts → src/prompts}/multi-select.js +67 -58
- package/dist/src/prompts/multi-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/number.js +51 -39
- package/dist/src/prompts/number.js.map +1 -0
- package/dist/{prompts → src/prompts}/otp.js +43 -27
- package/dist/src/prompts/otp.js.map +1 -0
- package/dist/{prompts → src/prompts}/pattern.js +74 -71
- package/dist/src/prompts/pattern.js.map +1 -0
- package/dist/{prompts → src/prompts}/phone.js +107 -118
- package/dist/src/prompts/phone.js.map +1 -0
- package/dist/src/prompts/quiz-select.js +114 -0
- package/dist/src/prompts/quiz-select.js.map +1 -0
- package/dist/src/prompts/quiz-text.js +98 -0
- package/dist/src/prompts/quiz-text.js.map +1 -0
- package/dist/{prompts → src/prompts}/range.js +85 -61
- package/dist/src/prompts/range.js.map +1 -0
- package/dist/{prompts → src/prompts}/rating.js +29 -24
- package/dist/src/prompts/rating.js.map +1 -0
- package/dist/{prompts → src/prompts}/regex.js +50 -36
- package/dist/src/prompts/regex.js.map +1 -0
- package/dist/{prompts → src/prompts}/region.js +62 -56
- package/dist/src/prompts/region.js.map +1 -0
- package/dist/{prompts → src/prompts}/schedule.js +82 -75
- package/dist/src/prompts/schedule.js.map +1 -0
- package/dist/{prompts → src/prompts}/scroll.js +61 -58
- package/dist/src/prompts/scroll.js.map +1 -0
- package/dist/src/prompts/seat.js +164 -0
- package/dist/src/prompts/seat.js.map +1 -0
- package/dist/{prompts → src/prompts}/select-range.js +58 -46
- package/dist/src/prompts/select-range.js.map +1 -0
- package/dist/{prompts → src/prompts}/select.js +65 -66
- package/dist/src/prompts/select.js.map +1 -0
- package/dist/{prompts → src/prompts}/semver.js +24 -13
- package/dist/src/prompts/semver.js.map +1 -0
- package/dist/src/prompts/shortcut.js +133 -0
- package/dist/src/prompts/shortcut.js.map +1 -0
- package/dist/{prompts → src/prompts}/slider.js +28 -23
- package/dist/src/prompts/slider.js.map +1 -0
- package/dist/src/prompts/slot.js +117 -0
- package/dist/src/prompts/slot.js.map +1 -0
- package/dist/{prompts → src/prompts}/snippet.js +82 -61
- package/dist/src/prompts/snippet.js.map +1 -0
- package/dist/{prompts → src/prompts}/sort-grid.js +64 -59
- package/dist/src/prompts/sort-grid.js.map +1 -0
- package/dist/{prompts → src/prompts}/sort.js +59 -49
- package/dist/src/prompts/sort.js.map +1 -0
- package/dist/src/prompts/spam.js +80 -0
- package/dist/src/prompts/spam.js.map +1 -0
- package/dist/{prompts → src/prompts}/spreadsheet.js +71 -70
- package/dist/src/prompts/spreadsheet.js.map +1 -0
- package/dist/{prompts → src/prompts}/table.js +52 -38
- package/dist/src/prompts/table.js.map +1 -0
- package/dist/{prompts → src/prompts}/text.js +74 -70
- package/dist/src/prompts/text.js.map +1 -0
- package/dist/{prompts → src/prompts}/time.js +105 -96
- package/dist/src/prompts/time.js.map +1 -0
- package/dist/src/prompts/toggle.js +53 -0
- package/dist/src/prompts/toggle.js.map +1 -0
- package/dist/{prompts → src/prompts}/transfer.js +71 -67
- package/dist/src/prompts/transfer.js.map +1 -0
- package/dist/{prompts → src/prompts}/tree-select.js +83 -86
- package/dist/src/prompts/tree-select.js.map +1 -0
- package/dist/{prompts → src/prompts}/tree.js +69 -67
- package/dist/src/prompts/tree.js.map +1 -0
- package/dist/src/prompts/wait.js +79 -0
- package/dist/src/prompts/wait.js.map +1 -0
- package/dist/src/spinner.js +105 -0
- package/dist/src/spinner.js.map +1 -0
- package/dist/{symbols.js → src/symbols.js} +32 -7
- package/dist/src/symbols.js.map +1 -0
- package/dist/{tasks.js → src/tasks.js} +104 -79
- package/dist/src/tasks.js.map +1 -0
- package/dist/src/theme.js +29 -0
- package/dist/src/theme.js.map +1 -0
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -0
- package/dist/{utils.js → src/utils.js} +196 -152
- package/dist/src/utils.js.map +1 -0
- package/package.json +16 -13
- package/dist/ansi.d.ts +0 -36
- package/dist/base.d.ts +0 -60
- package/dist/core.d.ts +0 -1072
- package/dist/data/countries.d.ts +0 -2
- package/dist/data/countries.js +0 -105
- package/dist/data/licenses.d.ts +0 -2
- package/dist/data/licenses.js +0 -109
- package/dist/highlight.d.ts +0 -7
- package/dist/index.d.ts +0 -48
- package/dist/index.js +0 -64
- package/dist/input.d.ts +0 -14
- package/dist/pipeline.d.ts +0 -39
- package/dist/pipeline.js +0 -54
- package/dist/prompts/autocomplete.d.ts +0 -22
- package/dist/prompts/box.d.ts +0 -21
- package/dist/prompts/breadcrumb-search.d.ts +0 -14
- package/dist/prompts/breadcrumb.d.ts +0 -32
- package/dist/prompts/byte.d.ts +0 -13
- package/dist/prompts/calculator.d.ts +0 -17
- package/dist/prompts/calendar.d.ts +0 -33
- package/dist/prompts/checkbox.d.ts +0 -13
- package/dist/prompts/code.d.ts +0 -19
- package/dist/prompts/color.d.ts +0 -14
- package/dist/prompts/confirm.d.ts +0 -8
- package/dist/prompts/connection-string.d.ts +0 -18
- package/dist/prompts/cron.d.ts +0 -13
- package/dist/prompts/curl-utils.d.ts +0 -25
- package/dist/prompts/curl-utils.js +0 -41
- package/dist/prompts/curl.d.ts +0 -41
- package/dist/prompts/data-inspector.d.ts +0 -22
- package/dist/prompts/date.d.ts +0 -12
- package/dist/prompts/dependency.d.ts +0 -16
- package/dist/prompts/dial.d.ts +0 -10
- package/dist/prompts/diff.d.ts +0 -10
- package/dist/prompts/diff.js +0 -101
- package/dist/prompts/draw.d.ts +0 -20
- package/dist/prompts/editor.d.ts +0 -14
- package/dist/prompts/editor.js +0 -203
- package/dist/prompts/emoji.d.ts +0 -18
- package/dist/prompts/exec.d.ts +0 -17
- package/dist/prompts/file.d.ts +0 -21
- package/dist/prompts/file.js +0 -210
- package/dist/prompts/form.d.ts +0 -18
- package/dist/prompts/fuzzy-multi-column.d.ts +0 -12
- package/dist/prompts/fuzzy.d.ts +0 -12
- package/dist/prompts/gauge.d.ts +0 -21
- package/dist/prompts/gauge.js +0 -130
- package/dist/prompts/grid.d.ts +0 -14
- package/dist/prompts/heatmap.d.ts +0 -13
- package/dist/prompts/ip.d.ts +0 -11
- package/dist/prompts/kanban.d.ts +0 -17
- package/dist/prompts/keypress.d.ts +0 -7
- package/dist/prompts/keypress.js +0 -55
- package/dist/prompts/license.d.ts +0 -9
- package/dist/prompts/license.js +0 -105
- package/dist/prompts/list.d.ts +0 -9
- package/dist/prompts/map.d.ts +0 -17
- package/dist/prompts/match.d.ts +0 -19
- package/dist/prompts/miller.d.ts +0 -15
- package/dist/prompts/multi-column-select.d.ts +0 -10
- package/dist/prompts/multi-range.d.ts +0 -9
- package/dist/prompts/multi-select.d.ts +0 -15
- package/dist/prompts/number.d.ts +0 -11
- package/dist/prompts/otp.d.ts +0 -10
- package/dist/prompts/pattern.d.ts +0 -22
- package/dist/prompts/phone.d.ts +0 -41
- package/dist/prompts/quiz-select.d.ts +0 -10
- package/dist/prompts/quiz-select.js +0 -104
- package/dist/prompts/quiz-text.d.ts +0 -11
- package/dist/prompts/quiz-text.js +0 -82
- package/dist/prompts/range.d.ts +0 -9
- package/dist/prompts/rating.d.ts +0 -8
- package/dist/prompts/regex.d.ts +0 -13
- package/dist/prompts/region.d.ts +0 -11
- package/dist/prompts/schedule.d.ts +0 -20
- package/dist/prompts/scroll.d.ts +0 -13
- package/dist/prompts/seat.d.ts +0 -17
- package/dist/prompts/seat.js +0 -165
- package/dist/prompts/select-range.d.ts +0 -8
- package/dist/prompts/select.d.ts +0 -15
- package/dist/prompts/semver.d.ts +0 -6
- package/dist/prompts/shortcut.d.ts +0 -9
- package/dist/prompts/shortcut.js +0 -135
- package/dist/prompts/slider.d.ts +0 -8
- package/dist/prompts/slot.d.ts +0 -16
- package/dist/prompts/slot.js +0 -107
- package/dist/prompts/snippet.d.ts +0 -19
- package/dist/prompts/sort-grid.d.ts +0 -16
- package/dist/prompts/sort.d.ts +0 -14
- package/dist/prompts/spam.d.ts +0 -17
- package/dist/prompts/spam.js +0 -62
- package/dist/prompts/spreadsheet.d.ts +0 -21
- package/dist/prompts/table.d.ts +0 -14
- package/dist/prompts/text.d.ts +0 -17
- package/dist/prompts/time.d.ts +0 -12
- package/dist/prompts/toggle.d.ts +0 -8
- package/dist/prompts/toggle.js +0 -47
- package/dist/prompts/transfer.d.ts +0 -18
- package/dist/prompts/tree-select.d.ts +0 -31
- package/dist/prompts/tree.d.ts +0 -20
- package/dist/prompts/wait.d.ts +0 -18
- package/dist/prompts/wait.js +0 -62
- package/dist/spinner.d.ts +0 -33
- package/dist/spinner.js +0 -89
- package/dist/symbols.d.ts +0 -33
- package/dist/tasks.d.ts +0 -57
- package/dist/theme.d.ts +0 -2
- package/dist/theme.js +0 -20
- package/dist/types.d.ts +0 -503
- package/dist/types.js +0 -5
- package/dist/utils.d.ts +0 -81
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// Default to US or VN? Let's default to index 0 (US in our list usually, or whatever is first)
|
|
29
|
-
this.selectedCountryIndex = 0;
|
|
30
|
-
}
|
|
31
|
-
this.filteredIndices = countries_1.COUNTRIES.map((_, i) => i);
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "PhonePrompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PhonePrompt;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _base = require("../base");
|
|
12
|
+
const _countries = require("../data/countries");
|
|
13
|
+
const _theme = require("../theme");
|
|
14
|
+
const _ansi = require("../ansi");
|
|
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;
|
|
32
26
|
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
let PhonePrompt = class PhonePrompt extends _base.Prompt {
|
|
33
30
|
get currentCountry() {
|
|
34
|
-
return
|
|
31
|
+
return _countries.COUNTRIES[this.selectedCountryIndex];
|
|
35
32
|
}
|
|
36
33
|
get mask() {
|
|
37
34
|
return this.currentCountry[3];
|
|
@@ -41,10 +38,9 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
41
38
|
}
|
|
42
39
|
/**
|
|
43
40
|
* Maps a raw index (index in the digit-only string) to a visual index in the formatted string.
|
|
44
|
-
*/
|
|
45
|
-
getVisualIndex(rawIndex, mask) {
|
|
41
|
+
*/ getVisualIndex(rawIndex, mask) {
|
|
46
42
|
let rawCounter = 0;
|
|
47
|
-
for
|
|
43
|
+
for(let i = 0; i < mask.length; i++){
|
|
48
44
|
if (rawCounter === rawIndex) {
|
|
49
45
|
if (mask[i] === '#') {
|
|
50
46
|
return i;
|
|
@@ -59,12 +55,11 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
59
55
|
}
|
|
60
56
|
/**
|
|
61
57
|
* Maps rawIndex to visual index, handling skipping of static characters.
|
|
62
|
-
*/
|
|
63
|
-
getVisualPosition(rawIndex) {
|
|
58
|
+
*/ getVisualPosition(rawIndex) {
|
|
64
59
|
const mask = this.mask;
|
|
65
60
|
let v = 0;
|
|
66
61
|
let r = 0;
|
|
67
|
-
while
|
|
62
|
+
while(v < mask.length){
|
|
68
63
|
if (r === rawIndex) {
|
|
69
64
|
// We reached the raw position.
|
|
70
65
|
// However, if the current mask char is NOT a placeholder, we should skip it
|
|
@@ -74,7 +69,7 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
74
69
|
// v=1(#), r=1 -> next
|
|
75
70
|
// v=2(#), r=2 -> next
|
|
76
71
|
// v=3(-). We are at r=3. The cursor should be at v=4 (the next #).
|
|
77
|
-
while
|
|
72
|
+
while(v < mask.length && mask[v] !== '#'){
|
|
78
73
|
v++;
|
|
79
74
|
}
|
|
80
75
|
return v;
|
|
@@ -88,23 +83,20 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
88
83
|
}
|
|
89
84
|
/**
|
|
90
85
|
* Formats the raw number according to the mask.
|
|
91
|
-
*/
|
|
92
|
-
formatNumber() {
|
|
86
|
+
*/ formatNumber() {
|
|
93
87
|
const mask = this.mask;
|
|
94
88
|
let result = '';
|
|
95
89
|
let rawIdx = 0;
|
|
96
|
-
for
|
|
90
|
+
for(let i = 0; i < mask.length; i++){
|
|
97
91
|
const m = mask[i];
|
|
98
92
|
if (m === '#') {
|
|
99
93
|
if (rawIdx < this.rawNumber.length) {
|
|
100
94
|
result += this.rawNumber[rawIdx];
|
|
101
95
|
rawIdx++;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
96
|
+
} else {
|
|
104
97
|
result += m; // Placeholder
|
|
105
98
|
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
99
|
+
} else {
|
|
108
100
|
result += m;
|
|
109
101
|
}
|
|
110
102
|
}
|
|
@@ -112,30 +104,26 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
112
104
|
}
|
|
113
105
|
/**
|
|
114
106
|
* Renders the formatted number with highlighting.
|
|
115
|
-
*/
|
|
116
|
-
renderFormattedNumber() {
|
|
107
|
+
*/ renderFormattedNumber() {
|
|
117
108
|
const mask = this.mask;
|
|
118
109
|
let output = '';
|
|
119
110
|
let rawIdx = 0;
|
|
120
|
-
for
|
|
111
|
+
for(let i = 0; i < mask.length; i++){
|
|
121
112
|
const m = mask[i];
|
|
122
113
|
if (m === '#') {
|
|
123
114
|
if (rawIdx < this.rawNumber.length) {
|
|
124
115
|
// Typed digit
|
|
125
|
-
output +=
|
|
116
|
+
output += _theme.theme.main + this.rawNumber[rawIdx] + _ansi.ANSI.RESET;
|
|
126
117
|
rawIdx++;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
118
|
+
} else {
|
|
129
119
|
// Placeholder
|
|
130
|
-
output +=
|
|
120
|
+
output += _theme.theme.muted + '#' + _ansi.ANSI.RESET;
|
|
131
121
|
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
else {
|
|
138
|
-
output += theme_1.theme.muted + m + ansi_1.ANSI.RESET;
|
|
122
|
+
} else {
|
|
123
|
+
if (rawIdx > 0 || rawIdx === 0 && this.rawNumber.length > 0) {
|
|
124
|
+
output += _theme.theme.muted + m + _ansi.ANSI.RESET;
|
|
125
|
+
} else {
|
|
126
|
+
output += _theme.theme.muted + m + _ansi.ANSI.RESET;
|
|
139
127
|
}
|
|
140
128
|
}
|
|
141
129
|
}
|
|
@@ -146,8 +134,8 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
146
134
|
this.print(`\x1b[${this.lastLinesUp}B`);
|
|
147
135
|
}
|
|
148
136
|
// 1. Title/Message
|
|
149
|
-
const check = this.errorMsg ?
|
|
150
|
-
const title = `${check} ${
|
|
137
|
+
const check = this.errorMsg ? _theme.theme.error + '✖' : _theme.theme.success + '?';
|
|
138
|
+
const title = `${check} ${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} `;
|
|
151
139
|
// 2. Build Components
|
|
152
140
|
const country = this.currentCountry;
|
|
153
141
|
// Country Section: "+84 (VN)"
|
|
@@ -155,10 +143,9 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
155
143
|
const prefixStr = `+${country[2]} (${country[0]})`;
|
|
156
144
|
let prefixRender = '';
|
|
157
145
|
if (this.activeSection === 'country') {
|
|
158
|
-
prefixRender =
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
prefixRender = theme_1.theme.muted + prefixStr + ansi_1.ANSI.RESET;
|
|
146
|
+
prefixRender = _ansi.ANSI.BG_BLUE + _ansi.ANSI.FG_WHITE + prefixStr + _ansi.ANSI.RESET;
|
|
147
|
+
} else {
|
|
148
|
+
prefixRender = _theme.theme.muted + prefixStr + _ansi.ANSI.RESET;
|
|
162
149
|
}
|
|
163
150
|
// Input Section
|
|
164
151
|
const formatted = this.renderFormattedNumber();
|
|
@@ -167,14 +154,13 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
167
154
|
const line = `${prefixRender} ${inputRender}`;
|
|
168
155
|
let output = title + line;
|
|
169
156
|
if (this.errorMsg) {
|
|
170
|
-
output += `\n${
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
output += `\n${theme_1.theme.muted}Searching: "${this.searchBuffer}"...${ansi_1.ANSI.RESET}`;
|
|
157
|
+
output += `\n${_theme.theme.error}>> ${this.errorMsg}${_ansi.ANSI.RESET}`;
|
|
158
|
+
} else if (this.activeSection === 'country' && this.searchBuffer) {
|
|
159
|
+
output += `\n${_theme.theme.muted}Searching: "${this.searchBuffer}"...${_ansi.ANSI.RESET}`;
|
|
174
160
|
}
|
|
175
161
|
this.renderFrame(output);
|
|
176
162
|
// 3. Cursor Positioning
|
|
177
|
-
const errorOffset =
|
|
163
|
+
const errorOffset = this.errorMsg || this.activeSection === 'country' && this.searchBuffer ? 1 : 0;
|
|
178
164
|
const totalRows = 1 + errorOffset;
|
|
179
165
|
// Reset cursor to end of render
|
|
180
166
|
const linesUp = totalRows - 1;
|
|
@@ -182,18 +168,16 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
182
168
|
this.print(`\x1b[${linesUp}A`);
|
|
183
169
|
}
|
|
184
170
|
this.lastLinesUp = linesUp;
|
|
185
|
-
this.print(
|
|
171
|
+
this.print(_ansi.ANSI.CURSOR_LEFT);
|
|
186
172
|
// Calculate horizontal position
|
|
187
|
-
const titleWidth = (0,
|
|
173
|
+
const titleWidth = (0, _utils.stripAnsi)(title).length;
|
|
188
174
|
if (this.activeSection === 'country') {
|
|
189
175
|
// Place cursor at end of prefix text? Or keep it hidden?
|
|
190
176
|
// Let's place it at the end of the prefix.
|
|
191
177
|
const prefixWidth = prefixStr.length;
|
|
192
178
|
const target = titleWidth + prefixWidth;
|
|
193
|
-
if (target > 0)
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
179
|
+
if (target > 0) this.print(`\x1b[${target}C`);
|
|
180
|
+
} else {
|
|
197
181
|
// Active is number
|
|
198
182
|
// Start position = Title + Prefix + Space
|
|
199
183
|
const prefixWidth = prefixStr.length;
|
|
@@ -201,10 +185,9 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
201
185
|
// Visual offset within input
|
|
202
186
|
const visualOffset = this.getVisualPosition(this.cursor);
|
|
203
187
|
const target = startX + visualOffset;
|
|
204
|
-
if (target > 0)
|
|
205
|
-
this.print(`\x1b[${target}C`);
|
|
188
|
+
if (target > 0) this.print(`\x1b[${target}C`);
|
|
206
189
|
}
|
|
207
|
-
this.print(
|
|
190
|
+
this.print(_ansi.ANSI.SHOW_CURSOR);
|
|
208
191
|
}
|
|
209
192
|
cleanup() {
|
|
210
193
|
if (this.lastLinesUp > 0) {
|
|
@@ -233,14 +216,12 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
233
216
|
this.cursor--;
|
|
234
217
|
this.errorMsg = '';
|
|
235
218
|
this.render(false);
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
219
|
+
} else {
|
|
238
220
|
// If at start of number, maybe backspace into country section?
|
|
239
221
|
this.activeSection = 'country';
|
|
240
222
|
this.render(false);
|
|
241
223
|
}
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
224
|
+
} else {
|
|
244
225
|
// Country section
|
|
245
226
|
if (this.searchBuffer.length > 0) {
|
|
246
227
|
this.searchBuffer = this.searchBuffer.slice(0, -1);
|
|
@@ -251,23 +232,21 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
251
232
|
return;
|
|
252
233
|
}
|
|
253
234
|
// Arrows
|
|
254
|
-
if (char === '\u001b[D') {
|
|
235
|
+
if (char === '\u001b[D') {
|
|
255
236
|
if (this.activeSection === 'number') {
|
|
256
237
|
if (this.cursor > 0) {
|
|
257
238
|
this.cursor--;
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
239
|
+
} else {
|
|
260
240
|
this.activeSection = 'country';
|
|
261
241
|
}
|
|
262
242
|
}
|
|
263
243
|
this.render(false);
|
|
264
244
|
return;
|
|
265
245
|
}
|
|
266
|
-
if (char === '\u001b[C') {
|
|
246
|
+
if (char === '\u001b[C') {
|
|
267
247
|
if (this.activeSection === 'country') {
|
|
268
248
|
this.activeSection = 'number';
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
249
|
+
} else {
|
|
271
250
|
if (this.cursor < this.rawNumber.length) {
|
|
272
251
|
this.cursor++;
|
|
273
252
|
}
|
|
@@ -275,14 +254,14 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
275
254
|
this.render(false);
|
|
276
255
|
return;
|
|
277
256
|
}
|
|
278
|
-
if (char === '\u001b[A') {
|
|
257
|
+
if (char === '\u001b[A') {
|
|
279
258
|
if (this.activeSection === 'country') {
|
|
280
259
|
this.cycleCountry(-1);
|
|
281
260
|
}
|
|
282
261
|
this.render(false);
|
|
283
262
|
return;
|
|
284
263
|
}
|
|
285
|
-
if (char === '\u001b[B') {
|
|
264
|
+
if (char === '\u001b[B') {
|
|
286
265
|
if (this.activeSection === 'country') {
|
|
287
266
|
this.cycleCountry(1);
|
|
288
267
|
}
|
|
@@ -295,8 +274,7 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
295
274
|
this.searchBuffer += char;
|
|
296
275
|
this.filterCountries();
|
|
297
276
|
this.render(false);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
277
|
+
} else {
|
|
300
278
|
// Number input: digits only
|
|
301
279
|
if (/^\d+$/.test(char)) {
|
|
302
280
|
// Check max length
|
|
@@ -314,29 +292,27 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
314
292
|
filterCountries() {
|
|
315
293
|
// Simple search logic
|
|
316
294
|
if (!this.searchBuffer) {
|
|
317
|
-
this.filteredIndices =
|
|
295
|
+
this.filteredIndices = _countries.COUNTRIES.map((_, i)=>i);
|
|
318
296
|
return;
|
|
319
297
|
}
|
|
320
298
|
// Prioritize: Starts with ISO, Starts with Name, Fuzzy Name
|
|
321
299
|
const buf = this.searchBuffer.toLowerCase();
|
|
322
|
-
const matches =
|
|
300
|
+
const matches = _countries.COUNTRIES.map((c, i)=>{
|
|
323
301
|
const iso = c[0].toLowerCase();
|
|
324
302
|
const name = c[1].toLowerCase();
|
|
325
303
|
const dial = c[2];
|
|
326
304
|
let score = 0;
|
|
327
|
-
if (iso.startsWith(buf))
|
|
328
|
-
|
|
329
|
-
if (
|
|
330
|
-
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
.sort((a, b) => b.score - a.score);
|
|
339
|
-
this.filteredIndices = matches.map(m => m.index);
|
|
305
|
+
if (iso.startsWith(buf)) score += 100;
|
|
306
|
+
if (name.startsWith(buf)) score += 50;
|
|
307
|
+
if (dial.startsWith(buf)) score += 20; // Search by code
|
|
308
|
+
const fuzzy = (0, _utils.fuzzyMatch)(this.searchBuffer, c[1]);
|
|
309
|
+
if (fuzzy) score += fuzzy.score;
|
|
310
|
+
return {
|
|
311
|
+
index: i,
|
|
312
|
+
score
|
|
313
|
+
};
|
|
314
|
+
}).filter((x)=>x.score > 0).sort((a, b)=>b.score - a.score);
|
|
315
|
+
this.filteredIndices = matches.map((m)=>m.index);
|
|
340
316
|
// Auto-select first match
|
|
341
317
|
if (this.filteredIndices.length > 0) {
|
|
342
318
|
this.selectedCountryIndex = this.filteredIndices[0];
|
|
@@ -349,10 +325,8 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
349
325
|
// Cycle within filtered list
|
|
350
326
|
const currentInFiltered = this.filteredIndices.indexOf(this.selectedCountryIndex);
|
|
351
327
|
let nextIdx = currentInFiltered + dir;
|
|
352
|
-
if (nextIdx < 0)
|
|
353
|
-
|
|
354
|
-
if (nextIdx >= this.filteredIndices.length)
|
|
355
|
-
nextIdx = 0;
|
|
328
|
+
if (nextIdx < 0) nextIdx = this.filteredIndices.length - 1;
|
|
329
|
+
if (nextIdx >= this.filteredIndices.length) nextIdx = 0;
|
|
356
330
|
this.selectedCountryIndex = this.filteredIndices[nextIdx];
|
|
357
331
|
this.enforceMaxLen();
|
|
358
332
|
}
|
|
@@ -363,8 +337,7 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
363
337
|
const max = this.getMaxRawLength();
|
|
364
338
|
if (this.rawNumber.length > max) {
|
|
365
339
|
this.rawNumber = this.rawNumber.slice(0, max);
|
|
366
|
-
if (this.cursor > max)
|
|
367
|
-
this.cursor = max;
|
|
340
|
+
if (this.cursor > max) this.cursor = max;
|
|
368
341
|
}
|
|
369
342
|
}
|
|
370
343
|
validateAndSubmit() {
|
|
@@ -395,8 +368,8 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
395
368
|
}
|
|
396
369
|
handleMouse(event) {
|
|
397
370
|
if (event.action === 'press' || event.action === 'move') {
|
|
398
|
-
|
|
399
|
-
|
|
371
|
+
// This is hard to map without exact coordinates of sections.
|
|
372
|
+
// Simplified: Scroll changes country if active.
|
|
400
373
|
}
|
|
401
374
|
if (event.scroll) {
|
|
402
375
|
if (this.activeSection === 'country') {
|
|
@@ -405,5 +378,21 @@ class PhonePrompt extends base_1.Prompt {
|
|
|
405
378
|
}
|
|
406
379
|
}
|
|
407
380
|
}
|
|
408
|
-
|
|
409
|
-
|
|
381
|
+
constructor(options){
|
|
382
|
+
super(options), _define_property(this, "activeSection", 'number'), _define_property(this, "selectedCountryIndex", 0), _define_property(this, "rawNumber", '') // Only digits
|
|
383
|
+
, _define_property(this, "cursor", 0) // Index in rawNumber
|
|
384
|
+
, _define_property(this, "searchBuffer", ''), _define_property(this, "lastLinesUp", 0), _define_property(this, "errorMsg", ''), // For country search/filtering
|
|
385
|
+
_define_property(this, "filteredIndices", []);
|
|
386
|
+
// Initialize country
|
|
387
|
+
if (options.defaultCountry) {
|
|
388
|
+
const idx = _countries.COUNTRIES.findIndex((c)=>c[0] === options.defaultCountry?.toUpperCase());
|
|
389
|
+
if (idx !== -1) this.selectedCountryIndex = idx;
|
|
390
|
+
} else {
|
|
391
|
+
// Default to US or VN? Let's default to index 0 (US in our list usually, or whatever is first)
|
|
392
|
+
this.selectedCountryIndex = 0;
|
|
393
|
+
}
|
|
394
|
+
this.filteredIndices = _countries.COUNTRIES.map((_, i)=>i);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
//# sourceMappingURL=phone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/phone.ts"],"sourcesContent":["import { Prompt } from '../base';\nimport { PhoneOptions } from '../types';\nimport { COUNTRIES, CountryEntry } from '../data/countries';\nimport { theme } from '../theme';\nimport { ANSI } from '../ansi';\nimport { fuzzyMatch, stripAnsi } from '../utils';\n\nexport class PhonePrompt extends Prompt<string, PhoneOptions> {\n protected activeSection: 'country' | 'number' = 'number';\n protected selectedCountryIndex: number = 0;\n protected rawNumber: string = ''; // Only digits\n protected cursor: number = 0; // Index in rawNumber\n protected searchBuffer: string = '';\n protected lastLinesUp: number = 0;\n protected errorMsg: string = '';\n\n // For country search/filtering\n protected filteredIndices: number[] = [];\n\n constructor(options: PhoneOptions) {\n super(options);\n\n // Initialize country\n if (options.defaultCountry) {\n const idx = COUNTRIES.findIndex(c => c[0] === options.defaultCountry?.toUpperCase());\n if (idx !== -1) this.selectedCountryIndex = idx;\n } else {\n // Default to US or VN? Let's default to index 0 (US in our list usually, or whatever is first)\n this.selectedCountryIndex = 0;\n }\n\n this.filteredIndices = COUNTRIES.map((_, i) => i);\n }\n\n private get currentCountry(): CountryEntry {\n return COUNTRIES[this.selectedCountryIndex];\n }\n\n private get mask(): string {\n return this.currentCountry[3];\n }\n\n private get dialCode(): string {\n return this.currentCountry[2];\n }\n\n /**\n * Maps a raw index (index in the digit-only string) to a visual index in the formatted string.\n */\n private getVisualIndex(rawIndex: number, mask: string): number {\n let rawCounter = 0;\n for (let i = 0; i < mask.length; i++) {\n if (rawCounter === rawIndex) {\n if (mask[i] === '#') {\n return i;\n }\n }\n\n if (mask[i] === '#') {\n rawCounter++;\n }\n }\n // If we went past the end\n return mask.length;\n }\n\n /**\n * Maps rawIndex to visual index, handling skipping of static characters.\n */\n private getVisualPosition(rawIndex: number): number {\n const mask = this.mask;\n let v = 0;\n let r = 0;\n\n while (v < mask.length) {\n if (r === rawIndex) {\n // We reached the raw position. \n // However, if the current mask char is NOT a placeholder, we should skip it\n // because the user doesn't type it.\n // E.g. mask \"###-###\". rawIndex 3.\n // v=0(#), r=0 -> next\n // v=1(#), r=1 -> next\n // v=2(#), r=2 -> next\n // v=3(-). We are at r=3. The cursor should be at v=4 (the next #).\n while (v < mask.length && mask[v] !== '#') {\n v++;\n }\n return v;\n }\n\n if (mask[v] === '#') {\n r++;\n }\n v++;\n }\n return v;\n }\n\n /**\n * Formats the raw number according to the mask.\n */\n private formatNumber(): string {\n const mask = this.mask;\n let result = '';\n let rawIdx = 0;\n\n for (let i = 0; i < mask.length; i++) {\n const m = mask[i];\n if (m === '#') {\n if (rawIdx < this.rawNumber.length) {\n result += this.rawNumber[rawIdx];\n rawIdx++;\n } else {\n result += m; // Placeholder\n }\n } else {\n result += m;\n }\n }\n return result;\n }\n\n /**\n * Renders the formatted number with highlighting.\n */\n private renderFormattedNumber(): string {\n const mask = this.mask;\n let output = '';\n let rawIdx = 0;\n\n for (let i = 0; i < mask.length; i++) {\n const m = mask[i];\n if (m === '#') {\n if (rawIdx < this.rawNumber.length) {\n // Typed digit\n output += theme.main + this.rawNumber[rawIdx] + ANSI.RESET;\n rawIdx++;\n } else {\n // Placeholder\n output += theme.muted + '#' + ANSI.RESET;\n }\n } else {\n if (rawIdx > 0 || (rawIdx === 0 && this.rawNumber.length > 0)) {\n output += theme.muted + m + ANSI.RESET;\n } else {\n output += theme.muted + m + ANSI.RESET;\n }\n }\n }\n return output;\n }\n\n protected render(firstRender: boolean) {\n if (!firstRender && this.lastLinesUp > 0) {\n this.print(`\\x1b[${this.lastLinesUp}B`);\n }\n\n // 1. Title/Message\n const check = this.errorMsg ? theme.error + '✖' : theme.success + '?';\n const title = `${check} ${theme.title}${this.options.message}${ANSI.RESET} `;\n\n // 2. Build Components\n const country = this.currentCountry;\n\n // Country Section: \"+84 (VN)\"\n // Highlight if active\n const prefixStr = `+${country[2]} (${country[0]})`;\n let prefixRender = '';\n if (this.activeSection === 'country') {\n prefixRender = ANSI.BG_BLUE + ANSI.FG_WHITE + prefixStr + ANSI.RESET;\n } else {\n prefixRender = theme.muted + prefixStr + ANSI.RESET;\n }\n\n // Input Section\n const formatted = this.renderFormattedNumber();\n const inputRender = formatted;\n\n // Layout: [Prefix] [Input]\n const line = `${prefixRender} ${inputRender}`;\n\n let output = title + line;\n\n if (this.errorMsg) {\n output += `\\n${theme.error}>> ${this.errorMsg}${ANSI.RESET}`;\n } else if (this.activeSection === 'country' && this.searchBuffer) {\n output += `\\n${theme.muted}Searching: \"${this.searchBuffer}\"...${ANSI.RESET}`;\n }\n\n this.renderFrame(output);\n\n // 3. Cursor Positioning\n const errorOffset = (this.errorMsg || (this.activeSection === 'country' && this.searchBuffer)) ? 1 : 0;\n const totalRows = 1 + errorOffset;\n\n // Reset cursor to end of render\n const linesUp = totalRows - 1;\n if (linesUp > 0) {\n this.print(`\\x1b[${linesUp}A`);\n }\n this.lastLinesUp = linesUp;\n\n this.print(ANSI.CURSOR_LEFT);\n\n // Calculate horizontal position\n const titleWidth = stripAnsi(title).length;\n\n if (this.activeSection === 'country') {\n // Place cursor at end of prefix text? Or keep it hidden?\n // Let's place it at the end of the prefix.\n const prefixWidth = prefixStr.length;\n const target = titleWidth + prefixWidth;\n if (target > 0) this.print(`\\x1b[${target}C`);\n } else {\n // Active is number\n // Start position = Title + Prefix + Space\n const prefixWidth = prefixStr.length;\n const startX = titleWidth + prefixWidth + 1;\n\n // Visual offset within input\n const visualOffset = this.getVisualPosition(this.cursor);\n const target = startX + visualOffset;\n\n if (target > 0) this.print(`\\x1b[${target}C`);\n }\n\n this.print(ANSI.SHOW_CURSOR);\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 // Handle common keys\n if (char === '\\r' || char === '\\n') {\n this.validateAndSubmit();\n return;\n }\n\n if (char === '\\t') {\n // Toggle section\n this.activeSection = this.activeSection === 'country' ? 'number' : 'country';\n this.render(false);\n return;\n }\n\n // Backspace\n if (char === '\\x7f' || char === '\\u0008') {\n if (this.activeSection === 'number') {\n if (this.cursor > 0) {\n this.rawNumber = this.rawNumber.slice(0, this.cursor - 1) + this.rawNumber.slice(this.cursor);\n this.cursor--;\n this.errorMsg = '';\n this.render(false);\n } else {\n // If at start of number, maybe backspace into country section?\n this.activeSection = 'country';\n this.render(false);\n }\n } else {\n // Country section\n if (this.searchBuffer.length > 0) {\n this.searchBuffer = this.searchBuffer.slice(0, -1);\n this.filterCountries();\n this.render(false);\n }\n }\n return;\n }\n\n // Arrows\n if (char === '\\u001b[D') { // Left\n if (this.activeSection === 'number') {\n if (this.cursor > 0) {\n this.cursor--;\n } else {\n this.activeSection = 'country';\n }\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[C') { // Right\n if (this.activeSection === 'country') {\n this.activeSection = 'number';\n } else {\n if (this.cursor < this.rawNumber.length) {\n this.cursor++;\n }\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[A') { // Up\n if (this.activeSection === 'country') {\n this.cycleCountry(-1);\n }\n this.render(false);\n return;\n }\n\n if (char === '\\u001b[B') { // Down\n if (this.activeSection === 'country') {\n this.cycleCountry(1);\n }\n this.render(false);\n return;\n }\n\n // Typing\n if (!/^[\\x00-\\x1F]/.test(char) && !char.startsWith('\\x1b')) {\n if (this.activeSection === 'country') {\n this.searchBuffer += char;\n this.filterCountries();\n this.render(false);\n } else {\n // Number input: digits only\n if (/^\\d+$/.test(char)) {\n // Check max length\n const maxLen = this.getMaxRawLength();\n if (this.rawNumber.length < maxLen) {\n this.rawNumber = this.rawNumber.slice(0, this.cursor) + char + this.rawNumber.slice(this.cursor);\n this.cursor++;\n this.errorMsg = '';\n this.render(false);\n }\n }\n }\n }\n }\n\n private filterCountries() {\n // Simple search logic\n if (!this.searchBuffer) {\n this.filteredIndices = COUNTRIES.map((_, i) => i);\n return;\n }\n\n // Prioritize: Starts with ISO, Starts with Name, Fuzzy Name\n const buf = this.searchBuffer.toLowerCase();\n\n const matches = COUNTRIES.map((c, i) => {\n const iso = c[0].toLowerCase();\n const name = c[1].toLowerCase();\n const dial = c[2];\n\n let score = 0;\n if (iso.startsWith(buf)) score += 100;\n if (name.startsWith(buf)) score += 50;\n if (dial.startsWith(buf)) score += 20; // Search by code\n\n const fuzzy = fuzzyMatch(this.searchBuffer, c[1]);\n if (fuzzy) score += fuzzy.score;\n\n return { index: i, score };\n }).filter(x => x.score > 0)\n .sort((a, b) => b.score - a.score);\n\n this.filteredIndices = matches.map(m => m.index);\n\n // Auto-select first match\n if (this.filteredIndices.length > 0) {\n this.selectedCountryIndex = this.filteredIndices[0];\n\n // If we changed country, we should validate/truncate current rawNumber?\n // The mask might change.\n this.enforceMaxLen();\n }\n }\n\n private cycleCountry(dir: number) {\n // Cycle within filtered list\n const currentInFiltered = this.filteredIndices.indexOf(this.selectedCountryIndex);\n let nextIdx = currentInFiltered + dir;\n\n if (nextIdx < 0) nextIdx = this.filteredIndices.length - 1;\n if (nextIdx >= this.filteredIndices.length) nextIdx = 0;\n\n this.selectedCountryIndex = this.filteredIndices[nextIdx];\n this.enforceMaxLen();\n }\n\n private getMaxRawLength(): number {\n return this.mask.split('#').length - 1;\n }\n\n private enforceMaxLen() {\n const max = this.getMaxRawLength();\n if (this.rawNumber.length > max) {\n this.rawNumber = this.rawNumber.slice(0, max);\n if (this.cursor > max) this.cursor = max;\n }\n }\n\n private validateAndSubmit() {\n if (this.options.strict) {\n const max = this.getMaxRawLength();\n if (this.rawNumber.length !== max) {\n this.errorMsg = `Number too short (expected ${max} digits)`;\n this.render(false);\n return;\n }\n }\n\n // Validation callback\n const e164 = `+${this.dialCode}${this.rawNumber}`;\n if (this.options.validate) {\n const valid = this.options.validate(e164); // Pass strict format\n if (typeof valid === 'string') {\n this.errorMsg = valid;\n this.render(false);\n return;\n }\n if (valid === false) {\n this.errorMsg = 'Invalid phone number';\n this.render(false);\n return;\n }\n }\n\n this.submit(e164);\n }\n\n protected handleMouse(event: any) {\n if (event.action === 'press' || event.action === 'move') {\n // This is hard to map without exact coordinates of sections.\n // Simplified: Scroll changes country if active.\n }\n\n if (event.scroll) {\n if (this.activeSection === 'country') {\n this.cycleCountry(event.scroll === 'up' ? -1 : 1);\n this.render(false);\n }\n }\n }\n}\n"],"names":["PhonePrompt","Prompt","currentCountry","COUNTRIES","selectedCountryIndex","mask","dialCode","getVisualIndex","rawIndex","rawCounter","i","length","getVisualPosition","v","r","formatNumber","result","rawIdx","m","rawNumber","renderFormattedNumber","output","theme","main","ANSI","RESET","muted","render","firstRender","lastLinesUp","print","check","errorMsg","error","success","title","options","message","country","prefixStr","prefixRender","activeSection","BG_BLUE","FG_WHITE","formatted","inputRender","line","searchBuffer","renderFrame","errorOffset","totalRows","linesUp","CURSOR_LEFT","titleWidth","stripAnsi","prefixWidth","target","startX","visualOffset","cursor","SHOW_CURSOR","cleanup","handleInput","char","validateAndSubmit","slice","filterCountries","cycleCountry","test","startsWith","maxLen","getMaxRawLength","filteredIndices","map","_","buf","toLowerCase","matches","c","iso","name","dial","score","fuzzy","fuzzyMatch","index","filter","x","sort","a","b","enforceMaxLen","dir","currentInFiltered","indexOf","nextIdx","split","max","strict","e164","validate","valid","submit","handleMouse","event","action","scroll","defaultCountry","idx","findIndex","toUpperCase"],"mappings":";;;;+BAOaA;;;eAAAA;;;sBAPU;2BAEiB;uBAClB;sBACD;uBACiB;;;;;;;;;;;;;;AAE/B,IAAA,AAAMA,cAAN,MAAMA,oBAAoBC,YAAM;IA2BnC,IAAYC,iBAA+B;QACvC,OAAOC,oBAAS,CAAC,IAAI,CAACC,oBAAoB,CAAC;IAC/C;IAEA,IAAYC,OAAe;QACvB,OAAO,IAAI,CAACH,cAAc,CAAC,EAAE;IACjC;IAEA,IAAYI,WAAmB;QAC3B,OAAO,IAAI,CAACJ,cAAc,CAAC,E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C,CAACC,GAAGhE,IAAMA;IACnD;AA2ZJ"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "QuizSelectPrompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return QuizSelectPrompt;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ansi = require("../ansi");
|
|
12
|
+
const _theme = require("../theme");
|
|
13
|
+
const _symbols = require("../symbols");
|
|
14
|
+
const _select = require("./select");
|
|
15
|
+
function _define_property(obj, key, value) {
|
|
16
|
+
if (key in obj) {
|
|
17
|
+
Object.defineProperty(obj, key, {
|
|
18
|
+
value: value,
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
obj[key] = value;
|
|
25
|
+
}
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
let QuizSelectPrompt = class QuizSelectPrompt extends _select.SelectPrompt {
|
|
29
|
+
handleInput(char) {
|
|
30
|
+
if (this.status === 'revealed') {
|
|
31
|
+
// Wait for Enter to submit
|
|
32
|
+
if (char === '\r' || char === '\n') {
|
|
33
|
+
const choices = this.getFilteredChoices();
|
|
34
|
+
// Ensure index is valid, though it should be captured
|
|
35
|
+
const value = choices[this.userSelectionIndex] ? choices[this.userSelectionIndex].value : null;
|
|
36
|
+
this.submit(value);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (this.status === 'pending') {
|
|
41
|
+
// Intercept Enter
|
|
42
|
+
if (char === '\r' || char === '\n') {
|
|
43
|
+
const choices = this.getFilteredChoices();
|
|
44
|
+
if (choices.length === 0) return;
|
|
45
|
+
if (this.isSeparator(choices[this.selectedIndex])) return;
|
|
46
|
+
this.userSelectionIndex = this.selectedIndex;
|
|
47
|
+
const selectedChoice = choices[this.userSelectionIndex];
|
|
48
|
+
// Check correctness
|
|
49
|
+
this.isCorrect = selectedChoice.value === this.options.correctValue;
|
|
50
|
+
this.status = 'revealed';
|
|
51
|
+
this.render(false);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Delegate navigation to super
|
|
55
|
+
super.handleInput(char);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
render(firstRender) {
|
|
59
|
+
if (this.status === 'pending') {
|
|
60
|
+
super.render(firstRender);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Revealed State
|
|
64
|
+
let output = '';
|
|
65
|
+
const choices = this.getFilteredChoices();
|
|
66
|
+
// Header
|
|
67
|
+
const icon = this.isCorrect ? `${_theme.theme.success}${_symbols.symbols.tick}` : `${_theme.theme.error}${_symbols.symbols.cross}`;
|
|
68
|
+
output += `${icon} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET}\n`;
|
|
69
|
+
const visibleChoices = choices.slice(this.scrollTop, this.scrollTop + this.pageSize);
|
|
70
|
+
visibleChoices.forEach((choice, index)=>{
|
|
71
|
+
if (index > 0) output += '\n';
|
|
72
|
+
if (this.isSeparator(choice)) {
|
|
73
|
+
output += ` ${_ansi.ANSI.DIM}${choice.text || _symbols.symbols.line.repeat(8)}${_ansi.ANSI.RESET}`;
|
|
74
|
+
} else {
|
|
75
|
+
// Determine absolute index to match with user selection
|
|
76
|
+
const actualIndex = this.scrollTop + index;
|
|
77
|
+
const isSelected = actualIndex === this.userSelectionIndex;
|
|
78
|
+
const isCorrectAnswer = choice.value === this.options.correctValue;
|
|
79
|
+
let prefix = ' ';
|
|
80
|
+
let style = _ansi.ANSI.RESET;
|
|
81
|
+
if (isSelected) {
|
|
82
|
+
if (this.isCorrect) {
|
|
83
|
+
prefix = `${_theme.theme.success}${_symbols.symbols.pointer} `;
|
|
84
|
+
style = _theme.theme.success;
|
|
85
|
+
} else {
|
|
86
|
+
prefix = `${_theme.theme.error}${_symbols.symbols.cross} `;
|
|
87
|
+
style = _theme.theme.error;
|
|
88
|
+
}
|
|
89
|
+
} else if (isCorrectAnswer) {
|
|
90
|
+
prefix = `${_theme.theme.success}${_symbols.symbols.pointer} `;
|
|
91
|
+
style = _theme.theme.success;
|
|
92
|
+
}
|
|
93
|
+
output += `${prefix}${style}${choice.title}${_ansi.ANSI.RESET}`;
|
|
94
|
+
if (isSelected && !this.isCorrect) {
|
|
95
|
+
output += ` ${_theme.theme.error}(Your Answer)${_ansi.ANSI.RESET}`;
|
|
96
|
+
}
|
|
97
|
+
if (isCorrectAnswer && !isSelected) {
|
|
98
|
+
output += ` ${_theme.theme.success}(Correct)${_ansi.ANSI.RESET}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
// Explanation
|
|
103
|
+
if (this.options.explanation) {
|
|
104
|
+
output += `\n\n${_ansi.ANSI.BOLD}Explanation:${_ansi.ANSI.RESET}\n${_theme.theme.muted}${this.options.explanation}${_ansi.ANSI.RESET}`;
|
|
105
|
+
}
|
|
106
|
+
output += `\n\n${_ansi.ANSI.DIM}(Press Enter to continue)${_ansi.ANSI.RESET}`;
|
|
107
|
+
this.renderFrame(output);
|
|
108
|
+
}
|
|
109
|
+
constructor(options){
|
|
110
|
+
super(options), _define_property(this, "status", 'pending'), _define_property(this, "isCorrect", false), _define_property(this, "userSelectionIndex", -1);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=quiz-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/quiz-select.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { theme } from '../theme';\nimport { symbols } from '../symbols';\nimport { QuizSelectOptions } from '../types';\nimport { SelectPrompt } from './select';\n\nexport class QuizSelectPrompt<V> extends SelectPrompt<V, QuizSelectOptions<V>> {\n private status: 'pending' | 'revealed' = 'pending';\n private isCorrect: boolean = false;\n private userSelectionIndex: number = -1;\n\n constructor(options: QuizSelectOptions<V>) {\n super(options);\n }\n\n protected handleInput(char: string) {\n if (this.status === 'revealed') {\n // Wait for Enter to submit\n if (char === '\\r' || char === '\\n') {\n const choices = this.getFilteredChoices();\n // Ensure index is valid, though it should be captured\n const value = choices[this.userSelectionIndex]\n ? (choices[this.userSelectionIndex] as any).value\n : null;\n this.submit(value as V);\n }\n return;\n }\n\n if (this.status === 'pending') {\n // Intercept Enter\n if (char === '\\r' || char === '\\n') {\n const choices = this.getFilteredChoices();\n if (choices.length === 0) return;\n if (this.isSeparator(choices[this.selectedIndex])) return;\n\n this.userSelectionIndex = this.selectedIndex;\n const selectedChoice = choices[this.userSelectionIndex] as any;\n\n // Check correctness\n this.isCorrect = selectedChoice.value === this.options.correctValue;\n\n this.status = 'revealed';\n this.render(false);\n return;\n }\n\n // Delegate navigation to super\n super.handleInput(char);\n }\n }\n\n protected render(firstRender: boolean) {\n if (this.status === 'pending') {\n super.render(firstRender);\n return;\n }\n\n // Revealed State\n let output = '';\n const choices = this.getFilteredChoices();\n\n // Header\n const icon = this.isCorrect ? `${theme.success}${symbols.tick}` : `${theme.error}${symbols.cross}`;\n output += `${icon} ${ANSI.BOLD}${theme.title}${this.options.message}${ANSI.RESET}\\n`;\n\n const visibleChoices = choices.slice(this.scrollTop, this.scrollTop + this.pageSize);\n\n visibleChoices.forEach((choice, index) => {\n if (index > 0) output += '\\n';\n\n if (this.isSeparator(choice)) {\n output += ` ${ANSI.DIM}${(choice as any).text || symbols.line.repeat(8)}${ANSI.RESET}`;\n } else {\n // Determine absolute index to match with user selection\n const actualIndex = this.scrollTop + index;\n const isSelected = actualIndex === this.userSelectionIndex;\n const isCorrectAnswer = (choice as any).value === this.options.correctValue;\n\n let prefix = ' ';\n let style = ANSI.RESET;\n\n if (isSelected) {\n if (this.isCorrect) {\n prefix = `${theme.success}${symbols.pointer} `;\n style = theme.success;\n } else {\n prefix = `${theme.error}${symbols.cross} `;\n style = theme.error;\n }\n } else if (isCorrectAnswer) {\n prefix = `${theme.success}${symbols.pointer} `;\n style = theme.success;\n }\n\n output += `${prefix}${style}${(choice as any).title}${ANSI.RESET}`;\n\n if (isSelected && !this.isCorrect) {\n output += ` ${theme.error}(Your Answer)${ANSI.RESET}`;\n }\n if (isCorrectAnswer && !isSelected) {\n output += ` ${theme.success}(Correct)${ANSI.RESET}`;\n }\n }\n });\n\n // Explanation\n if (this.options.explanation) {\n output += `\\n\\n${ANSI.BOLD}Explanation:${ANSI.RESET}\\n${theme.muted}${this.options.explanation}${ANSI.RESET}`;\n }\n\n output += `\\n\\n${ANSI.DIM}(Press Enter to continue)${ANSI.RESET}`;\n\n this.renderFrame(output);\n }\n}\n"],"names":["QuizSelectPrompt","SelectPrompt","handleInput","char","status","choices","getFilteredChoices","value","userSelectionIndex","submit","length","isSeparator","selectedIndex","selectedChoice","isCorrect","options","correctValue","render","firstRender","output","icon","theme","success","symbols","tick","error","cross","ANSI","BOLD","title","message","RESET","visibleChoices","slice","scrollTop","pageSize","forEach","choice","index","DIM","text","line","repeat","actualIndex","isSelected","isCorrectAnswer","prefix","style","pointer","explanation","muted","renderFrame"],"mappings":";;;;+BAMaA;;;eAAAA;;;sBANQ;uBACC;yBACE;wBAEK;;;;;;;;;;;;;;AAEtB,IAAA,AAAMA,mBAAN,MAAMA,yBAA4BC,oBAAY;IASvCC,YAAYC,IAAY,EAAE;QAChC,IAAI,IAAI,CAACC,MAAM,KAAK,YAAY;YAC5B,2BAA2B;YAC3B,IAAID,SAAS,QAAQA,SAAS,MAAM;gBAChC,MAAME,UAAU,IAAI,CAACC,kBAAkB;gBACvC,sDAAsD;gBACtD,MAAMC,QAAQF,OAAO,CAAC,IAAI,CAACG,kBAAkB,CAAC,GACxC,AAACH,OAAO,CAAC,IAAI,CAACG,kBAAkB,CAAC,CAASD,KAAK,GAC/C;gBACN,IAAI,CAACE,MAAM,CAACF;YAChB;YAC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