@kaynooo/cli-pick 0.5.0 → 0.6.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.
- package/README.md +1 -1
- package/dist/pick.js +21 -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.
|
|
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
|
@@ -1127,7 +1127,10 @@ var KEYS = {
|
|
|
1127
1127
|
"\b": "erase",
|
|
1128
1128
|
"\x15": "clear",
|
|
1129
1129
|
"\x17": "word",
|
|
1130
|
-
"\t": "tab"
|
|
1130
|
+
"\t": "tab",
|
|
1131
|
+
"\x1F": "help",
|
|
1132
|
+
"\x1BOP": "help",
|
|
1133
|
+
"\x1B[11~": "help"
|
|
1131
1134
|
};
|
|
1132
1135
|
function repeat(value, count) {
|
|
1133
1136
|
return Array.from({ length: count }).fill(value);
|
|
@@ -1196,7 +1199,7 @@ function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
|
1196
1199
|
});
|
|
1197
1200
|
}
|
|
1198
1201
|
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 };
|
|
1202
|
+
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
1203
|
return withRows(state, rows);
|
|
1201
1204
|
}
|
|
1202
1205
|
function withRows(state, rows, header = state.header) {
|
|
@@ -1218,6 +1221,8 @@ function highlighted(state) {
|
|
|
1218
1221
|
function press(state, key) {
|
|
1219
1222
|
if (state.done !== undefined)
|
|
1220
1223
|
return state;
|
|
1224
|
+
if (state.help)
|
|
1225
|
+
return { ...state, help: false };
|
|
1221
1226
|
if (typeof key === "object") {
|
|
1222
1227
|
if ("text" in key)
|
|
1223
1228
|
return withQuery(state, state.query + key.text);
|
|
@@ -1238,6 +1243,8 @@ function press(state, key) {
|
|
|
1238
1243
|
return move(state, state.matches.length);
|
|
1239
1244
|
case "cancel":
|
|
1240
1245
|
return { ...state, done: "cancel" };
|
|
1246
|
+
case "help":
|
|
1247
|
+
return { ...state, help: true };
|
|
1241
1248
|
case "erase":
|
|
1242
1249
|
return withQuery(state, [...state.query].slice(0, -1).join(""));
|
|
1243
1250
|
case "clear":
|
|
@@ -1418,7 +1425,18 @@ function fitStyled(line, width, plain = identity) {
|
|
|
1418
1425
|
function caretColumn(state, layout) {
|
|
1419
1426
|
return Math.min(layout.listWidth, Bun.stringWidth(state.prompt) + Bun.stringWidth(state.query) + 1);
|
|
1420
1427
|
}
|
|
1428
|
+
function helpLines(state, layout, theme) {
|
|
1429
|
+
const lines = [
|
|
1430
|
+
"type to filter, up, down, ctrl-p, ctrl-n, pgup, pgdn, home, end move",
|
|
1431
|
+
`enter picks${state.multi ? ", tab marks" : ""}, ctrl-u clears the query, ctrl-w a word, esc or ctrl-c cancels`,
|
|
1432
|
+
...state.expect.length > 0 ? [`${state.expect.join(", ")} end the pick as this command asks`] : []
|
|
1433
|
+
];
|
|
1434
|
+
const title = "keys, any key closes this help";
|
|
1435
|
+
return [{ text: theme.accent(title), width: title.length }, ...lines.map((line) => fit(` ${line}`, layout.listWidth, theme.label))];
|
|
1436
|
+
}
|
|
1421
1437
|
function listLines(state, layout, theme) {
|
|
1438
|
+
if (state.help)
|
|
1439
|
+
return helpLines(state, layout, theme);
|
|
1422
1440
|
const header = state.header === "" ? [] : state.header.split(`
|
|
1423
1441
|
`).map((line) => fitStyled(line, layout.listWidth, theme.label));
|
|
1424
1442
|
const rows = Math.max(1, layout.listHeight - 2 - header.length);
|
|
@@ -1675,7 +1693,7 @@ async function choose(lines, settings) {
|
|
|
1675
1693
|
// src/pick.ts
|
|
1676
1694
|
var USAGE = `pick [options]: a fuzzy selector, the lines on stdin in, the chosen one on stdout out
|
|
1677
1695
|
|
|
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.
|
|
1696
|
+
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
1697
|
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
1698
|
--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
1699
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-pick",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.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.
|
|
38
|
+
"@kaynooo/cli-kit": "0.26.0"
|
|
39
39
|
}
|
|
40
40
|
}
|