@seamapi/cli 0.17.1 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/util/prompt.d.ts +16 -0
- package/lib/util/prompt.js +40 -0
- package/lib/util/prompt.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/lib/util/prompt.ts +43 -0
- package/src/lib/version.ts +1 -1
package/lib/util/prompt.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events';
|
|
2
|
+
import type { Key } from 'node:readline';
|
|
1
3
|
/**
|
|
2
4
|
* Whether the CLI can ask the user a question.
|
|
3
5
|
*
|
|
@@ -16,6 +18,20 @@ export interface PromptChoice<Value> {
|
|
|
16
18
|
value: Value;
|
|
17
19
|
hint?: string | undefined;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The arrow keypress an Emacs-style control keypress stands for, or
|
|
23
|
+
* undefined for any other key: ctrl-p is up and ctrl-n is down.
|
|
24
|
+
*/
|
|
25
|
+
export declare const arrowKeyFor: (key: Key | undefined) => Key | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Re-emit Emacs-style control keypresses as the arrow keys they stand for.
|
|
28
|
+
*
|
|
29
|
+
* Clack navigates on the readline key name, so a synthetic arrow keypress
|
|
30
|
+
* moves the cursor in every prompt kind. Its own alias table cannot express
|
|
31
|
+
* this: aliases match bare key names, unaware of ctrl, and are ignored by
|
|
32
|
+
* prompts that track typed input, such as autocomplete.
|
|
33
|
+
*/
|
|
34
|
+
export declare const emitArrowKeyAliases: (input: EventEmitter) => void;
|
|
19
35
|
export declare const promptText: (options: {
|
|
20
36
|
message: string;
|
|
21
37
|
placeholder?: string;
|
package/lib/util/prompt.js
CHANGED
|
@@ -19,6 +19,46 @@ const ensureInteractive = () => {
|
|
|
19
19
|
if (!canPrompt()) {
|
|
20
20
|
throw new NonInteractiveError('Cannot prompt without a terminal: pass the missing arguments, or pipe them in as JSON');
|
|
21
21
|
}
|
|
22
|
+
installArrowKeyAliases();
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The arrow keypress an Emacs-style control keypress stands for, or
|
|
26
|
+
* undefined for any other key: ctrl-p is up and ctrl-n is down.
|
|
27
|
+
*/
|
|
28
|
+
export const arrowKeyFor = (key) => {
|
|
29
|
+
if (key?.ctrl !== true || key.meta === true || key.shift === true) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const base = { ctrl: false, meta: false, shift: false };
|
|
33
|
+
if (key.name === 'p')
|
|
34
|
+
return { ...base, name: 'up', sequence: '\x1B[A' };
|
|
35
|
+
if (key.name === 'n')
|
|
36
|
+
return { ...base, name: 'down', sequence: '\x1B[B' };
|
|
37
|
+
return undefined;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Re-emit Emacs-style control keypresses as the arrow keys they stand for.
|
|
41
|
+
*
|
|
42
|
+
* Clack navigates on the readline key name, so a synthetic arrow keypress
|
|
43
|
+
* moves the cursor in every prompt kind. Its own alias table cannot express
|
|
44
|
+
* this: aliases match bare key names, unaware of ctrl, and are ignored by
|
|
45
|
+
* prompts that track typed input, such as autocomplete.
|
|
46
|
+
*/
|
|
47
|
+
export const emitArrowKeyAliases = (input) => {
|
|
48
|
+
input.on('keypress', (_char, key) => {
|
|
49
|
+
const arrowKey = arrowKeyFor(key);
|
|
50
|
+
if (arrowKey !== undefined)
|
|
51
|
+
input.emit('keypress', undefined, arrowKey);
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
let arrowKeyAliasesInstalled = false;
|
|
55
|
+
// Keypress events only flow while a prompt has stdin in raw mode, so the
|
|
56
|
+
// listener is inert the rest of the time and never holds the process open.
|
|
57
|
+
const installArrowKeyAliases = () => {
|
|
58
|
+
if (arrowKeyAliasesInstalled)
|
|
59
|
+
return;
|
|
60
|
+
arrowKeyAliasesInstalled = true;
|
|
61
|
+
emitArrowKeyAliases(process.stdin);
|
|
22
62
|
};
|
|
23
63
|
const unwrap = (value) => {
|
|
24
64
|
if (isCancel(value))
|
package/lib/util/prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/lib/util/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/lib/util/prompt.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,OAAO,EACP,QAAQ,EAER,MAAM,EACN,IAAI,GACL,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAEnD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAY,EAAE,CACrC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAA;AAE/D,8EAA8E;AAC9E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,WAAW,CAAC,CAAA;IACpB,CAAC;CACF;AAQD,MAAM,iBAAiB,GAAG,GAAS,EAAE;IACnC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,mBAAmB,CAC3B,uFAAuF,CACxF,CAAA;IACH,CAAC;IACD,sBAAsB,EAAE,CAAA;AAC1B,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAoB,EAAmB,EAAE;IACnE,IAAI,GAAG,EAAE,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAClE,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE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GAAG,CAAC,CAAC,CAAA;IAEpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAEnC,MAAM,UAAU,GAAG,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,IAAI,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE;SAC5D,WAAW,EAAE;SACb,IAAI,EAAE,CAAA;IACT,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;AACzD,CAAC,CAAA"}
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/package.json
CHANGED
package/src/lib/util/prompt.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { EventEmitter } from 'node:events'
|
|
2
|
+
import type { Key } from 'node:readline'
|
|
3
|
+
|
|
1
4
|
import {
|
|
2
5
|
autocomplete,
|
|
3
6
|
autocompleteMultiselect,
|
|
@@ -40,6 +43,46 @@ const ensureInteractive = (): void => {
|
|
|
40
43
|
'Cannot prompt without a terminal: pass the missing arguments, or pipe them in as JSON',
|
|
41
44
|
)
|
|
42
45
|
}
|
|
46
|
+
installArrowKeyAliases()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The arrow keypress an Emacs-style control keypress stands for, or
|
|
51
|
+
* undefined for any other key: ctrl-p is up and ctrl-n is down.
|
|
52
|
+
*/
|
|
53
|
+
export const arrowKeyFor = (key: Key | undefined): Key | undefined => {
|
|
54
|
+
if (key?.ctrl !== true || key.meta === true || key.shift === true) {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
const base = { ctrl: false, meta: false, shift: false }
|
|
58
|
+
if (key.name === 'p') return { ...base, name: 'up', sequence: '\x1B[A' }
|
|
59
|
+
if (key.name === 'n') return { ...base, name: 'down', sequence: '\x1B[B' }
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Re-emit Emacs-style control keypresses as the arrow keys they stand for.
|
|
65
|
+
*
|
|
66
|
+
* Clack navigates on the readline key name, so a synthetic arrow keypress
|
|
67
|
+
* moves the cursor in every prompt kind. Its own alias table cannot express
|
|
68
|
+
* this: aliases match bare key names, unaware of ctrl, and are ignored by
|
|
69
|
+
* prompts that track typed input, such as autocomplete.
|
|
70
|
+
*/
|
|
71
|
+
export const emitArrowKeyAliases = (input: EventEmitter): void => {
|
|
72
|
+
input.on('keypress', (_char, key: Key | undefined) => {
|
|
73
|
+
const arrowKey = arrowKeyFor(key)
|
|
74
|
+
if (arrowKey !== undefined) input.emit('keypress', undefined, arrowKey)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let arrowKeyAliasesInstalled = false
|
|
79
|
+
|
|
80
|
+
// Keypress events only flow while a prompt has stdin in raw mode, so the
|
|
81
|
+
// listener is inert the rest of the time and never holds the process open.
|
|
82
|
+
const installArrowKeyAliases = (): void => {
|
|
83
|
+
if (arrowKeyAliasesInstalled) return
|
|
84
|
+
arrowKeyAliasesInstalled = true
|
|
85
|
+
emitArrowKeyAliases(process.stdin)
|
|
43
86
|
}
|
|
44
87
|
|
|
45
88
|
const unwrap = <Value>(value: Value | symbol): Value => {
|
package/src/lib/version.ts
CHANGED