mepcli 1.4.0 → 2.0.0-beta.2
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 +43 -12
- 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 -322
- 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/{pipeline.js → src/pipeline.js} +120 -93
- 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 +15 -16
- 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 -90
- 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
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
<p align="center">
|
|
5
5
|
<sub>(Mep <a href="examples/basic-prompts.ts">Basic Prompts</a>)</a></sub>
|
|
6
|
-
<img src="https://raw.githubusercontent.com/CodeTease/mep/refs/heads/
|
|
6
|
+
<img src="https://raw.githubusercontent.com/CodeTease/mep/refs/heads/main/media/basic.gif" alt="Enquirer Survey Prompt" width="750">
|
|
7
7
|
|
|
8
8
|
**Mep** is a lightweight and zero-dependency library for creating interactive command-line prompts in Node.js. It focuses on simplicity, modern design, and robust input handling.
|
|
9
9
|
|
|
@@ -25,12 +25,21 @@ For comprehensive guides, API references, and advanced usage, please visit the *
|
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
27
27
|
|
|
28
|
+
Via NPM:
|
|
28
29
|
```sh
|
|
29
30
|
npm install mepcli
|
|
30
|
-
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Via Yarn:
|
|
34
|
+
```sh
|
|
31
35
|
yarn add mepcli
|
|
32
36
|
```
|
|
33
37
|
|
|
38
|
+
Via Bun:
|
|
39
|
+
```sh
|
|
40
|
+
bun add mepcli
|
|
41
|
+
```
|
|
42
|
+
|
|
34
43
|
## Quick Start
|
|
35
44
|
|
|
36
45
|
```typescript
|
|
@@ -206,20 +215,42 @@ tasks.success('download', 'Downloaded');
|
|
|
206
215
|
tasks.stop();
|
|
207
216
|
```
|
|
208
217
|
|
|
209
|
-
## Pipeline (Workflow Engine)
|
|
218
|
+
## Pipeline (Workflow Engine)
|
|
210
219
|
|
|
211
|
-
|
|
220
|
+
Pipelines provide a powerful, sequential workflow engine. Based on the philosophy of **Enter-and-Forget (EAF)**, **Zero-Dependency**, and **Method Chaining**, Pipelines allow you to chain actions, prompts, and tasks sequentially, accumulating their results into a Context object.
|
|
212
221
|
|
|
213
222
|
```typescript
|
|
214
|
-
|
|
215
|
-
|
|
223
|
+
import { MepCLI, Pipeline } from 'mepcli';
|
|
224
|
+
import { z } from 'zod';
|
|
225
|
+
|
|
226
|
+
interface Context {
|
|
227
|
+
name: string;
|
|
228
|
+
age: number;
|
|
229
|
+
email?: string;
|
|
230
|
+
parentalConsent?: boolean;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const result = await new Pipeline<Context>()
|
|
234
|
+
.step('name', async () => {
|
|
235
|
+
return await MepCLI.text({ message: 'What is your name?' });
|
|
236
|
+
}, {
|
|
237
|
+
validate: (val) => val.length > 0 || 'Name is required'
|
|
238
|
+
})
|
|
239
|
+
.step('age', async () => {
|
|
240
|
+
return await MepCLI.number({ message: 'How old are you?' });
|
|
241
|
+
}, {
|
|
242
|
+
transform: (val) => Number(val),
|
|
243
|
+
validate: z.number().min(0, "Age must be positive")
|
|
244
|
+
})
|
|
216
245
|
.stepIf(
|
|
217
|
-
(ctx) => ctx.
|
|
218
|
-
'
|
|
219
|
-
() =>
|
|
220
|
-
message: '
|
|
221
|
-
|
|
222
|
-
|
|
246
|
+
(ctx) => ctx.age < 18,
|
|
247
|
+
'parentalConsent',
|
|
248
|
+
async () => {
|
|
249
|
+
return await MepCLI.confirm({ message: 'Do you have parental consent?' });
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
validate: (val) => val === true || 'Parental consent is required'
|
|
253
|
+
}
|
|
223
254
|
)
|
|
224
255
|
.run();
|
|
225
256
|
```
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* ANSI Escape Codes
|
|
4
3
|
* Manual definitions to maintain zero-dependency status.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", {
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
*/ "use strict";
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "ANSI", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function() {
|
|
11
|
+
return ANSI;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const ANSI = {
|
|
9
15
|
RESET: '\x1b[0m',
|
|
10
16
|
BOLD: '\x1b[1m',
|
|
11
17
|
DIM: '\x1b[2m',
|
|
@@ -28,9 +34,9 @@ exports.ANSI = {
|
|
|
28
34
|
BG_GREEN: '\x1b[42m',
|
|
29
35
|
BG_RED: '\x1b[41m',
|
|
30
36
|
// Cursor & Erasing
|
|
31
|
-
ERASE_LINE: '\x1b[2K',
|
|
32
|
-
ERASE_DOWN: '\x1b[J',
|
|
33
|
-
CURSOR_LEFT: '\x1b[1000D',
|
|
37
|
+
ERASE_LINE: '\x1b[2K',
|
|
38
|
+
ERASE_DOWN: '\x1b[J',
|
|
39
|
+
CURSOR_LEFT: '\x1b[1000D',
|
|
34
40
|
HIDE_CURSOR: '\x1b[?25l',
|
|
35
41
|
SHOW_CURSOR: '\x1b[?25h',
|
|
36
42
|
UP: '\x1b[A',
|
|
@@ -38,5 +44,7 @@ exports.ANSI = {
|
|
|
38
44
|
// Mouse Tracking (SGR Protocol)
|
|
39
45
|
SET_ANY_EVENT_MOUSE: '\x1b[?1003h',
|
|
40
46
|
SET_SGR_EXT_MODE_MOUSE: '\x1b[?1006h',
|
|
41
|
-
DISABLE_MOUSE: '\x1b[?1003l\x1b[?1006l'
|
|
47
|
+
DISABLE_MOUSE: '\x1b[?1003l\x1b[?1006l'
|
|
42
48
|
};
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=ansi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/ansi.ts"],"sourcesContent":["/**\n * ANSI Escape Codes\n * Manual definitions to maintain zero-dependency status.\n */\n\nexport const ANSI = {\n RESET: '\\x1b[0m',\n BOLD: '\\x1b[1m',\n DIM: '\\x1b[2m',\n ITALIC: '\\x1b[3m',\n UNDERLINE: '\\x1b[4m',\n REVERSE: '\\x1b[7m',\n\n // Colors\n FG_GREEN: '\\x1b[32m',\n FG_CYAN: '\\x1b[36m',\n FG_YELLOW: '\\x1b[33m',\n FG_RED: '\\x1b[31m',\n FG_GRAY: '\\x1b[90m',\n FG_WHITE: '\\x1b[37m',\n FG_BLUE: '\\x1b[34m',\n FG_MAGENTA: '\\x1b[35m',\n FG_BLACK: '\\x1b[30m',\n\n BG_YELLOW: '\\x1b[43m',\n BG_BLUE: '\\x1b[44m',\n BG_CYAN: '\\x1b[46m',\n BG_GREEN: '\\x1b[42m',\n BG_RED: '\\x1b[41m',\n\n // Cursor & Erasing\n ERASE_LINE: '\\x1b[2K', // Clear current line\n ERASE_DOWN: '\\x1b[J', // Clear from cursor to end of screen\n CURSOR_LEFT: '\\x1b[1000D', // Move cursor to start of line\n HIDE_CURSOR: '\\x1b[?25l',\n SHOW_CURSOR: '\\x1b[?25h',\n UP: '\\x1b[A',\n DOWN: '\\x1b[B',\n\n // Mouse Tracking (SGR Protocol)\n SET_ANY_EVENT_MOUSE: '\\x1b[?1003h',\n SET_SGR_EXT_MODE_MOUSE: '\\x1b[?1006h',\n DISABLE_MOUSE: '\\x1b[?1003l\\x1b[?1006l',\n};\n"],"names":["ANSI","RESET","BOLD","DIM","ITALIC","UNDERLINE","REVERSE","FG_GREEN","FG_CYAN","FG_YELLOW","FG_RED","FG_GRAY","FG_WHITE","FG_BLUE","FG_MAGENTA","FG_BLACK","BG_YELLOW","BG_BLUE","BG_CYAN","BG_GREEN","BG_RED","ERASE_LINE","ERASE_DOWN","CURSOR_LEFT","HIDE_CURSOR","SHOW_CURSOR","UP","DOWN","SET_ANY_EVENT_MOUSE","SET_SGR_EXT_MODE_MOUSE","DISABLE_MOUSE"],"mappings":"AAAA;;;CAGC;;;;+BAEYA;;;eAAAA;;;AAAN,MAAMA,OAAO;IAChBC,OAAO;IACPC,MAAM;IACNC,KAAK;IACLC,QAAQ;IACRC,WAAW;IACXC,SAAS;IAET,SAAS;IACTC,UAAU;IACVC,SAAS;IACTC,WAAW;IACXC,QAAQ;IACRC,SAAS;IACTC,UAAU;IACVC,SAAS;IACTC,YAAY;IACZC,UAAU;IAEVC,WAAW;IACXC,SAAS;IACTC,SAAS;IACTC,UAAU;IACVC,QAAQ;IAER,mBAAmB;IACnBC,YAAY;IACZC,YAAY;IACZC,aAAa;IACbC,aAAa;IACbC,aAAa;IACbC,IAAI;IACJC,MAAM;IAEN,gCAAgC;IAChCC,qBAAqB;IACrBC,wBAAwB;IACxBC,eAAe;AACnB"}
|
|
@@ -1,54 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Implements a Robust Linear Scan Diffing Engine.
|
|
10
|
-
*/
|
|
11
|
-
class Prompt {
|
|
12
|
-
constructor(options) {
|
|
13
|
-
this.lastRenderLines = [];
|
|
14
|
-
this.lastRenderHeight = 0;
|
|
15
|
-
this.options = options;
|
|
16
|
-
this.stdin = process.stdin;
|
|
17
|
-
this.stdout = process.stdout;
|
|
18
|
-
this._inputParser = new input_1.InputParser();
|
|
19
|
-
this.capabilities = (0, utils_1.detectCapabilities)();
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Prompt", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Prompt;
|
|
20
9
|
}
|
|
10
|
+
});
|
|
11
|
+
const _ansi = require("./ansi");
|
|
12
|
+
const _input = require("./input");
|
|
13
|
+
const _utils = require("./utils");
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
27
|
+
let Prompt = class Prompt {
|
|
21
28
|
/**
|
|
22
29
|
* Checks if running on Windows and logs a warning message once per component type.
|
|
23
30
|
* Call this in the constructor of problematic prompts.
|
|
24
|
-
*/
|
|
25
|
-
checkWindowsAttention() {
|
|
31
|
+
*/ checkWindowsAttention() {
|
|
26
32
|
const componentName = this.constructor.name;
|
|
27
33
|
// Check platform and if already warned
|
|
28
34
|
if (process.platform === 'win32' && !Prompt.warnedComponents.has(componentName)) {
|
|
29
|
-
console.warn(`${
|
|
30
|
-
`Press 'Enter' if unresponsive.`);
|
|
35
|
+
console.warn(`${_ansi.ANSI.FG_YELLOW}Warning:${_ansi.ANSI.RESET} ${componentName} may hang on Windows TTY after multiple cycles. ` + `Press 'Enter' if unresponsive.`);
|
|
31
36
|
Prompt.warnedComponents.add(componentName);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Warn about experimental prompts.
|
|
36
41
|
* Call this in the constructor of experimental prompts.
|
|
37
|
-
*/
|
|
38
|
-
warnExperimental() {
|
|
42
|
+
*/ warnExperimental() {
|
|
39
43
|
const componentName = this.constructor.name;
|
|
40
44
|
if (!Prompt.warnedComponents.has(componentName)) {
|
|
41
|
-
console.warn(`${
|
|
42
|
-
`Use with caution.`);
|
|
45
|
+
console.warn(`${_ansi.ANSI.FG_YELLOW}Warning:${_ansi.ANSI.RESET} ${componentName} is an experimental prompt and may have bugs or unexpected behavior. ` + `Use with caution.`);
|
|
43
46
|
Prompt.warnedComponents.add(componentName);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
handleMouse(_event) {
|
|
49
|
+
handleMouse(_event) {}
|
|
47
50
|
print(text) {
|
|
48
51
|
this.stdout.write(text);
|
|
49
52
|
}
|
|
50
53
|
run() {
|
|
51
|
-
return new Promise((resolve, reject)
|
|
54
|
+
return new Promise((resolve, reject)=>{
|
|
52
55
|
this._resolve = resolve;
|
|
53
56
|
this._reject = reject;
|
|
54
57
|
if (typeof this.stdin.setRawMode === 'function') {
|
|
@@ -58,26 +61,25 @@ class Prompt {
|
|
|
58
61
|
this.stdin.setEncoding('utf8');
|
|
59
62
|
const shouldEnableMouse = this.options.mouse !== false && this.capabilities.hasMouse;
|
|
60
63
|
if (shouldEnableMouse) {
|
|
61
|
-
this.print(
|
|
64
|
+
this.print(_ansi.ANSI.SET_ANY_EVENT_MOUSE + _ansi.ANSI.SET_SGR_EXT_MODE_MOUSE);
|
|
62
65
|
}
|
|
63
|
-
this.print(
|
|
66
|
+
this.print(_ansi.ANSI.HIDE_CURSOR);
|
|
64
67
|
// Initial render
|
|
65
68
|
this.render(true);
|
|
66
|
-
this._onKeyHandler = (char, buffer)
|
|
67
|
-
if (char === '\u0003') {
|
|
69
|
+
this._onKeyHandler = (char, buffer)=>{
|
|
70
|
+
if (char === '\u0003') {
|
|
68
71
|
this.cleanup();
|
|
69
|
-
this.print(
|
|
70
|
-
if (this._reject)
|
|
71
|
-
this._reject(new Error('User force closed'));
|
|
72
|
+
this.print(_ansi.ANSI.SHOW_CURSOR + '\n');
|
|
73
|
+
if (this._reject) this._reject(new Error('User force closed'));
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
this.handleInput(char, buffer);
|
|
75
77
|
};
|
|
76
78
|
this._inputParser.on('keypress', this._onKeyHandler);
|
|
77
|
-
this._inputParser.on('mouse', (event)
|
|
79
|
+
this._inputParser.on('mouse', (event)=>{
|
|
78
80
|
this.handleMouse(event);
|
|
79
81
|
});
|
|
80
|
-
this._onDataHandler = (buffer)
|
|
82
|
+
this._onDataHandler = (buffer)=>{
|
|
81
83
|
this._inputParser.feed(buffer);
|
|
82
84
|
};
|
|
83
85
|
this.stdin.on('data', this._onDataHandler);
|
|
@@ -86,8 +88,7 @@ class Prompt {
|
|
|
86
88
|
/**
|
|
87
89
|
* Pauses the input stream and removes listeners.
|
|
88
90
|
* Useful for yielding control to child processes.
|
|
89
|
-
*/
|
|
90
|
-
pauseInput() {
|
|
91
|
+
*/ pauseInput() {
|
|
91
92
|
if (this._onDataHandler) {
|
|
92
93
|
this.stdin.removeListener('data', this._onDataHandler);
|
|
93
94
|
}
|
|
@@ -98,8 +99,7 @@ class Prompt {
|
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
101
|
* Resumes the input stream and re-attaches listeners.
|
|
101
|
-
*/
|
|
102
|
-
resumeInput() {
|
|
102
|
+
*/ resumeInput() {
|
|
103
103
|
if (typeof this.stdin.setRawMode === 'function') {
|
|
104
104
|
this.stdin.setRawMode(true);
|
|
105
105
|
}
|
|
@@ -115,34 +115,31 @@ class Prompt {
|
|
|
115
115
|
if (this._onKeyHandler) {
|
|
116
116
|
this._inputParser.removeListener('keypress', this._onKeyHandler);
|
|
117
117
|
}
|
|
118
|
-
this.print(
|
|
118
|
+
this.print(_ansi.ANSI.DISABLE_MOUSE);
|
|
119
119
|
if (typeof this.stdin.setRawMode === 'function') {
|
|
120
120
|
this.stdin.setRawMode(false);
|
|
121
121
|
}
|
|
122
122
|
this.stdin.pause();
|
|
123
|
-
this.print(
|
|
123
|
+
this.print(_ansi.ANSI.SHOW_CURSOR);
|
|
124
124
|
}
|
|
125
125
|
submit(result) {
|
|
126
126
|
this.cleanup();
|
|
127
127
|
this.print('\n');
|
|
128
|
-
if (this._resolve)
|
|
129
|
-
this._resolve(result);
|
|
128
|
+
if (this._resolve) this._resolve(result);
|
|
130
129
|
}
|
|
131
130
|
cancel(reason) {
|
|
132
131
|
this.cleanup();
|
|
133
132
|
this.print('\n');
|
|
134
|
-
if (this._reject)
|
|
135
|
-
this._reject(reason);
|
|
133
|
+
if (this._reject) this._reject(reason);
|
|
136
134
|
}
|
|
137
135
|
/**
|
|
138
136
|
* Renders the frame using a linear scan diffing algorithm.
|
|
139
137
|
* Prevents flicker and handles height changes (expand/collapse) robustly.
|
|
140
|
-
*/
|
|
141
|
-
renderFrame(content) {
|
|
138
|
+
*/ renderFrame(content) {
|
|
142
139
|
const width = this.stdout.columns || 80;
|
|
143
140
|
const rawLines = content.split('\n');
|
|
144
141
|
// Truncate lines to prevent wrapping artifacts
|
|
145
|
-
const newLines = rawLines.map(line
|
|
142
|
+
const newLines = rawLines.map((line)=>this.truncate(line, width));
|
|
146
143
|
// 1. First Render Case
|
|
147
144
|
if (this.lastRenderLines.length === 0) {
|
|
148
145
|
this.print(newLines.join('\n'));
|
|
@@ -157,7 +154,7 @@ class Prompt {
|
|
|
157
154
|
}
|
|
158
155
|
outputBuffer += '\r'; // Ensure column 0
|
|
159
156
|
// 3. Linear Scan & Update
|
|
160
|
-
for
|
|
157
|
+
for(let i = 0; i < newLines.length; i++){
|
|
161
158
|
const newLine = newLines[i];
|
|
162
159
|
// Logic for moving to the next line
|
|
163
160
|
if (i > 0) {
|
|
@@ -165,8 +162,7 @@ class Prompt {
|
|
|
165
162
|
// Moving within the previously existing area.
|
|
166
163
|
// Use 'Down' (B) to avoid scrolling/shifting existing content.
|
|
167
164
|
outputBuffer += '\x1b[B\r';
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
165
|
+
} else {
|
|
170
166
|
// Moving into NEW area (Append).
|
|
171
167
|
// Must use '\n' to create the new line.
|
|
172
168
|
outputBuffer += '\n';
|
|
@@ -177,10 +173,9 @@ class Prompt {
|
|
|
177
173
|
const oldLine = this.lastRenderLines[i];
|
|
178
174
|
if (newLine !== oldLine) {
|
|
179
175
|
// Overwrite existing line
|
|
180
|
-
outputBuffer +=
|
|
176
|
+
outputBuffer += _ansi.ANSI.ERASE_LINE + newLine;
|
|
181
177
|
}
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
178
|
+
} else {
|
|
184
179
|
// Print new line (we are already at start due to '\n' above)
|
|
185
180
|
outputBuffer += newLine;
|
|
186
181
|
}
|
|
@@ -190,7 +185,7 @@ class Prompt {
|
|
|
190
185
|
// Move down to the first obsolete line
|
|
191
186
|
outputBuffer += '\n';
|
|
192
187
|
// Clear everything below
|
|
193
|
-
outputBuffer +=
|
|
188
|
+
outputBuffer += _ansi.ANSI.ERASE_DOWN;
|
|
194
189
|
// Move back up to the last valid line to maintain cursor state consistency
|
|
195
190
|
outputBuffer += `\x1b[A`;
|
|
196
191
|
}
|
|
@@ -200,19 +195,18 @@ class Prompt {
|
|
|
200
195
|
this.lastRenderHeight = newLines.length;
|
|
201
196
|
}
|
|
202
197
|
stripAnsi(str) {
|
|
203
|
-
return (0,
|
|
198
|
+
return (0, _utils.stripAnsi)(str);
|
|
204
199
|
}
|
|
205
200
|
truncate(str, width) {
|
|
206
|
-
const visualWidth = (0,
|
|
201
|
+
const visualWidth = (0, _utils.stringWidth)(str);
|
|
207
202
|
if (visualWidth <= width) {
|
|
208
203
|
return str;
|
|
209
204
|
}
|
|
210
205
|
let currentWidth = 0;
|
|
211
206
|
let cutIndex = 0;
|
|
212
207
|
let inAnsi = false;
|
|
213
|
-
for
|
|
214
|
-
if (str[i] === '\x1b')
|
|
215
|
-
inAnsi = true;
|
|
208
|
+
for(let i = 0; i < str.length; i++){
|
|
209
|
+
if (str[i] === '\x1b') inAnsi = true;
|
|
216
210
|
if (!inAnsi) {
|
|
217
211
|
const code = str.charCodeAt(i);
|
|
218
212
|
const charWidth = code > 255 ? 2 : 1;
|
|
@@ -220,14 +214,12 @@ class Prompt {
|
|
|
220
214
|
break;
|
|
221
215
|
}
|
|
222
216
|
currentWidth += charWidth;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (str[i] === 'm' || (str[i] >= 'A' && str[i] <= 'Z'))
|
|
226
|
-
inAnsi = false;
|
|
217
|
+
} else {
|
|
218
|
+
if (str[i] === 'm' || str[i] >= 'A' && str[i] <= 'Z') inAnsi = false;
|
|
227
219
|
}
|
|
228
220
|
cutIndex = i + 1;
|
|
229
221
|
}
|
|
230
|
-
return str.substring(0, cutIndex) + '...' +
|
|
222
|
+
return str.substring(0, cutIndex) + '...' + _ansi.ANSI.RESET;
|
|
231
223
|
}
|
|
232
224
|
isUp(char) {
|
|
233
225
|
return char === '\u001b[A' || char === '\u001bOA';
|
|
@@ -241,6 +233,26 @@ class Prompt {
|
|
|
241
233
|
isLeft(char) {
|
|
242
234
|
return char === '\u001b[D' || char === '\u001bOD';
|
|
243
235
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
constructor(options){
|
|
237
|
+
_define_property(this, "options", void 0);
|
|
238
|
+
_define_property(this, "value", void 0);
|
|
239
|
+
_define_property(this, "stdin", void 0);
|
|
240
|
+
_define_property(this, "stdout", void 0);
|
|
241
|
+
_define_property(this, "_resolve", void 0);
|
|
242
|
+
_define_property(this, "_reject", void 0);
|
|
243
|
+
_define_property(this, "_inputParser", void 0);
|
|
244
|
+
_define_property(this, "_onKeyHandler", void 0);
|
|
245
|
+
_define_property(this, "_onDataHandler", void 0);
|
|
246
|
+
_define_property(this, "lastRenderLines", []);
|
|
247
|
+
_define_property(this, "lastRenderHeight", 0);
|
|
248
|
+
_define_property(this, "capabilities", void 0);
|
|
249
|
+
this.options = options;
|
|
250
|
+
this.stdin = process.stdin;
|
|
251
|
+
this.stdout = process.stdout;
|
|
252
|
+
this._inputParser = new _input.InputParser();
|
|
253
|
+
this.capabilities = (0, _utils.detectCapabilities)();
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
_define_property(Prompt, "warnedComponents", new Set());
|
|
257
|
+
|
|
258
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/base.ts"],"sourcesContent":["import { ANSI } from './ansi';\nimport { InputParser } from './input';\nimport { BaseOptions, MouseEvent } from './types';\nimport { detectCapabilities, stringWidth, stripAnsi } from './utils';\n\n/**\n * Abstract base class for all prompts.\n * Implements a Robust Linear Scan Diffing Engine.\n */\nexport abstract class Prompt<T, O> {\n protected options: O;\n protected value: any;\n protected stdin: NodeJS.ReadStream;\n protected stdout: NodeJS.WriteStream;\n private _resolve?: (value: T | PromiseLike<T>) => void;\n private _reject?: (reason?: any) => void;\n private _inputParser: InputParser;\n private _onKeyHandler?: (char: string, key: Buffer) => void;\n private _onDataHandler?: (chunk: Buffer) => void;\n private static warnedComponents = new Set<string>();\n\n protected lastRenderLines: string[] = [];\n protected lastRenderHeight: number = 0;\n\n protected capabilities: ReturnType<typeof detectCapabilities>;\n\n constructor(options: O) {\n this.options = options;\n this.stdin = process.stdin;\n this.stdout = process.stdout;\n this._inputParser = new InputParser();\n this.capabilities = detectCapabilities();\n }\n\n /**\n * Checks if running on Windows and logs a warning message once per component type.\n * Call this in the constructor of problematic prompts.\n */\n protected checkWindowsAttention() {\n const componentName = this.constructor.name;\n\n // Check platform and if already warned\n if (process.platform === 'win32' && !Prompt.warnedComponents.has(componentName)) {\n console.warn(\n `${ANSI.FG_YELLOW}Warning:${ANSI.RESET} ${componentName} may hang on Windows TTY after multiple cycles. ` +\n `Press 'Enter' if unresponsive.`\n );\n Prompt.warnedComponents.add(componentName);\n }\n }\n\n /**\n * Warn about experimental prompts.\n * Call this in the constructor of experimental prompts.\n */\n protected warnExperimental() {\n const componentName = this.constructor.name;\n\n if (!Prompt.warnedComponents.has(componentName)) {\n console.warn(\n `${ANSI.FG_YELLOW}Warning:${ANSI.RESET} ${componentName} is an experimental prompt and may have bugs or unexpected behavior. ` +\n `Use with caution.`\n );\n Prompt.warnedComponents.add(componentName);\n }\n }\n\n protected abstract render(firstRender: boolean): void;\n protected abstract handleInput(char: string, key: Buffer): void;\n protected handleMouse(_event: MouseEvent): void { }\n\n protected print(text: string) {\n this.stdout.write(text);\n }\n\n public run(): Promise<T> {\n return new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n\n if (typeof this.stdin.setRawMode === 'function') {\n this.stdin.setRawMode(true);\n }\n this.stdin.resume();\n this.stdin.setEncoding('utf8');\n\n const shouldEnableMouse = (this.options as BaseOptions).mouse !== false && this.capabilities.hasMouse;\n if (shouldEnableMouse) {\n this.print(ANSI.SET_ANY_EVENT_MOUSE + ANSI.SET_SGR_EXT_MODE_MOUSE);\n }\n\n this.print(ANSI.HIDE_CURSOR);\n\n // Initial render\n this.render(true);\n\n this._onKeyHandler = (char: string, buffer: Buffer) => {\n if (char === '\\u0003') { // Ctrl+C\n this.cleanup();\n this.print(ANSI.SHOW_CURSOR + '\\n');\n if (this._reject) this._reject(new Error('User force closed'));\n return;\n }\n this.handleInput(char, buffer);\n };\n\n this._inputParser.on('keypress', this._onKeyHandler);\n\n this._inputParser.on('mouse', (event: MouseEvent) => {\n this.handleMouse(event);\n });\n\n this._onDataHandler = (buffer: Buffer) => {\n this._inputParser.feed(buffer);\n };\n\n this.stdin.on('data', this._onDataHandler);\n });\n }\n\n /**\n * Pauses the input stream and removes listeners.\n * Useful for yielding control to child processes.\n */\n protected pauseInput() {\n if (this._onDataHandler) {\n this.stdin.removeListener('data', this._onDataHandler);\n }\n if (typeof this.stdin.setRawMode === 'function') {\n this.stdin.setRawMode(false);\n }\n this.stdin.pause();\n }\n\n /**\n * Resumes the input stream and re-attaches listeners.\n */\n protected resumeInput() {\n if (typeof this.stdin.setRawMode === 'function') {\n this.stdin.setRawMode(true);\n }\n this.stdin.resume();\n if (this._onDataHandler) {\n this.stdin.on('data', this._onDataHandler);\n }\n }\n\n protected cleanup() {\n if (this._onDataHandler) {\n this.stdin.removeListener('data', this._onDataHandler);\n }\n if (this._onKeyHandler) {\n this._inputParser.removeListener('keypress', this._onKeyHandler);\n }\n\n this.print(ANSI.DISABLE_MOUSE);\n\n if (typeof this.stdin.setRawMode === 'function') {\n this.stdin.setRawMode(false);\n }\n this.stdin.pause();\n this.print(ANSI.SHOW_CURSOR);\n }\n\n protected submit(result: T) {\n this.cleanup();\n this.print('\\n');\n if (this._resolve) this._resolve(result);\n }\n\n protected cancel(reason: any) {\n this.cleanup();\n this.print('\\n');\n if (this._reject) this._reject(reason);\n }\n\n /**\n * Renders the frame using a linear scan diffing algorithm.\n * Prevents flicker and handles height changes (expand/collapse) robustly.\n */\n protected renderFrame(content: string) {\n const width = this.stdout.columns || 80;\n const rawLines = content.split('\\n');\n\n // Truncate lines to prevent wrapping artifacts\n const newLines = rawLines.map(line => this.truncate(line, width));\n\n // 1. First Render Case\n if (this.lastRenderLines.length === 0) {\n this.print(newLines.join('\\n'));\n this.lastRenderLines = newLines;\n this.lastRenderHeight = newLines.length;\n return;\n }\n\n let outputBuffer = '';\n\n // 2. Return Cursor to the Top of the Prompt\n if (this.lastRenderHeight > 1) {\n outputBuffer += `\\x1b[${this.lastRenderHeight - 1}A`;\n }\n outputBuffer += '\\r'; // Ensure column 0\n\n // 3. Linear Scan & Update\n for (let i = 0; i < newLines.length; i++) {\n const newLine = newLines[i];\n\n // Logic for moving to the next line\n if (i > 0) {\n if (i < this.lastRenderLines.length) {\n // Moving within the previously existing area.\n // Use 'Down' (B) to avoid scrolling/shifting existing content.\n outputBuffer += '\\x1b[B\\r';\n } else {\n // Moving into NEW area (Append).\n // Must use '\\n' to create the new line.\n outputBuffer += '\\n';\n }\n }\n\n // Printing logic\n if (i < this.lastRenderLines.length) {\n const oldLine = this.lastRenderLines[i];\n if (newLine !== oldLine) {\n // Overwrite existing line\n outputBuffer += ANSI.ERASE_LINE + newLine;\n }\n } else {\n // Print new line (we are already at start due to '\\n' above)\n outputBuffer += newLine;\n }\n }\n\n // 4. Handle Shrinkage (Clear garbage below)\n if (newLines.length < this.lastRenderLines.length) {\n // Move down to the first obsolete line\n outputBuffer += '\\n';\n // Clear everything below\n outputBuffer += ANSI.ERASE_DOWN;\n // Move back up to the last valid line to maintain cursor state consistency\n outputBuffer += `\\x1b[A`;\n }\n\n this.print(outputBuffer);\n\n // Update State\n this.lastRenderLines = newLines;\n this.lastRenderHeight = newLines.length;\n }\n\n protected stripAnsi(str: string): string {\n return stripAnsi(str);\n }\n\n protected truncate(str: string, width: number): string {\n const visualWidth = stringWidth(str);\n if (visualWidth <= width) {\n return str;\n }\n\n let currentWidth = 0;\n let cutIndex = 0;\n let inAnsi = false;\n\n for (let i = 0; i < str.length; i++) {\n if (str[i] === '\\x1b') inAnsi = true;\n\n if (!inAnsi) {\n const code = str.charCodeAt(i);\n const charWidth = code > 255 ? 2 : 1;\n if (currentWidth + charWidth > width - 3) {\n break;\n }\n currentWidth += charWidth;\n } else {\n if (str[i] === 'm' || (str[i] >= 'A' && str[i] <= 'Z')) inAnsi = false;\n }\n cutIndex = i + 1;\n }\n\n return str.substring(0, cutIndex) + '...' + ANSI.RESET;\n }\n\n protected isUp(char: string): boolean {\n return char === '\\u001b[A' || char === '\\u001bOA';\n }\n protected isDown(char: string): boolean {\n return char === '\\u001b[B' || char === '\\u001bOB';\n }\n protected isRight(char: string): boolean {\n return char === '\\u001b[C' || char === '\\u001bOC';\n }\n protected isLeft(char: string): boolean {\n return char === '\\u001b[D' || char === '\\u001bOD';\n }\n}"],"names":["Prompt","checkWindowsAttention","componentName","name","process","platform","warnedComponents","has","console","warn","ANSI","FG_YELLOW","RESET","add","warnExperimental","handleMouse","_event","print","text","stdout","write","run","Promise","resolve","reject","_resolve","_reject","stdin","setRawMode","resume","setEncoding","shouldEnableMouse","options","mouse","capabilities","hasMouse","SET_ANY_EVENT_MOUSE","SET_SGR_EXT_MODE_MOUSE","HIDE_CURSOR","render","_onKeyHandler","char","buffer","cleanup","SHOW_CURSOR","Error","handleInput","_inputParser","on","event","_onDataHandler","feed","pauseInput","removeListener","pause","resumeInput","DISABLE_MOUSE","submit","result","cancel","reason","renderFrame","content","width","columns","rawLines","split","newLines","map","line","truncate","lastRenderLines","length","join","lastRenderHeight","outputBuffer","i","newLine","oldLine","ERASE_LINE","ERASE_DOWN","stripAnsi","str","visualWidth","stringWidth","currentWidth","cutIndex","inAnsi","code","charCodeAt","charWidth","substring","isUp","isDown","isRight","isLeft","value","InputParser","detectCapabilities","Set"],"mappings":";;;;+BASsBA;;;eAAAA;;;sBATD;uBACO;uBAE+B;;;;;;;;;;;;;;AAMpD,IAAA,AAAeA,SAAf,MAAeA;IAyBlB;;;KAGC,GACD,AAAUC,wBAAwB;QAC9B,MAAMC,gBAAgB,IAAI,CAAC,WAAW,CAACC,IAAI;QAE3C,uCAAuC;QACvC,IAAIC,QA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