@lemmo-lab/tokens-cli 2.1.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.
@@ -0,0 +1,67 @@
1
+ import readline from 'node:readline/promises';
2
+ import { stdin as input, stdout as output } from 'node:process';
3
+
4
+ export async function createPromptSession() {
5
+ const rl = readline.createInterface({ input, output });
6
+
7
+ return {
8
+ async askText(question, defaultValue = '') {
9
+ const promptStr = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
10
+ const answer = await rl.question(promptStr);
11
+ return answer.trim() || defaultValue;
12
+ },
13
+
14
+ async askConfirm(question, defaultYes = true) {
15
+ const hint = defaultYes ? '(Y/n)' : '(y/N)';
16
+ const answer = await rl.question(`${question} ${hint} `);
17
+ const cleaned = answer.trim().toLowerCase();
18
+ if (!cleaned) return defaultYes;
19
+ return cleaned === 'y' || cleaned === 'yes';
20
+ },
21
+
22
+ async askChoice(question, options, defaultIndex = 0) {
23
+ console.log(`\n${question}`);
24
+ options.forEach((opt, idx) => {
25
+ const marker = idx === defaultIndex ? '➔' : ' ';
26
+ console.log(` ${marker} ${idx + 1}) ${opt.label || opt}`);
27
+ });
28
+ const answer = await rl.question(`Select [1-${options.length}] (default: ${defaultIndex + 1}): `);
29
+ const num = parseInt(answer.trim(), 10);
30
+ if (isNaN(num) || num < 1 || num > options.length) {
31
+ return options[defaultIndex].value !== undefined ? options[defaultIndex].value : options[defaultIndex];
32
+ }
33
+ const sel = options[num - 1];
34
+ return sel.value !== undefined ? sel.value : sel;
35
+ },
36
+
37
+ async askMultiChoice(question, options, defaultSelectedIndices = []) {
38
+ console.log(`\n${question} (enter comma-separated numbers, e.g. 1,2 or hit enter for default):`);
39
+ options.forEach((opt, idx) => {
40
+ const isDef = defaultSelectedIndices.includes(idx);
41
+ const marker = isDef ? '✓' : ' ';
42
+ console.log(` [${marker}] ${idx + 1}) ${opt.label || opt}`);
43
+ });
44
+
45
+ const answer = await rl.question(`Select numbers (default: ${defaultSelectedIndices.map(i => i + 1).join(',')}): `);
46
+ const cleaned = answer.trim();
47
+ if (!cleaned) {
48
+ return defaultSelectedIndices.map(i => options[i].value !== undefined ? options[i].value : options[i]);
49
+ }
50
+
51
+ const indices = cleaned
52
+ .split(',')
53
+ .map(s => parseInt(s.trim(), 10) - 1)
54
+ .filter(i => !isNaN(i) && i >= 0 && i < options.length);
55
+
56
+ if (indices.length === 0) {
57
+ return defaultSelectedIndices.map(i => options[i].value !== undefined ? options[i].value : options[i]);
58
+ }
59
+
60
+ return indices.map(i => options[i].value !== undefined ? options[i].value : options[i]);
61
+ },
62
+
63
+ close() {
64
+ rl.close();
65
+ }
66
+ };
67
+ }