@kaynooo/cli-pick 0.6.1 → 0.8.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 +2 -2
  2. package/dist/pick.js +21 -11
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -12,9 +12,9 @@ bun add -g @kaynooo/cli-pick
12
12
  | `ls \| pick --multi` | tab marks lines, enter prints the marked ones (the highlighted one when none is marked) |
13
13
  | `pick --prompt 'branch> ' --query main` | a custom prompt, a query to start with |
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
- | `--height 12`, `--height 60%` | lines or a share of the terminal to draw in (40%) |
15
+ | `--height 12`, `--height 60%` | lines or a share of the terminal to draw in (100%) |
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
@@ -326,19 +326,21 @@ function userConfigPath(bin, where = {}) {
326
326
  }
327
327
 
328
328
  // ../kit/src/theme.ts
329
+ var ENDS = new Map;
329
330
  var DEFAULT = {
330
331
  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" },
332
+ 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
333
  accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
333
- bins: {}
334
+ bins: {},
335
+ gradient: ["#c084fc", "#67e8f9"]
334
336
  };
335
337
  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
338
  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: "#" };
339
+ var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+" };
338
340
  var PRESETS = {
339
341
  default: {},
340
- "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
341
- mono: { colors: MONO, accents: ["bold"] },
342
+ "high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
343
+ mono: { colors: MONO, accents: ["bold"], gradient: undefined },
342
344
  ascii: { glyphs: ASCII }
343
345
  };
344
346
  var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
@@ -409,6 +411,8 @@ function applyPreset(theme, name, warn, where) {
409
411
  Object.assign(theme.glyphs, preset.glyphs);
410
412
  if (preset.accents !== undefined)
411
413
  theme.accents = [...preset.accents];
414
+ if (Object.hasOwn(preset, "gradient"))
415
+ theme.gradient = preset.gradient;
412
416
  return name;
413
417
  }
414
418
  function applyFile(theme, file, where, warn) {
@@ -436,6 +440,12 @@ function applyFile(theme, file, where, warn) {
436
440
  theme.accents = [...file.accents];
437
441
  else if (file.accents !== undefined)
438
442
  warn(`${where}: accents must be a non-empty list of colours`);
443
+ if (file.gradient === null)
444
+ theme.gradient = undefined;
445
+ else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
446
+ theme.gradient = [file.gradient[0], file.gradient[1]];
447
+ else if (file.gradient !== undefined)
448
+ warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
439
449
  if (isRecord(file.bins)) {
440
450
  for (const [bin, value] of Object.entries(file.bins)) {
441
451
  if (isColorSpec(value))
@@ -459,7 +469,7 @@ function isPath(chosen) {
459
469
  return chosen.includes("/") || chosen.endsWith(".json");
460
470
  }
461
471
  function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
462
- const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
472
+ const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
463
473
  const sources = [];
464
474
  const chosen = env.KIT_THEME ?? "";
465
475
  const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
@@ -1381,7 +1391,7 @@ var PREVIEW_SHARE = 0.4;
1381
1391
  var RESET2 = "\x1B[0m";
1382
1392
  var SEPARATOR = " \u2502 ";
1383
1393
  var HEIGHT = /^(\d+)(%?)$/;
1384
- var DEFAULT_HEIGHT = { percent: 40 };
1394
+ var DEFAULT_HEIGHT = { percent: 100 };
1385
1395
  function parseHeight(text) {
1386
1396
  const found = HEIGHT.exec(text);
1387
1397
  if (found === null || Number(found[1]) < 1)
@@ -1448,7 +1458,7 @@ function listLines(state, layout, theme) {
1448
1458
  const promptWidth = Bun.stringWidth(state.prompt);
1449
1459
  const query = fit(state.query, Math.max(1, layout.listWidth - promptWidth), identity);
1450
1460
  const place = state.matches.length > rows ? ` (${state.cursor + 1} of ${state.matches.length})` : "";
1451
- const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks}`, layout.listWidth, theme.label);
1461
+ const count = fit(` ${state.matches.length}/${state.items.length}${place}${marks} ctrl-/ keys`, layout.listWidth, theme.label);
1452
1462
  const lines = [{ text: theme.accent(state.prompt) + query.text, width: promptWidth + query.width }, count, ...header];
1453
1463
  if (state.matches.length === 0)
1454
1464
  lines.push(fit(" no match", layout.listWidth, theme.label));
@@ -1456,7 +1466,7 @@ function listLines(state, layout, theme) {
1456
1466
  const current = top + offset === state.cursor;
1457
1467
  const pointer = current ? theme.accent("\u276F") : " ";
1458
1468
  const mark = state.multi ? `${state.marked.has(match.index) ? theme.id("\u25CF") : " "} ` : "";
1459
- const text = fit(state.items[match.index], layout.listWidth - prefixWidth, current ? theme.value : identity, theme.accent, new Set(match.positions), state.styles[match.index]);
1469
+ 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]);
1460
1470
  lines.push({ text: `${pointer} ${mark}${text.text}`, width: prefixWidth + text.width });
1461
1471
  }
1462
1472
  return lines;
@@ -1512,7 +1522,7 @@ function openTerminal() {
1512
1522
  get rows() {
1513
1523
  return out.rows || 24;
1514
1524
  },
1515
- theme: { accent: role("accent", out), label: role("label", out), value: role("value", out), id: role("id", out) },
1525
+ 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)) },
1516
1526
  write: (text) => void out.write(text),
1517
1527
  listen(onChunk, onResize) {
1518
1528
  resize = onResize;
@@ -1718,7 +1728,7 @@ var OPTIONS = {
1718
1728
  prompt: { type: "string", short: "p", description: "the prompt before the query (> )" },
1719
1729
  query: { type: "string", short: "q", description: "the query to start with" },
1720
1730
  preview: { type: "string", description: "a command shown for the highlighted line, {} standing for it" },
1721
- height: { type: "string", description: "lines or a percentage of the terminal to draw in (40%)" },
1731
+ height: { type: "string", description: "lines or a percentage of the terminal to draw in (100%)" },
1722
1732
  json: jsonOption("{picked: [lines]}, the choice or the marked lines in input order")
1723
1733
  };
1724
1734
  function print(chosen, json) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pick",
3
3
  "type": "module",
4
- "version": "0.6.1",
4
+ "version": "0.8.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.27.1"
38
+ "@kaynooo/cli-kit": "0.33.0"
39
39
  }
40
40
  }