@kaynooo/cli-pick 0.6.0 → 0.7.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/pick.js +24 -11
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -14,7 +14,7 @@ bun add -g @kaynooo/cli-pick
14
14
  | `ls \| pick --preview 'head -20 {}'` | a pane on the right (terminal at least 80 columns) shows the command run for the highlighted line, `{}` shell-quoted |
15
15
  | `--height 12`, `--height 60%` | lines or a share of the terminal to draw in (40%) |
16
16
 
17
- Keys: type to filter, up and down or ctrl-p and ctrl-n to move, enter to pick, esc or ctrl-c to cancel (exit 1, nothing printed), ctrl-u clears the query, ctrl-w deletes a word, ctrl-/ or f1 opens a legend of the keys until the next key.
17
+ Keys: type to filter, up and down or ctrl-p and ctrl-n to move, enter to pick, esc or ctrl-c to cancel (exit 1, nothing printed), ctrl-u clears the query, ctrl-w deletes a word, ctrl-/ or f1 opens a legend of the keys until the next key. The count line ends in a `ctrl-/ keys` hint, and the characters a query matched are underlined.
18
18
 
19
19
  The query matches as a subsequence, best first: a word start, a run of consecutive characters or a prefix scores higher, a lowercase query ignores case and an uppercase letter makes it exact. Keys come from `/dev/tty` and the selector is drawn on stderr, so a pipe or a command substitution takes only the choice. Without a terminal on stderr it exits 2.
20
20
 
package/dist/pick.js CHANGED
@@ -328,13 +328,13 @@ function userConfigPath(bin, where = {}) {
328
328
  // ../kit/src/theme.ts
329
329
  var DEFAULT = {
330
330
  colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
331
- glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
331
+ glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D" },
332
332
  accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
333
333
  bins: {}
334
334
  };
335
335
  var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
336
336
  var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
337
- var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
337
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
338
338
  var PRESETS = {
339
339
  default: {},
340
340
  "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
@@ -1004,6 +1004,8 @@ async function runMain({ name, version, run, redact, usage }, argv = process11.a
1004
1004
  }
1005
1005
  return code;
1006
1006
  }
1007
+ // ../kit/src/folders.ts
1008
+ var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
1007
1009
  // ../kit/src/secrets.ts
1008
1010
  var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
1009
1011
  // ../kit/src/sessions.ts
@@ -1446,7 +1448,7 @@ function listLines(state, layout, theme) {
1446
1448
  const promptWidth = Bun.stringWidth(state.prompt);
1447
1449
  const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
1448
1450
  const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
1449
- const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks}`, layout.listWidth, theme.label);
1451
+ const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks} ctrl-/ keys`, layout.listWidth, theme.label);
1450
1452
  const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
1451
1453
  if (state.matches.length === 0)
1452
1454
  lines.push(fit(" no match", layout.listWidth, theme.label));
@@ -1454,7 +1456,7 @@ function listLines(state, layout, theme) {
1454
1456
  const current = top + offset === state.cursor;
1455
1457
  const pointer = current ? theme.accent("\u276F") : " ";
1456
1458
  const mark = state.multi ? `${state.marked.has(match.index) ? theme.id("\u25CF") : " "} ` : "";
1457
- const text = fit(state.items[match.index], layout.listWidth - prefixWidth, current ? theme.value : identity, theme.accent, new Set(match.positions), state.styles[match.index]);
1459
+ const text = fit(state.items[match.index], layout.listWidth - prefixWidth, current ? theme.value : identity, theme.match ?? theme.accent, new Set(match.positions), state.styles[match.index]);
1458
1460
  lines.push({ text: `${pointer} ${mark}${text.text}`, width: prefixWidth + text.width });
1459
1461
  }
1460
1462
  return lines;
@@ -1485,14 +1487,24 @@ function up(lines) {
1485
1487
  return lines > 0 ? `\x1B[${lines}A` : "";
1486
1488
  }
1487
1489
  function openTerminal() {
1488
- let input;
1490
+ let mode;
1489
1491
  try {
1490
- input = new tty.ReadStream(openSync("/dev/tty", "r"));
1492
+ mode = new tty.ReadStream(openSync("/dev/tty", "r"));
1491
1493
  } catch {
1492
1494
  return fail("no terminal to read keys from (/dev/tty)");
1493
1495
  }
1496
+ const keys = Bun.file("/dev/tty").stream().getReader();
1494
1497
  const out = process14.stderr;
1495
1498
  let resize;
1499
+ async function read(onChunk) {
1500
+ const decoder = new TextDecoder;
1501
+ try {
1502
+ for (let chunk = await keys.read();!chunk.done; chunk = await keys.read())
1503
+ onChunk(decoder.decode(chunk.value, { stream: true }));
1504
+ } catch {
1505
+ onChunk("\x03");
1506
+ }
1507
+ }
1496
1508
  return {
1497
1509
  get columns() {
1498
1510
  return out.columns || 80;
@@ -1500,21 +1512,22 @@ function openTerminal() {
1500
1512
  get rows() {
1501
1513
  return out.rows || 24;
1502
1514
  },
1503
- theme: { accent: role("accent", out), label: role("label", out), value: role("value", out), id: role("id", out) },
1515
+ theme: { accent: role("accent", out), label: role("label", out), value: role("value", out), id: role("id", out), match: (text) => paint(out).underline(role("accent", out)(text)) },
1504
1516
  write: (text) => void out.write(text),
1505
1517
  listen(onChunk, onResize) {
1506
1518
  resize = onResize;
1507
- input.setRawMode(true);
1519
+ mode.setRawMode(true);
1508
1520
  out.on("resize", onResize);
1509
- input.on("data", (chunk) => onChunk(chunk.toString()));
1521
+ read(onChunk);
1510
1522
  },
1511
1523
  close() {
1512
1524
  if (resize !== undefined)
1513
1525
  out.off("resize", resize);
1514
1526
  try {
1515
- input.setRawMode(false);
1527
+ mode.setRawMode(false);
1516
1528
  } finally {
1517
- input.destroy();
1529
+ mode.destroy();
1530
+ keys.cancel();
1518
1531
  }
1519
1532
  }
1520
1533
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pick",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "description": "pick: a themed fuzzy selector, lines on stdin, the chosen one on stdout.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -35,6 +35,6 @@
35
35
  "pick": "$npm_execpath src/pick.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.26.0"
38
+ "@kaynooo/cli-kit": "0.28.0"
39
39
  }
40
40
  }