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,23 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ColorPrompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ColorPrompt;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ansi = require("../ansi");
|
|
12
|
+
const _base = require("../base");
|
|
13
|
+
const _theme = require("../theme");
|
|
14
|
+
function _define_property(obj, key, value) {
|
|
15
|
+
if (key in obj) {
|
|
16
|
+
Object.defineProperty(obj, key, {
|
|
17
|
+
value: value,
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
obj[key] = value;
|
|
13
24
|
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
let ColorPrompt = class ColorPrompt extends _base.Prompt {
|
|
14
28
|
parseHex(hex) {
|
|
15
29
|
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
16
30
|
return result ? {
|
|
17
31
|
r: parseInt(result[1], 16),
|
|
18
32
|
g: parseInt(result[2], 16),
|
|
19
33
|
b: parseInt(result[3], 16)
|
|
20
|
-
} : {
|
|
34
|
+
} : {
|
|
35
|
+
r: 0,
|
|
36
|
+
g: 0,
|
|
37
|
+
b: 0
|
|
38
|
+
};
|
|
21
39
|
}
|
|
22
40
|
rgbToHex(r, g, b) {
|
|
23
41
|
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
|
|
@@ -29,45 +47,51 @@ class ColorPrompt extends base_1.Prompt {
|
|
|
29
47
|
render(_firstRender) {
|
|
30
48
|
const { r, g, b } = this.rgb;
|
|
31
49
|
const hex = this.rgbToHex(r, g, b);
|
|
32
|
-
let output = `${
|
|
33
|
-
output += `${
|
|
50
|
+
let output = `${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} `;
|
|
51
|
+
output += `${_ansi.ANSI.BOLD}${hex}${_ansi.ANSI.RESET}\n\n`;
|
|
34
52
|
// Preview Block
|
|
35
53
|
if (this.capabilities.hasTrueColor) {
|
|
36
54
|
const bg = this.getBgColorCode(r, g, b);
|
|
37
|
-
const block = `${bg} ${
|
|
55
|
+
const block = `${bg} ${_ansi.ANSI.RESET}`; // 8 spaces
|
|
38
56
|
output += ` ${block}\n`;
|
|
39
57
|
output += ` ${block}\n`;
|
|
40
58
|
output += ` ${block}\n\n`;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
59
|
+
} else {
|
|
43
60
|
// Fallback for no true color?
|
|
44
61
|
// Maybe just show text or use closest 256 color?
|
|
45
62
|
// For now, simpler fallback:
|
|
46
63
|
output += ` (Preview unavailable in this terminal)\n\n`;
|
|
47
64
|
}
|
|
48
65
|
// Sliders
|
|
49
|
-
const channels = [
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
const channels = [
|
|
67
|
+
'r',
|
|
68
|
+
'g',
|
|
69
|
+
'b'
|
|
70
|
+
];
|
|
71
|
+
const labels = {
|
|
72
|
+
r: 'Red ',
|
|
73
|
+
g: 'Green',
|
|
74
|
+
b: 'Blue '
|
|
75
|
+
};
|
|
76
|
+
channels.forEach((ch)=>{
|
|
52
77
|
const val = this.rgb[ch];
|
|
53
78
|
const isActive = this.activeChannel === ch;
|
|
54
79
|
// Render slider track
|
|
55
80
|
// Width 20 chars for 0-255
|
|
56
81
|
const width = 20;
|
|
57
|
-
const pos = Math.floor(
|
|
82
|
+
const pos = Math.floor(val / 255 * width);
|
|
58
83
|
// Wait, '⚪' might be wide. using simpler char if needed. 'O' or ANSI reverse space.
|
|
59
84
|
// Let's use standard chars.
|
|
60
85
|
const trackSimple = '━'.repeat(pos) + (isActive ? '●' : '○') + '─'.repeat(width - pos);
|
|
61
86
|
let line = `${labels[ch]}: ${val.toString().padStart(3)} [${trackSimple}]`;
|
|
62
87
|
if (isActive) {
|
|
63
|
-
line = `${
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
88
|
+
line = `${_theme.theme.main}${_ansi.ANSI.REVERSE} ${line} ${_ansi.ANSI.RESET}`;
|
|
89
|
+
} else {
|
|
66
90
|
line = ` ${line} `;
|
|
67
91
|
}
|
|
68
92
|
output += line + '\n';
|
|
69
93
|
});
|
|
70
|
-
output += `\n${
|
|
94
|
+
output += `\n${_theme.theme.muted}Arrows: Adjust/Switch | Shift+Arrows: Adjust fast | Enter: Submit${_ansi.ANSI.RESET}`;
|
|
71
95
|
this.renderFrame(output);
|
|
72
96
|
}
|
|
73
97
|
handleInput(char, _key) {
|
|
@@ -82,32 +106,24 @@ class ColorPrompt extends base_1.Prompt {
|
|
|
82
106
|
const isShiftLeft = char === '\x1b[1;2D';
|
|
83
107
|
// Channel Switching (Up/Down)
|
|
84
108
|
if (isUp) {
|
|
85
|
-
if (this.activeChannel === 'g')
|
|
86
|
-
|
|
87
|
-
else if (this.activeChannel === 'b')
|
|
88
|
-
this.activeChannel = 'g';
|
|
109
|
+
if (this.activeChannel === 'g') this.activeChannel = 'r';
|
|
110
|
+
else if (this.activeChannel === 'b') this.activeChannel = 'g';
|
|
89
111
|
this.render(false);
|
|
90
112
|
return;
|
|
91
113
|
}
|
|
92
114
|
if (isDown) {
|
|
93
|
-
if (this.activeChannel === 'r')
|
|
94
|
-
|
|
95
|
-
else if (this.activeChannel === 'g')
|
|
96
|
-
this.activeChannel = 'b';
|
|
115
|
+
if (this.activeChannel === 'r') this.activeChannel = 'g';
|
|
116
|
+
else if (this.activeChannel === 'g') this.activeChannel = 'b';
|
|
97
117
|
this.render(false);
|
|
98
118
|
return;
|
|
99
119
|
}
|
|
100
120
|
// Value Adjustment (Left/Right)
|
|
101
121
|
if (isLeft || isRight || isShiftLeft || isShiftRight) {
|
|
102
122
|
let change = 0;
|
|
103
|
-
if (isRight)
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
if (isShiftRight)
|
|
108
|
-
change = 10;
|
|
109
|
-
if (isShiftLeft)
|
|
110
|
-
change = -10;
|
|
123
|
+
if (isRight) change = 1;
|
|
124
|
+
if (isLeft) change = -1;
|
|
125
|
+
if (isShiftRight) change = 10;
|
|
126
|
+
if (isShiftLeft) change = -10;
|
|
111
127
|
const val = this.rgb[this.activeChannel] + change;
|
|
112
128
|
this.rgb[this.activeChannel] = Math.max(0, Math.min(255, val));
|
|
113
129
|
this.render(false);
|
|
@@ -115,12 +131,9 @@ class ColorPrompt extends base_1.Prompt {
|
|
|
115
131
|
}
|
|
116
132
|
// Tab to cycle channels
|
|
117
133
|
if (char === '\t') {
|
|
118
|
-
if (this.activeChannel === 'r')
|
|
119
|
-
|
|
120
|
-
else
|
|
121
|
-
this.activeChannel = 'b';
|
|
122
|
-
else
|
|
123
|
-
this.activeChannel = 'r';
|
|
134
|
+
if (this.activeChannel === 'r') this.activeChannel = 'g';
|
|
135
|
+
else if (this.activeChannel === 'g') this.activeChannel = 'b';
|
|
136
|
+
else this.activeChannel = 'r';
|
|
124
137
|
this.render(false);
|
|
125
138
|
return;
|
|
126
139
|
}
|
|
@@ -135,7 +148,7 @@ class ColorPrompt extends base_1.Prompt {
|
|
|
135
148
|
// If Ctrl is held, adjust by a larger step (fast adjust).
|
|
136
149
|
const fast = !!event.ctrl;
|
|
137
150
|
const step = fast ? 10 : 1;
|
|
138
|
-
const change = event.scroll === 'up' ? step :
|
|
151
|
+
const change = event.scroll === 'up' ? step : event.scroll === 'down' ? -step : 0;
|
|
139
152
|
if (change !== 0) {
|
|
140
153
|
const val = this.rgb[this.activeChannel] + change;
|
|
141
154
|
this.rgb[this.activeChannel] = Math.max(0, Math.min(255, val));
|
|
@@ -143,5 +156,10 @@ class ColorPrompt extends base_1.Prompt {
|
|
|
143
156
|
}
|
|
144
157
|
}
|
|
145
158
|
}
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
constructor(options){
|
|
160
|
+
super(options), _define_property(this, "rgb", void 0), _define_property(this, "activeChannel", 'r'), _define_property(this, "inputBuffer", '');
|
|
161
|
+
this.rgb = this.parseHex(options.initial || '#000000');
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/color.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { Prompt } from '../base';\nimport { theme } from '../theme';\nimport { ColorOptions, MouseEvent } from '../types';\n\ninterface RGB {\n r: number;\n g: number;\n b: number;\n}\n\nexport class ColorPrompt extends Prompt<string, ColorOptions> {\n private rgb: RGB;\n private activeChannel: 'r' | 'g' | 'b' = 'r';\n private inputBuffer: string = '';\n\n constructor(options: ColorOptions) {\n super(options);\n this.rgb = this.parseHex(options.initial || '#000000');\n }\n\n private parseHex(hex: string): RGB {\n const result = /^#?([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(hex);\n return result ? {\n r: parseInt(result[1], 16),\n g: parseInt(result[2], 16),\n b: parseInt(result[3], 16)\n } : { r: 0, g: 0, b: 0 };\n }\n\n private rgbToHex(r: number, g: number, b: number): string {\n return \"#\" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();\n }\n\n // Helper to format ANSI TrueColor background\n private getBgColorCode(r: number, g: number, b: number): string {\n return `\\x1b[48;2;${r};${g};${b}m`;\n }\n\n protected render(_firstRender: boolean): void {\n const { r, g, b } = this.rgb;\n const hex = this.rgbToHex(r, g, b);\n\n let output = `${theme.title}${this.options.message}${ANSI.RESET} `;\n output += `${ANSI.BOLD}${hex}${ANSI.RESET}\\n\\n`;\n\n // Preview Block\n if (this.capabilities.hasTrueColor) {\n const bg = this.getBgColorCode(r, g, b);\n const block = `${bg} ${ANSI.RESET}`; // 8 spaces\n output += ` ${block}\\n`;\n output += ` ${block}\\n`;\n output += ` ${block}\\n\\n`;\n } else {\n // Fallback for no true color?\n // Maybe just show text or use closest 256 color?\n // For now, simpler fallback:\n output += ` (Preview unavailable in this terminal)\\n\\n`;\n }\n\n // Sliders\n const channels: ('r' | 'g' | 'b')[] = ['r', 'g', 'b'];\n const labels = { r: 'Red ', g: 'Green', b: 'Blue ' };\n\n channels.forEach(ch => {\n const val = this.rgb[ch];\n const isActive = this.activeChannel === ch;\n\n // Render slider track\n // Width 20 chars for 0-255\n const width = 20;\n const pos = Math.floor((val / 255) * width);\n // Wait, '⚪' might be wide. using simpler char if needed. 'O' or ANSI reverse space.\n // Let's use standard chars.\n const trackSimple = '━'.repeat(pos) + (isActive ? '●' : '○') + '─'.repeat(width - pos);\n\n let line = `${labels[ch]}: ${val.toString().padStart(3)} [${trackSimple}]`;\n\n if (isActive) {\n line = `${theme.main}${ANSI.REVERSE} ${line} ${ANSI.RESET}`;\n } else {\n line = ` ${line} `;\n }\n output += line + '\\n';\n });\n\n output += `\\n${theme.muted}Arrows: Adjust/Switch | Shift+Arrows: Adjust fast | Enter: Submit${ANSI.RESET}`;\n\n this.renderFrame(output);\n }\n\n protected handleInput(char: string, _key: Buffer): void {\n const isUp = this.isUp(char);\n const isDown = this.isDown(char);\n const isLeft = this.isLeft(char);\n const isRight = this.isRight(char);\n\n // Detect Shift key for faster movement (generic check if possible, or mapping specific codes)\n // \\x1b[1;2C is Shift+Right usually. \\x1b[1;2D is Shift+Left.\n // It varies by terminal.\n const isShiftRight = char === '\\x1b[1;2C';\n const isShiftLeft = char === '\\x1b[1;2D';\n\n // Channel Switching (Up/Down)\n if (isUp) {\n if (this.activeChannel === 'g') this.activeChannel = 'r';\n else if (this.activeChannel === 'b') this.activeChannel = 'g';\n this.render(false);\n return;\n }\n if (isDown) {\n if (this.activeChannel === 'r') this.activeChannel = 'g';\n else if (this.activeChannel === 'g') this.activeChannel = 'b';\n this.render(false);\n return;\n }\n\n // Value Adjustment (Left/Right)\n if (isLeft || isRight || isShiftLeft || isShiftRight) {\n let change = 0;\n if (isRight) change = 1;\n if (isLeft) change = -1;\n if (isShiftRight) change = 10;\n if (isShiftLeft) change = -10;\n\n const val = this.rgb[this.activeChannel] + change;\n this.rgb[this.activeChannel] = Math.max(0, Math.min(255, val));\n this.render(false);\n return;\n }\n\n // Tab to cycle channels\n if (char === '\\t') {\n if (this.activeChannel === 'r') this.activeChannel = 'g';\n else if (this.activeChannel === 'g') this.activeChannel = 'b';\n else this.activeChannel = 'r';\n this.render(false);\n return;\n }\n\n if (char === '\\r' || char === '\\n') {\n this.submit(this.rgbToHex(this.rgb.r, this.rgb.g, this.rgb.b));\n return;\n }\n }\n\n protected handleMouse(event: MouseEvent): void {\n if (event.action === 'scroll') {\n // On scroll, adjust the currently active channel's value.\n // If Ctrl is held, adjust by a larger step (fast adjust).\n const fast = !!event.ctrl;\n const step = fast ? 10 : 1;\n const change = event.scroll === 'up' ? step : (event.scroll === 'down' ? -step : 0);\n if (change !== 0) {\n const val = this.rgb[this.activeChannel] + change;\n this.rgb[this.activeChannel] = Math.max(0, Math.min(255, val));\n this.render(false);\n }\n }\n }\n}\n"],"names":["ColorPrompt","Prompt","parseHex","hex","result","exec","r","parseInt","g","b","rgbToHex","toString","slice","toUpperCase","getBgColorCode","render","_firstRender","rgb","output","theme","title","options","message","ANSI","RESET","BOLD","capabilities","hasTrueColor","bg","block","channels","labels","forEach","ch","val","isActive","activeChannel","width","pos","Math","floor","trackSimple","repeat","line","padStart","main","REVERSE","muted","renderFrame","handleInput","char","_key","isUp","isDown","isLeft","isRight","isShiftRight","isShiftLeft","change","max","min","submit","handleMouse","event","action","fast","ctrl","step","scroll","inputBuffer","initial"],"mappings":";;;;+BAWaA;;;eAAAA;;;sBAXQ;sBACE;uBACD;;;;;;;;;;;;;;AASf,IAAA,AAAMA,cAAN,MAAMA,oBAAoBC,YAAM;IAU3BC,SA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;IAChD;AA6IJ"}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
constructor(options) {
|
|
10
|
-
super(options);
|
|
11
|
-
this.value = options.initial ?? true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ConfirmPrompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ConfirmPrompt;
|
|
12
9
|
}
|
|
10
|
+
});
|
|
11
|
+
const _ansi = require("../ansi");
|
|
12
|
+
const _base = require("../base");
|
|
13
|
+
const _theme = require("../theme");
|
|
14
|
+
let ConfirmPrompt = class ConfirmPrompt extends _base.Prompt {
|
|
13
15
|
render(_firstRender) {
|
|
14
16
|
// Prepare content
|
|
15
|
-
const hint = this.value ? `${
|
|
16
|
-
let output = `${
|
|
17
|
+
const hint = this.value ? `${_ansi.ANSI.BOLD}Yes${_ansi.ANSI.RESET}/no` : `yes/${_ansi.ANSI.BOLD}No${_ansi.ANSI.RESET}`;
|
|
18
|
+
let output = `${_theme.theme.success}?${_ansi.ANSI.RESET} ${_ansi.ANSI.BOLD}${_theme.theme.title}${this.options.message}${_ansi.ANSI.RESET} ${_theme.theme.muted}(${hint})${_ansi.ANSI.RESET} `;
|
|
17
19
|
const text = this.value ? 'Yes' : 'No';
|
|
18
|
-
output += `${
|
|
20
|
+
output += `${_theme.theme.main}${text}${_ansi.ANSI.RESET}`;
|
|
19
21
|
this.renderFrame(output);
|
|
20
22
|
}
|
|
21
23
|
handleInput(char) {
|
|
@@ -44,5 +46,10 @@ class ConfirmPrompt extends base_1.Prompt {
|
|
|
44
46
|
this.render(false);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
constructor(options){
|
|
50
|
+
super(options);
|
|
51
|
+
this.value = options.initial ?? true;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=confirm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/confirm.ts"],"sourcesContent":["import { ANSI } from '../ansi';\nimport { Prompt } from '../base';\nimport { theme } from '../theme';\nimport { ConfirmOptions, MouseEvent } from '../types';\n\n// --- Implementation: Confirm Prompt ---\nexport class ConfirmPrompt extends Prompt<boolean, ConfirmOptions> {\n constructor(options: ConfirmOptions) {\n super(options);\n this.value = options.initial ?? true;\n }\n\n protected render(_firstRender: boolean) {\n // Prepare content\n const hint = this.value ? `${ANSI.BOLD}Yes${ANSI.RESET}/no` : `yes/${ANSI.BOLD}No${ANSI.RESET}`;\n let output = `${theme.success}?${ANSI.RESET} ${ANSI.BOLD}${theme.title}${this.options.message}${ANSI.RESET} ${theme.muted}(${hint})${ANSI.RESET} `;\n const text = this.value ? 'Yes' : 'No';\n output += `${theme.main}${text}${ANSI.RESET}`;\n\n this.renderFrame(output);\n }\n\n protected handleInput(char: string) {\n const c = char.toLowerCase();\n if (c === '\\r' || c === '\\n') {\n this.submit(this.value);\n return;\n }\n if (c === 'y') { this.value = true; this.render(false); }\n if (c === 'n') { this.value = false; this.render(false); }\n\n // Allow left/right to toggle as well for better UX\n if (this.isLeft(char) || this.isRight(char)) {\n this.value = !this.value;\n this.render(false);\n }\n }\n\n protected handleMouse(event: MouseEvent) {\n if (event.action === 'scroll') {\n this.value = !this.value;\n this.render(false);\n }\n }\n}\n"],"names":["ConfirmPrompt","Prompt","render","_firstRender","hint","value","ANSI","BOLD","RESET","output","theme","success","title","options","message","muted","text","main","renderFrame","handleInput","char","c","toLowerCase","submit","isLeft","isRight","handleMouse","event","action","initial"],"mappings":";;;;+BAMaA;;;eAAAA;;;sBANQ;sBACE;uBACD;AAIf,IAAA,AAAMA,gBAA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AAC,IAAI,CAACA,KAAK;YACxB,IAAI,CAACH,MAAM,CAAC;QAChB;IACJ;IAEUwB,YAAYC,KAAiB,EAAE;QACrC,IAAIA,MAAMC,MAAM,KAAK,UAAU;YAC3B,IAAI,CAACvB,KAAK,GAAG,CAAC,IAAI,CAACA,KAAK;YACxB,IAAI,CAACH,MAAM,CAAC;QAChB;IACJ;IApCA,YAAYW,OAAuB,CAAE;QACjC,KAAK,CAACA;QACN,IAAI,CAACR,KAAK,GAAGQ,QAAQgB,OAAO,IAAI;IACpC;AAkCJ"}
|
|
@@ -1,88 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "connectionString", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return connectionString;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _select = require("./select");
|
|
12
|
+
const _text = require("./text");
|
|
13
|
+
const _number = require("./number");
|
|
14
|
+
const _confirm = require("./confirm");
|
|
15
|
+
const _file = require("./file");
|
|
16
|
+
const DEFAULT_PROTOCOLS = [
|
|
17
|
+
'postgres',
|
|
18
|
+
'mysql',
|
|
19
|
+
'mongodb',
|
|
20
|
+
'redis',
|
|
21
|
+
'amqp',
|
|
22
|
+
'sqlite'
|
|
23
|
+
];
|
|
10
24
|
const DEFAULT_PORTS = {
|
|
11
25
|
postgres: 5432,
|
|
12
26
|
mysql: 3306,
|
|
13
27
|
mongodb: 27017,
|
|
14
28
|
redis: 6379,
|
|
15
|
-
amqp: 5672
|
|
29
|
+
amqp: 5672
|
|
16
30
|
};
|
|
17
31
|
async function connectionString(options) {
|
|
18
32
|
const protocols = options.protocols || DEFAULT_PROTOCOLS;
|
|
19
|
-
const defaults = {
|
|
33
|
+
const defaults = {
|
|
34
|
+
...DEFAULT_PORTS,
|
|
35
|
+
...options.defaults
|
|
36
|
+
};
|
|
20
37
|
// 1. Protocol Selection
|
|
21
|
-
const protocol = await new
|
|
38
|
+
const protocol = await new _select.SelectPrompt({
|
|
22
39
|
message: options.message,
|
|
23
|
-
choices: protocols.map(p
|
|
40
|
+
choices: protocols.map((p)=>({
|
|
41
|
+
title: p,
|
|
42
|
+
value: p
|
|
43
|
+
}))
|
|
24
44
|
}).run();
|
|
25
|
-
const parts = {
|
|
45
|
+
const parts = {
|
|
46
|
+
protocol
|
|
47
|
+
};
|
|
26
48
|
let raw = '';
|
|
27
49
|
if (protocol === 'sqlite') {
|
|
28
50
|
// SQLite: File Path
|
|
29
|
-
const filePath = await new
|
|
30
|
-
message: 'Database file path'
|
|
51
|
+
const filePath = await new _file.FilePrompt({
|
|
52
|
+
message: 'Database file path'
|
|
31
53
|
}).run();
|
|
32
54
|
parts.filePath = filePath;
|
|
33
55
|
// Construct SQLite URI
|
|
34
56
|
raw = `sqlite://${filePath}`;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
57
|
+
} else {
|
|
37
58
|
// Network Database
|
|
38
59
|
// 2. Host
|
|
39
|
-
const host = await new
|
|
60
|
+
const host = await new _text.TextPrompt({
|
|
40
61
|
message: 'Host',
|
|
41
62
|
initial: 'localhost',
|
|
42
|
-
placeholder: 'localhost'
|
|
63
|
+
placeholder: 'localhost'
|
|
43
64
|
}).run();
|
|
44
65
|
parts.host = host;
|
|
45
66
|
// 3. Port
|
|
46
67
|
const defaultPort = defaults[protocol];
|
|
47
|
-
const port = await new
|
|
68
|
+
const port = await new _number.NumberPrompt({
|
|
48
69
|
message: 'Port',
|
|
49
|
-
initial: defaultPort
|
|
70
|
+
initial: defaultPort
|
|
50
71
|
}).run();
|
|
51
72
|
parts.port = port;
|
|
52
73
|
// 4. Auth
|
|
53
|
-
const hasAuth = await new
|
|
74
|
+
const hasAuth = await new _confirm.ConfirmPrompt({
|
|
54
75
|
message: 'Authentication required?',
|
|
55
|
-
initial: true
|
|
76
|
+
initial: true
|
|
56
77
|
}).run();
|
|
57
78
|
if (hasAuth) {
|
|
58
|
-
const user = await new
|
|
79
|
+
const user = await new _text.TextPrompt({
|
|
59
80
|
message: 'Username',
|
|
60
|
-
initial: 'root'
|
|
81
|
+
initial: 'root'
|
|
61
82
|
}).run();
|
|
62
83
|
parts.user = user;
|
|
63
84
|
// Use TextPrompt with empty mask for secret handling
|
|
64
|
-
const password = await new
|
|
85
|
+
const password = await new _text.TextPrompt({
|
|
65
86
|
message: 'Password',
|
|
66
|
-
mask: '*'
|
|
87
|
+
mask: '*'
|
|
67
88
|
}).run();
|
|
68
89
|
parts.password = password;
|
|
69
90
|
}
|
|
70
91
|
// 5. Database
|
|
71
|
-
const database = await new
|
|
72
|
-
message: 'Database name'
|
|
92
|
+
const database = await new _text.TextPrompt({
|
|
93
|
+
message: 'Database name'
|
|
73
94
|
}).run();
|
|
74
95
|
parts.database = database;
|
|
75
96
|
// Construct URL
|
|
76
97
|
try {
|
|
77
98
|
// Use URL object for safe construction and encoding
|
|
78
99
|
const u = new URL(`${protocol}://${host}:${port}/${database}`);
|
|
79
|
-
if (parts.user)
|
|
80
|
-
|
|
81
|
-
if (parts.password)
|
|
82
|
-
u.password = parts.password;
|
|
100
|
+
if (parts.user) u.username = parts.user;
|
|
101
|
+
if (parts.password) u.password = parts.password;
|
|
83
102
|
raw = u.toString();
|
|
84
|
-
}
|
|
85
|
-
catch (_e) {
|
|
103
|
+
} catch (_e) {
|
|
86
104
|
// Fallback manual construction with encoding
|
|
87
105
|
const userEncoded = parts.user ? encodeURIComponent(parts.user) : '';
|
|
88
106
|
const passEncoded = parts.password ? encodeURIComponent(parts.password) : '';
|
|
@@ -93,5 +111,10 @@ async function connectionString(options) {
|
|
|
93
111
|
raw = `${protocol}://${authPart}${host}:${port}/${parts.database}`;
|
|
94
112
|
}
|
|
95
113
|
}
|
|
96
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
raw,
|
|
116
|
+
parts
|
|
117
|
+
};
|
|
97
118
|
}
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=connection-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/prompts/connection-string.ts"],"sourcesContent":["import { SelectPrompt } from './select';\nimport { TextPrompt } from './text';\nimport { NumberPrompt } from './number';\nimport { ConfirmPrompt } from './confirm';\nimport { FilePrompt } from './file';\n\nexport interface ConnectionStringOptions {\n message: string;\n protocols?: string[];\n defaults?: Record<string, number>;\n}\n\nexport interface ConnectionStringResult {\n raw: string;\n parts: {\n protocol: string;\n host?: string;\n port?: number;\n user?: string;\n password?: string;\n database?: string;\n filePath?: string;\n };\n}\n\nconst DEFAULT_PROTOCOLS = ['postgres', 'mysql', 'mongodb', 'redis', 'amqp', 'sqlite'];\n\nconst DEFAULT_PORTS: Record<string, number> = {\n postgres: 5432,\n mysql: 3306,\n mongodb: 27017,\n redis: 6379,\n amqp: 5672,\n};\n\nexport async function connectionString(options: ConnectionStringOptions): Promise<ConnectionStringResult> {\n const protocols = options.protocols || DEFAULT_PROTOCOLS;\n const defaults = { ...DEFAULT_PORTS, ...options.defaults };\n\n // 1. Protocol Selection\n const protocol = await new SelectPrompt({\n message: options.message,\n choices: protocols.map(p => ({ title: p, value: p })),\n }).run();\n\n const parts: ConnectionStringResult['parts'] = { protocol };\n let raw = '';\n\n if (protocol === 'sqlite') {\n // SQLite: File Path\n const filePath = await new FilePrompt({\n message: 'Database file path',\n }).run();\n parts.filePath = filePath;\n // Construct SQLite URI\n raw = `sqlite://${filePath}`;\n } else {\n // Network Database\n // 2. Host\n const host = await new TextPrompt({\n message: 'Host',\n initial: 'localhost',\n placeholder: 'localhost',\n }).run();\n parts.host = host;\n\n // 3. Port\n const defaultPort = defaults[protocol];\n const port = await new NumberPrompt({\n message: 'Port',\n initial: defaultPort,\n }).run();\n parts.port = port;\n\n // 4. Auth\n const hasAuth = await new ConfirmPrompt({\n message: 'Authentication required?',\n initial: true,\n }).run();\n\n if (hasAuth) {\n const user = await new TextPrompt({\n message: 'Username',\n initial: 'root', // Common default\n }).run();\n parts.user = user;\n\n // Use TextPrompt with empty mask for secret handling\n const password = await new TextPrompt({\n message: 'Password',\n mask: '*', // Mask with asterisks\n }).run();\n parts.password = password;\n }\n\n // 5. Database\n const database = await new TextPrompt({\n message: 'Database name',\n }).run();\n parts.database = database;\n\n // Construct URL\n try {\n // Use URL object for safe construction and encoding\n const u = new URL(`${protocol}://${host}:${port}/${database}`);\n if (parts.user) u.username = parts.user;\n if (parts.password) u.password = parts.password;\n raw = u.toString();\n } catch (_e) {\n // Fallback manual construction with encoding\n const userEncoded = parts.user ? encodeURIComponent(parts.user) : '';\n const passEncoded = parts.password ? encodeURIComponent(parts.password) : '';\n let authPart = '';\n if (userEncoded || passEncoded) {\n authPart = `${userEncoded}:${passEncoded}@`;\n }\n raw = `${protocol}://${authPart}${host}:${port}/${parts.database}`;\n }\n }\n\n return { raw, parts };\n}\n"],"names":["connectionString","DEFAULT_PROTOCOLS","DEFAULT_PORTS","postgres","mysql","mongodb","redis","amqp","options","protocols","defaults","protocol","SelectPrompt","message","choices","map","p","title","value","run","parts","raw","filePath","FilePrompt","host","TextPrompt","initial","placeholder","defaultPort","port","NumberPrompt","hasAuth","ConfirmPrompt","user","password","mask","database","u","URL","username","toString","_e","userEncoded","encodeURIComponent","passEncoded","authPart"],"mappings":";;;;+BAmCsBA;;;eAAAA;;;wBAnCO;sBACF;wBACE;yBACC;sBACH;AAqB3B,MAAMC,oBAAoB;IAAC;IAAY;IAAS;IAAW;IAAS;IAAQ;CAAS;AAErF,MAAMC,gBAAwC;IAC1CC,UAAU;IACVC,OAAO;IACPC,SAAS;IACTC,OAAO;IACPC,MAAM;AACV;AAEO,eAAeP,iBAAiBQ,OAAgC;IACnE,MAAMC,YAAYD,QAAQC,SAAS,IAAIR;IACvC,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