@kaynooo/cli-pick 0.5.0 → 0.6.1

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 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.
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.
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
@@ -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
@@ -1127,7 +1129,10 @@ var KEYS = {
1127
1129
  "\b": "erase",
1128
1130
  "\x15": "clear",
1129
1131
  "\x17": "word",
1130
- "\t": "tab"
1132
+ "\t": "tab",
1133
+ "\x1F": "help",
1134
+ "\x1BOP": "help",
1135
+ "\x1B[11~": "help"
1131
1136
  };
1132
1137
  function repeat(value, count) {
1133
1138
  return Array.from({ length: count }).fill(value);
@@ -1196,7 +1201,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
1196
1201
  });
1197
1202
  }
1198
1203
  function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
1199
- const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, page: 10, marked: new Set, multi, prompt, done: undefined };
1204
+ const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
1200
1205
  return withRows(state, rows);
1201
1206
  }
1202
1207
  function withRows(state, rows, header = state.header) {
@@ -1218,6 +1223,8 @@ function highlighted(state) {
1218
1223
  function press(state, key) {
1219
1224
  if (state.done !== undefined)
1220
1225
  return state;
1226
+ if (state.help)
1227
+ return { ...state, help: false };
1221
1228
  if (typeof key === "object") {
1222
1229
  if ("text" in key)
1223
1230
  return withQuery(state, state.query + key.text);
@@ -1238,6 +1245,8 @@ function press(state, key) {
1238
1245
  return move(state, state.matches.length);
1239
1246
  case "cancel":
1240
1247
  return { ...state, done: "cancel" };
1248
+ case "help":
1249
+ return { ...state, help: true };
1241
1250
  case "erase":
1242
1251
  return withQuery(state, [...state.query].slice(0, -1).join(""));
1243
1252
  case "clear":
@@ -1418,7 +1427,18 @@ function fitStyled(line, width, plain = identity) {
1418
1427
  function caretColumn(state, layout) {
1419
1428
  return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
1420
1429
  }
1430
+ function helpLines(state, layout, theme) {
1431
+ const lines = [
1432
+ "type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
1433
+ `enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
1434
+ ...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
1435
+ ];
1436
+ const title = "keys, any key closes this help";
1437
+ return [{ text: theme.accent(title), width: title.length }, ...lines.map((line) => fit(` ${line}`, layout.listWidth, theme.label))];
1438
+ }
1421
1439
  function listLines(state, layout, theme) {
1440
+ if (state.help)
1441
+ return helpLines(state, layout, theme);
1422
1442
  const header = state.header === "" ? [] : state.header.split(`
1423
1443
  `).map((line) => fitStyled(line, layout.listWidth, theme.label));
1424
1444
  const rows = Math.max(1, layout.listHeight - 2 - header.length);
@@ -1467,14 +1487,24 @@ function up(lines) {
1467
1487
  return lines > 0 ? `\x1B[${lines}A` : "";
1468
1488
  }
1469
1489
  function openTerminal() {
1470
- let input;
1490
+ let mode;
1471
1491
  try {
1472
- input = new tty.ReadStream(openSync("/dev/tty", "r"));
1492
+ mode = new tty.ReadStream(openSync("/dev/tty", "r"));
1473
1493
  } catch {
1474
1494
  return fail("no terminal to read keys from (/dev/tty)");
1475
1495
  }
1496
+ const keys = Bun.file("/dev/tty").stream().getReader();
1476
1497
  const out = process14.stderr;
1477
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
+ }
1478
1508
  return {
1479
1509
  get columns() {
1480
1510
  return out.columns || 80;
@@ -1486,17 +1516,18 @@ function openTerminal() {
1486
1516
  write: (text) => void out.write(text),
1487
1517
  listen(onChunk, onResize) {
1488
1518
  resize = onResize;
1489
- input.setRawMode(true);
1519
+ mode.setRawMode(true);
1490
1520
  out.on("resize", onResize);
1491
- input.on("data", (chunk) => onChunk(chunk.toString()));
1521
+ read(onChunk);
1492
1522
  },
1493
1523
  close() {
1494
1524
  if (resize !== undefined)
1495
1525
  out.off("resize", resize);
1496
1526
  try {
1497
- input.setRawMode(false);
1527
+ mode.setRawMode(false);
1498
1528
  } finally {
1499
- input.destroy();
1529
+ mode.destroy();
1530
+ keys.cancel();
1500
1531
  }
1501
1532
  }
1502
1533
  };
@@ -1675,7 +1706,7 @@ async function choose(lines, settings) {
1675
1706
  // src/pick.ts
1676
1707
  var USAGE = `pick [options]: a fuzzy selector, the lines on stdin in, the chosen one on stdout out
1677
1708
 
1678
- Type to filter: the query matches as a subsequence, best matches first (a word start, a run of characters or a prefix scores higher; a lowercase query ignores case, an uppercase letter makes it exact). Up and down or ctrl-p and ctrl-n move, enter picks, esc and ctrl-c cancel, ctrl-u clears the query.
1709
+ Type to filter: the query matches as a subsequence, best matches first (a word start, a run of characters or a prefix scores higher; a lowercase query ignores case, an uppercase letter makes it exact). Up and down or ctrl-p and ctrl-n move, enter picks, esc and ctrl-c cancel, ctrl-u clears the query, ctrl-/ or f1 shows the keys.
1679
1710
  The keys are read from the terminal and the selector is drawn on stderr, so \`pick\` in a pipe or a command substitution prints only the choice. With --multi, tab marks the highlighted line and enter prints the marked lines in input order (the highlighted one when none is marked).
1680
1711
  --preview runs a command for the highlighted line, \`{}\` standing for it shell-quoted, in a pane on the right when the terminal is at least 80 columns wide; its output is cut at 64 KiB and 200 lines.
1681
1712
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pick",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.1",
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.25.0"
38
+ "@kaynooo/cli-kit": "0.27.1"
39
39
  }
40
40
  }