oh-langfuse 0.1.8 → 0.1.9
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/bin/cli.js +78 -41
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -260,7 +260,7 @@ async function askText(rl, label, { defaultValue = "", required = false } = {})
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
-
async function askYesNo(rl, label, { defaultValue = true } = {}) {
|
|
263
|
+
async function askYesNo(rl, label, { defaultValue = true } = {}) {
|
|
264
264
|
const hint = defaultValue ? "Y/n" : "y/N";
|
|
265
265
|
while (true) {
|
|
266
266
|
const answer = (await rl.question(`${paint(label, t.cyan)} ${paint(`(${hint})`, t.muted)} `)).trim().toLowerCase();
|
|
@@ -268,10 +268,47 @@ async function askYesNo(rl, label, { defaultValue = true } = {}) {
|
|
|
268
268
|
if (["y", "yes"].includes(answer)) return true;
|
|
269
269
|
if (["n", "no"].includes(answer)) return false;
|
|
270
270
|
console.log(paint("Please answer y or n.", t.red));
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function keySeq(raw, key = {}) {
|
|
275
|
+
return String(key.sequence ?? raw ?? "");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function isCtrlC(raw, key = {}) {
|
|
279
|
+
return Boolean(key.ctrl && key.name === "c") || keySeq(raw, key) === "\x03";
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function isEscape(raw, key = {}) {
|
|
283
|
+
const seq = keySeq(raw, key);
|
|
284
|
+
return key.name === "escape" || seq === "\x1b";
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function isUpKey(raw, key = {}) {
|
|
288
|
+
const seq = keySeq(raw, key);
|
|
289
|
+
return key.name === "up" || seq === "\x1b[A" || seq === "\x1bOA";
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function isDownKey(raw, key = {}) {
|
|
293
|
+
const seq = keySeq(raw, key);
|
|
294
|
+
return key.name === "down" || seq === "\x1b[B" || seq === "\x1bOB";
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function isEnterKey(raw, key = {}) {
|
|
298
|
+
const seq = keySeq(raw, key);
|
|
299
|
+
return key.name === "return" || key.name === "enter" || seq === "\r" || seq === "\n";
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function isSpaceKey(raw, key = {}) {
|
|
303
|
+
return key.name === "space" || keySeq(raw, key) === " ";
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function numberKey(raw, key = {}) {
|
|
307
|
+
const seq = keySeq(raw, key);
|
|
308
|
+
return /^[1-9]$/.test(seq) ? Number.parseInt(seq, 10) : Number.NaN;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function renderChoiceScreen(label, choices, index, options = {}) {
|
|
275
312
|
clearScreen();
|
|
276
313
|
renderBrand(options);
|
|
277
314
|
console.log("");
|
|
@@ -308,23 +345,23 @@ async function askChoice(rl, label, choices, options = {}) {
|
|
|
308
345
|
resolve(value);
|
|
309
346
|
}
|
|
310
347
|
|
|
311
|
-
function onKeypress(
|
|
312
|
-
if (
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
if (
|
|
325
|
-
const num =
|
|
326
|
-
if (Number.isInteger(num) && choices[num - 1]) return cleanup(choices[num - 1].value);
|
|
327
|
-
}
|
|
348
|
+
function onKeypress(raw, key = {}) {
|
|
349
|
+
if (isCtrlC(raw, key)) return cleanup("exit");
|
|
350
|
+
if (isUpKey(raw, key)) {
|
|
351
|
+
index = (index - 1 + choices.length) % choices.length;
|
|
352
|
+
renderChoiceScreen(label, choices, index, options);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (isDownKey(raw, key)) {
|
|
356
|
+
index = (index + 1) % choices.length;
|
|
357
|
+
renderChoiceScreen(label, choices, index, options);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (keySeq(raw, key).toLowerCase() === "q" || isEscape(raw, key)) return cleanup("exit");
|
|
361
|
+
if (isEnterKey(raw, key)) return cleanup(choices[index].value);
|
|
362
|
+
const num = numberKey(raw, key);
|
|
363
|
+
if (Number.isInteger(num) && choices[num - 1]) return cleanup(choices[num - 1].value);
|
|
364
|
+
}
|
|
328
365
|
|
|
329
366
|
readline.emitKeypressEvents(stdin);
|
|
330
367
|
if (stdin.isTTY) stdin.setRawMode(true);
|
|
@@ -393,25 +430,25 @@ async function askMultiChoice(rl, label, choices, options = {}) {
|
|
|
393
430
|
renderMultiChoiceScreen(label, choices, index, selected, options);
|
|
394
431
|
}
|
|
395
432
|
|
|
396
|
-
function onKeypress(
|
|
397
|
-
if (
|
|
398
|
-
if (
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (key
|
|
410
|
-
if (
|
|
411
|
-
const num =
|
|
412
|
-
if (Number.isInteger(num) && choices[num - 1]) {
|
|
413
|
-
index = num - 1;
|
|
414
|
-
toggle();
|
|
433
|
+
function onKeypress(raw, key = {}) {
|
|
434
|
+
if (isCtrlC(raw, key)) return cleanup([]);
|
|
435
|
+
if (isUpKey(raw, key)) {
|
|
436
|
+
index = (index - 1 + choices.length) % choices.length;
|
|
437
|
+
renderMultiChoiceScreen(label, choices, index, selected, options);
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
if (isDownKey(raw, key)) {
|
|
441
|
+
index = (index + 1) % choices.length;
|
|
442
|
+
renderMultiChoiceScreen(label, choices, index, selected, options);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (keySeq(raw, key).toLowerCase() === "q" || isEscape(raw, key)) return cleanup([]);
|
|
446
|
+
if (isSpaceKey(raw, key)) return toggle();
|
|
447
|
+
if (isEnterKey(raw, key)) return cleanup([...selected]);
|
|
448
|
+
const num = numberKey(raw, key);
|
|
449
|
+
if (Number.isInteger(num) && choices[num - 1]) {
|
|
450
|
+
index = num - 1;
|
|
451
|
+
toggle();
|
|
415
452
|
}
|
|
416
453
|
}
|
|
417
454
|
|