@karmaniverous/stan-cli 0.10.3 → 0.11.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/dist/cjs/index.js +1 -1
- package/dist/cli/{index-BO3K2S0m.js → index-CoyGQCX9.js} +141 -152
- package/dist/cli/stan.js +389 -43
- package/dist/mjs/index.js +1 -1
- package/dist/types/index.d.ts +3 -0
- package/package.json +13 -13
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as readline$1 from 'node:readline';
|
|
3
3
|
import readline__default from 'node:readline';
|
|
4
|
-
import { g as getDefaultExportFromCjs, r as
|
|
4
|
+
import { g as getDefaultExportFromCjs, r as requireIsFullwidthCodePoint, a as requireEmojiRegex, b as requireColorConvert, o as onExit } from './stan.js';
|
|
5
5
|
import R from 'stream';
|
|
6
|
-
import
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
7
|
import process$1 from 'node:process';
|
|
8
8
|
import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
|
|
9
9
|
import { stripVTControlCharacters } from 'node:util';
|
|
@@ -15,22 +15,33 @@ import os from 'node:os';
|
|
|
15
15
|
import { randomUUID } from 'node:crypto';
|
|
16
16
|
import require$$0$2 from 'buffer';
|
|
17
17
|
import require$$1$1 from 'string_decoder';
|
|
18
|
-
import 'node:events';
|
|
19
|
-
import 'node:child_process';
|
|
20
18
|
import 'node:fs';
|
|
21
19
|
import 'node:fs/promises';
|
|
22
20
|
import 'fs-extra';
|
|
23
21
|
import 'node:url';
|
|
24
22
|
import 'process';
|
|
23
|
+
import 'node:child_process';
|
|
25
24
|
import 'os';
|
|
26
25
|
import 'path';
|
|
27
26
|
import 'util';
|
|
28
27
|
import 'events';
|
|
28
|
+
import 'node:tty';
|
|
29
29
|
import 'clipboardy';
|
|
30
|
-
import 'node:module';
|
|
31
30
|
|
|
32
|
-
const isUpKey = (key) =>
|
|
33
|
-
|
|
31
|
+
const isUpKey = (key, keybindings = []) =>
|
|
32
|
+
// The up key
|
|
33
|
+
key.name === 'up' ||
|
|
34
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
35
|
+
(keybindings.includes('vim') && key.name === 'k') ||
|
|
36
|
+
// Emacs keybinding: Ctrl+P means "previous" in Emacs navigation conventions
|
|
37
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'p');
|
|
38
|
+
const isDownKey = (key, keybindings = []) =>
|
|
39
|
+
// The down key
|
|
40
|
+
key.name === 'down' ||
|
|
41
|
+
// Vim keybinding: hjkl keys map to left/down/up/right
|
|
42
|
+
(keybindings.includes('vim') && key.name === 'j') ||
|
|
43
|
+
// Emacs keybinding: Ctrl+N means "next" in Emacs navigation conventions
|
|
44
|
+
(keybindings.includes('emacs') && key.ctrl && key.name === 'n');
|
|
34
45
|
const isSpaceKey = (key) => key.name === 'space';
|
|
35
46
|
const isBackspaceKey = (key) => key.name === 'backspace';
|
|
36
47
|
const isTabKey = (key) => key.name === 'tab';
|
|
@@ -198,18 +209,21 @@ function useEffect(cb, depArray) {
|
|
|
198
209
|
});
|
|
199
210
|
}
|
|
200
211
|
|
|
212
|
+
const require$1 = createRequire(import.meta.url);
|
|
213
|
+
function __require() { return require$1("node:tty"); }
|
|
214
|
+
|
|
201
215
|
var yoctocolorsCjs;
|
|
202
216
|
var hasRequiredYoctocolorsCjs;
|
|
203
217
|
|
|
204
218
|
function requireYoctocolorsCjs () {
|
|
205
219
|
if (hasRequiredYoctocolorsCjs) return yoctocolorsCjs;
|
|
206
220
|
hasRequiredYoctocolorsCjs = 1;
|
|
207
|
-
const tty
|
|
221
|
+
const tty = __require(); // eslint-disable-line unicorn/prefer-module
|
|
208
222
|
|
|
209
223
|
// eslint-disable-next-line no-warning-comments
|
|
210
224
|
// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
|
|
211
225
|
// Lots of optionals here to support Deno.
|
|
212
|
-
const hasColors = tty
|
|
226
|
+
const hasColors = tty?.WriteStream?.prototype?.hasColors?.() ?? false;
|
|
213
227
|
|
|
214
228
|
const format = (open, close) => {
|
|
215
229
|
if (!hasColors) {
|
|
@@ -814,66 +828,6 @@ function requireStripAnsi () {
|
|
|
814
828
|
return stripAnsi;
|
|
815
829
|
}
|
|
816
830
|
|
|
817
|
-
var isFullwidthCodePoint = {exports: {}};
|
|
818
|
-
|
|
819
|
-
/* eslint-disable yoda */
|
|
820
|
-
|
|
821
|
-
var hasRequiredIsFullwidthCodePoint;
|
|
822
|
-
|
|
823
|
-
function requireIsFullwidthCodePoint () {
|
|
824
|
-
if (hasRequiredIsFullwidthCodePoint) return isFullwidthCodePoint.exports;
|
|
825
|
-
hasRequiredIsFullwidthCodePoint = 1;
|
|
826
|
-
|
|
827
|
-
const isFullwidthCodePoint$1 = codePoint => {
|
|
828
|
-
if (Number.isNaN(codePoint)) {
|
|
829
|
-
return false;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// Code points are derived from:
|
|
833
|
-
// http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
|
|
834
|
-
if (
|
|
835
|
-
codePoint >= 0x1100 && (
|
|
836
|
-
codePoint <= 0x115F || // Hangul Jamo
|
|
837
|
-
codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
|
|
838
|
-
codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
|
|
839
|
-
// CJK Radicals Supplement .. Enclosed CJK Letters and Months
|
|
840
|
-
(0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
|
|
841
|
-
// Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
|
|
842
|
-
(0x3250 <= codePoint && codePoint <= 0x4DBF) ||
|
|
843
|
-
// CJK Unified Ideographs .. Yi Radicals
|
|
844
|
-
(0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
|
|
845
|
-
// Hangul Jamo Extended-A
|
|
846
|
-
(0xA960 <= codePoint && codePoint <= 0xA97C) ||
|
|
847
|
-
// Hangul Syllables
|
|
848
|
-
(0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
|
|
849
|
-
// CJK Compatibility Ideographs
|
|
850
|
-
(0xF900 <= codePoint && codePoint <= 0xFAFF) ||
|
|
851
|
-
// Vertical Forms
|
|
852
|
-
(0xFE10 <= codePoint && codePoint <= 0xFE19) ||
|
|
853
|
-
// CJK Compatibility Forms .. Small Form Variants
|
|
854
|
-
(0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
|
|
855
|
-
// Halfwidth and Fullwidth Forms
|
|
856
|
-
(0xFF01 <= codePoint && codePoint <= 0xFF60) ||
|
|
857
|
-
(0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
|
|
858
|
-
// Kana Supplement
|
|
859
|
-
(0x1B000 <= codePoint && codePoint <= 0x1B001) ||
|
|
860
|
-
// Enclosed Ideographic Supplement
|
|
861
|
-
(0x1F200 <= codePoint && codePoint <= 0x1F251) ||
|
|
862
|
-
// CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
|
|
863
|
-
(0x20000 <= codePoint && codePoint <= 0x3FFFD)
|
|
864
|
-
)
|
|
865
|
-
) {
|
|
866
|
-
return true;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
return false;
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
isFullwidthCodePoint.exports = isFullwidthCodePoint$1;
|
|
873
|
-
isFullwidthCodePoint.exports.default = isFullwidthCodePoint$1;
|
|
874
|
-
return isFullwidthCodePoint.exports;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
831
|
var hasRequiredStringWidth;
|
|
878
832
|
|
|
879
833
|
function requireStringWidth () {
|
|
@@ -1849,8 +1803,12 @@ const checkboxTheme = {
|
|
|
1849
1803
|
disabledChoice: (text) => colors.dim(`- ${text}`),
|
|
1850
1804
|
renderSelectedChoices: (selectedChoices) => selectedChoices.map((choice) => choice.short).join(', '),
|
|
1851
1805
|
description: (text) => colors.cyan(text),
|
|
1806
|
+
keysHelpTip: (keys) => keys
|
|
1807
|
+
.map(([key, action]) => `${colors.bold(key)} ${colors.dim(action)}`)
|
|
1808
|
+
.join(colors.dim(' • ')),
|
|
1852
1809
|
},
|
|
1853
|
-
helpMode: '
|
|
1810
|
+
helpMode: 'always',
|
|
1811
|
+
keybindings: [],
|
|
1854
1812
|
};
|
|
1855
1813
|
function isSelectable$2(item) {
|
|
1856
1814
|
return !Separator.isSeparator(item) && !item.disabled;
|
|
@@ -1875,6 +1833,7 @@ function normalizeChoices$4(choices) {
|
|
|
1875
1833
|
value: choice,
|
|
1876
1834
|
name: choice,
|
|
1877
1835
|
short: choice,
|
|
1836
|
+
checkedName: choice,
|
|
1878
1837
|
disabled: false,
|
|
1879
1838
|
checked: false,
|
|
1880
1839
|
};
|
|
@@ -1884,6 +1843,7 @@ function normalizeChoices$4(choices) {
|
|
|
1884
1843
|
value: choice.value,
|
|
1885
1844
|
name,
|
|
1886
1845
|
short: choice.short ?? name,
|
|
1846
|
+
checkedName: choice.checkedName ?? name,
|
|
1887
1847
|
disabled: choice.disabled ?? false,
|
|
1888
1848
|
checked: choice.checked ?? false,
|
|
1889
1849
|
};
|
|
@@ -1894,10 +1854,12 @@ function normalizeChoices$4(choices) {
|
|
|
1894
1854
|
});
|
|
1895
1855
|
}
|
|
1896
1856
|
var checkbox = createPrompt((config, done) => {
|
|
1897
|
-
const {
|
|
1857
|
+
const {
|
|
1858
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1859
|
+
instructions, pageSize = 7, loop = true, required, validate = () => true, } = config;
|
|
1898
1860
|
const shortcuts = { all: 'a', invert: 'i', ...config.shortcuts };
|
|
1899
1861
|
const theme = makeTheme(checkboxTheme, config.theme);
|
|
1900
|
-
const
|
|
1862
|
+
const { keybindings } = theme;
|
|
1901
1863
|
const [status, setStatus] = useState('idle');
|
|
1902
1864
|
const prefix = usePrefix({ status, theme });
|
|
1903
1865
|
const [items, setItems] = useState(normalizeChoices$4(config.choices));
|
|
@@ -1910,7 +1872,6 @@ var checkbox = createPrompt((config, done) => {
|
|
|
1910
1872
|
return { first, last };
|
|
1911
1873
|
}, [items]);
|
|
1912
1874
|
const [active, setActive] = useState(bounds.first);
|
|
1913
|
-
const [showHelpTip, setShowHelpTip] = useState(true);
|
|
1914
1875
|
const [errorMsg, setError] = useState();
|
|
1915
1876
|
useKeypress(async (key) => {
|
|
1916
1877
|
if (isEnterKey(key)) {
|
|
@@ -1927,11 +1888,11 @@ var checkbox = createPrompt((config, done) => {
|
|
|
1927
1888
|
setError(isValid || 'You must select a valid value');
|
|
1928
1889
|
}
|
|
1929
1890
|
}
|
|
1930
|
-
else if (isUpKey(key) || isDownKey(key)) {
|
|
1891
|
+
else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
|
1931
1892
|
if (loop ||
|
|
1932
|
-
(isUpKey(key) && active !== bounds.first) ||
|
|
1933
|
-
(isDownKey(key) && active !== bounds.last)) {
|
|
1934
|
-
const offset = isUpKey(key) ? -1 : 1;
|
|
1893
|
+
(isUpKey(key, keybindings) && active !== bounds.first) ||
|
|
1894
|
+
(isDownKey(key, keybindings) && active !== bounds.last)) {
|
|
1895
|
+
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
|
1935
1896
|
let next = active;
|
|
1936
1897
|
do {
|
|
1937
1898
|
next = (next + offset + items.length) % items.length;
|
|
@@ -1941,7 +1902,6 @@ var checkbox = createPrompt((config, done) => {
|
|
|
1941
1902
|
}
|
|
1942
1903
|
else if (isSpaceKey(key)) {
|
|
1943
1904
|
setError(undefined);
|
|
1944
|
-
setShowHelpTip(false);
|
|
1945
1905
|
setItems(items.map((choice, i) => (i === active ? toggle(choice) : choice)));
|
|
1946
1906
|
}
|
|
1947
1907
|
else if (key.name === shortcuts.all) {
|
|
@@ -1985,9 +1945,10 @@ var checkbox = createPrompt((config, done) => {
|
|
|
1985
1945
|
description = item.description;
|
|
1986
1946
|
}
|
|
1987
1947
|
const checkbox = item.checked ? theme.icon.checked : theme.icon.unchecked;
|
|
1948
|
+
const name = item.checked ? item.checkedName : item.name;
|
|
1988
1949
|
const color = isActive ? theme.style.highlight : (x) => x;
|
|
1989
1950
|
const cursor = isActive ? theme.icon.cursor : ' ';
|
|
1990
|
-
return color(`${cursor}${checkbox} ${
|
|
1951
|
+
return color(`${cursor}${checkbox} ${name}`);
|
|
1991
1952
|
},
|
|
1992
1953
|
pageSize,
|
|
1993
1954
|
loop,
|
|
@@ -1995,44 +1956,39 @@ var checkbox = createPrompt((config, done) => {
|
|
|
1995
1956
|
if (status === 'done') {
|
|
1996
1957
|
const selection = items.filter(isChecked);
|
|
1997
1958
|
const answer = theme.style.answer(theme.style.renderSelectedChoices(selection, items));
|
|
1998
|
-
return
|
|
1959
|
+
return [prefix, message, answer].filter(Boolean).join(' ');
|
|
1999
1960
|
}
|
|
2000
|
-
let
|
|
2001
|
-
|
|
2002
|
-
if (theme.helpMode
|
|
2003
|
-
(theme.helpMode === 'auto' &&
|
|
2004
|
-
showHelpTip &&
|
|
2005
|
-
(instructions === undefined || instructions))) {
|
|
1961
|
+
let helpLine;
|
|
1962
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1963
|
+
if (theme.helpMode !== 'never' && instructions !== false) {
|
|
2006
1964
|
if (typeof instructions === 'string') {
|
|
2007
|
-
|
|
1965
|
+
helpLine = instructions;
|
|
2008
1966
|
}
|
|
2009
1967
|
else {
|
|
2010
1968
|
const keys = [
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
shortcuts.invert
|
|
2014
|
-
? `${theme.style.key(shortcuts.invert)} to invert selection`
|
|
2015
|
-
: '',
|
|
2016
|
-
`and ${theme.style.key('enter')} to proceed`,
|
|
1969
|
+
['↑↓', 'navigate'],
|
|
1970
|
+
['space', 'select'],
|
|
2017
1971
|
];
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
helpTipBottom = `\n${theme.style.help('(Use arrow keys to reveal more choices)')}`;
|
|
2025
|
-
firstRender.current = false;
|
|
1972
|
+
if (shortcuts.all)
|
|
1973
|
+
keys.push([shortcuts.all, 'all']);
|
|
1974
|
+
if (shortcuts.invert)
|
|
1975
|
+
keys.push([shortcuts.invert, 'invert']);
|
|
1976
|
+
keys.push(['⏎', 'submit']);
|
|
1977
|
+
helpLine = theme.style.keysHelpTip(keys);
|
|
2026
1978
|
}
|
|
2027
1979
|
}
|
|
2028
|
-
const
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
1980
|
+
const lines = [
|
|
1981
|
+
[prefix, message].filter(Boolean).join(' '),
|
|
1982
|
+
page,
|
|
1983
|
+
' ',
|
|
1984
|
+
description ? theme.style.description(description) : '',
|
|
1985
|
+
errorMsg ? theme.style.error(errorMsg) : '',
|
|
1986
|
+
helpLine,
|
|
1987
|
+
]
|
|
1988
|
+
.filter(Boolean)
|
|
1989
|
+
.join('\n')
|
|
1990
|
+
.trimEnd();
|
|
1991
|
+
return `${lines}${cursorHide}`;
|
|
2036
1992
|
});
|
|
2037
1993
|
|
|
2038
1994
|
var lib$1 = {};
|
|
@@ -15833,8 +15789,11 @@ const searchTheme = {
|
|
|
15833
15789
|
disabled: (text) => colors.dim(`- ${text}`),
|
|
15834
15790
|
searchTerm: (text) => colors.cyan(text),
|
|
15835
15791
|
description: (text) => colors.cyan(text),
|
|
15792
|
+
keysHelpTip: (keys) => keys
|
|
15793
|
+
.map(([key, action]) => `${colors.bold(key)} ${colors.dim(action)}`)
|
|
15794
|
+
.join(colors.dim(' • ')),
|
|
15836
15795
|
},
|
|
15837
|
-
helpMode: '
|
|
15796
|
+
helpMode: 'always',
|
|
15838
15797
|
};
|
|
15839
15798
|
function isSelectable$1(item) {
|
|
15840
15799
|
return !Separator.isSeparator(item) && !item.disabled;
|
|
@@ -15867,7 +15826,6 @@ function normalizeChoices$1(choices) {
|
|
|
15867
15826
|
var search = createPrompt((config, done) => {
|
|
15868
15827
|
const { pageSize = 7, validate = () => true } = config;
|
|
15869
15828
|
const theme = makeTheme(searchTheme, config.theme);
|
|
15870
|
-
const firstRender = useRef(true);
|
|
15871
15829
|
const [status, setStatus] = useState('loading');
|
|
15872
15830
|
const [searchTerm, setSearchTerm] = useState('');
|
|
15873
15831
|
const [searchResults, setSearchResults] = useState([]);
|
|
@@ -15956,18 +15914,22 @@ var search = createPrompt((config, done) => {
|
|
|
15956
15914
|
}
|
|
15957
15915
|
});
|
|
15958
15916
|
const message = theme.style.message(config.message, status);
|
|
15959
|
-
|
|
15960
|
-
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
|
|
15964
|
-
|
|
15965
|
-
|
|
15966
|
-
searchResults.length > pageSize
|
|
15967
|
-
|
|
15968
|
-
|
|
15917
|
+
let helpLine;
|
|
15918
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
15919
|
+
if (theme.helpMode !== 'never') {
|
|
15920
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
15921
|
+
if (config.instructions) {
|
|
15922
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
15923
|
+
const { pager, navigation } = config.instructions;
|
|
15924
|
+
helpLine = theme.style.help(searchResults.length > pageSize ? pager : navigation);
|
|
15925
|
+
}
|
|
15926
|
+
else {
|
|
15927
|
+
helpLine = theme.style.keysHelpTip([
|
|
15928
|
+
['↑↓', 'navigate'],
|
|
15929
|
+
['⏎', 'select'],
|
|
15930
|
+
]);
|
|
15931
|
+
}
|
|
15969
15932
|
}
|
|
15970
|
-
// TODO: What to do if no results are found? Should we display a message?
|
|
15971
15933
|
const page = usePagination({
|
|
15972
15934
|
items: searchResults,
|
|
15973
15935
|
active,
|
|
@@ -15995,19 +15957,26 @@ var search = createPrompt((config, done) => {
|
|
|
15995
15957
|
}
|
|
15996
15958
|
let searchStr;
|
|
15997
15959
|
if (status === 'done' && selectedChoice) {
|
|
15998
|
-
|
|
15999
|
-
|
|
15960
|
+
return [prefix, message, theme.style.answer(selectedChoice.short)]
|
|
15961
|
+
.filter(Boolean)
|
|
15962
|
+
.join(' ')
|
|
15963
|
+
.trimEnd();
|
|
16000
15964
|
}
|
|
16001
15965
|
else {
|
|
16002
15966
|
searchStr = theme.style.searchTerm(searchTerm);
|
|
16003
15967
|
}
|
|
16004
|
-
const
|
|
16005
|
-
|
|
16006
|
-
|
|
16007
|
-
|
|
16008
|
-
|
|
16009
|
-
|
|
16010
|
-
|
|
15968
|
+
const description = selectedChoice?.description;
|
|
15969
|
+
const header = [prefix, message, searchStr].filter(Boolean).join(' ').trimEnd();
|
|
15970
|
+
const body = [
|
|
15971
|
+
error ?? page,
|
|
15972
|
+
' ',
|
|
15973
|
+
description ? theme.style.description(description) : '',
|
|
15974
|
+
helpLine,
|
|
15975
|
+
]
|
|
15976
|
+
.filter(Boolean)
|
|
15977
|
+
.join('\n')
|
|
15978
|
+
.trimEnd();
|
|
15979
|
+
return [header, body];
|
|
16011
15980
|
});
|
|
16012
15981
|
|
|
16013
15982
|
const selectTheme = {
|
|
@@ -16015,9 +15984,13 @@ const selectTheme = {
|
|
|
16015
15984
|
style: {
|
|
16016
15985
|
disabled: (text) => colors.dim(`- ${text}`),
|
|
16017
15986
|
description: (text) => colors.cyan(text),
|
|
15987
|
+
keysHelpTip: (keys) => keys
|
|
15988
|
+
.map(([key, action]) => `${colors.bold(key)} ${colors.dim(action)}`)
|
|
15989
|
+
.join(colors.dim(' • ')),
|
|
16018
15990
|
},
|
|
16019
|
-
helpMode: '
|
|
15991
|
+
helpMode: 'always',
|
|
16020
15992
|
indexMode: 'hidden',
|
|
15993
|
+
keybindings: [],
|
|
16021
15994
|
};
|
|
16022
15995
|
function isSelectable(item) {
|
|
16023
15996
|
return !Separator.isSeparator(item) && !item.disabled;
|
|
@@ -16049,11 +16022,14 @@ function normalizeChoices(choices) {
|
|
|
16049
16022
|
}
|
|
16050
16023
|
var select = createPrompt((config, done) => {
|
|
16051
16024
|
const { loop = true, pageSize = 7 } = config;
|
|
16052
|
-
const firstRender = useRef(true);
|
|
16053
16025
|
const theme = makeTheme(selectTheme, config.theme);
|
|
16026
|
+
const { keybindings } = theme;
|
|
16054
16027
|
const [status, setStatus] = useState('idle');
|
|
16055
16028
|
const prefix = usePrefix({ status, theme });
|
|
16056
16029
|
const searchTimeoutRef = useRef();
|
|
16030
|
+
// Vim keybindings (j/k) conflict with typing those letters in search,
|
|
16031
|
+
// so search must be disabled when vim bindings are enabled
|
|
16032
|
+
const searchEnabled = !keybindings.includes('vim');
|
|
16057
16033
|
const items = useMemo(() => normalizeChoices(config.choices), [config.choices]);
|
|
16058
16034
|
const bounds = useMemo(() => {
|
|
16059
16035
|
const first = items.findIndex(isSelectable);
|
|
@@ -16077,12 +16053,12 @@ var select = createPrompt((config, done) => {
|
|
|
16077
16053
|
setStatus('done');
|
|
16078
16054
|
done(selectedChoice.value);
|
|
16079
16055
|
}
|
|
16080
|
-
else if (isUpKey(key) || isDownKey(key)) {
|
|
16056
|
+
else if (isUpKey(key, keybindings) || isDownKey(key, keybindings)) {
|
|
16081
16057
|
rl.clearLine(0);
|
|
16082
16058
|
if (loop ||
|
|
16083
|
-
(isUpKey(key) && active !== bounds.first) ||
|
|
16084
|
-
(isDownKey(key) && active !== bounds.last)) {
|
|
16085
|
-
const offset = isUpKey(key) ? -1 : 1;
|
|
16059
|
+
(isUpKey(key, keybindings) && active !== bounds.first) ||
|
|
16060
|
+
(isDownKey(key, keybindings) && active !== bounds.last)) {
|
|
16061
|
+
const offset = isUpKey(key, keybindings) ? -1 : 1;
|
|
16086
16062
|
let next = active;
|
|
16087
16063
|
do {
|
|
16088
16064
|
next = (next + offset + items.length) % items.length;
|
|
@@ -16111,8 +16087,7 @@ var select = createPrompt((config, done) => {
|
|
|
16111
16087
|
else if (isBackspaceKey(key)) {
|
|
16112
16088
|
rl.clearLine(0);
|
|
16113
16089
|
}
|
|
16114
|
-
else {
|
|
16115
|
-
// Default to search
|
|
16090
|
+
else if (searchEnabled) {
|
|
16116
16091
|
const searchTerm = rl.line.toLowerCase();
|
|
16117
16092
|
const matchIndex = items.findIndex((item) => {
|
|
16118
16093
|
if (Separator.isSeparator(item) || !isSelectable(item))
|
|
@@ -16131,16 +16106,20 @@ var select = createPrompt((config, done) => {
|
|
|
16131
16106
|
clearTimeout(searchTimeoutRef.current);
|
|
16132
16107
|
}, []);
|
|
16133
16108
|
const message = theme.style.message(config.message, status);
|
|
16134
|
-
let
|
|
16135
|
-
|
|
16136
|
-
if (theme.helpMode
|
|
16137
|
-
|
|
16138
|
-
|
|
16139
|
-
|
|
16140
|
-
|
|
16109
|
+
let helpLine;
|
|
16110
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
16111
|
+
if (theme.helpMode !== 'never') {
|
|
16112
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
16113
|
+
if (config.instructions) {
|
|
16114
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
16115
|
+
const { pager, navigation } = config.instructions;
|
|
16116
|
+
helpLine = theme.style.help(items.length > pageSize ? pager : navigation);
|
|
16141
16117
|
}
|
|
16142
16118
|
else {
|
|
16143
|
-
|
|
16119
|
+
helpLine = theme.style.keysHelpTip([
|
|
16120
|
+
['↑↓', 'navigate'],
|
|
16121
|
+
['⏎', 'select'],
|
|
16122
|
+
]);
|
|
16144
16123
|
}
|
|
16145
16124
|
}
|
|
16146
16125
|
let separatorCount = 0;
|
|
@@ -16165,12 +16144,22 @@ var select = createPrompt((config, done) => {
|
|
|
16165
16144
|
loop,
|
|
16166
16145
|
});
|
|
16167
16146
|
if (status === 'done') {
|
|
16168
|
-
return
|
|
16147
|
+
return [prefix, message, theme.style.answer(selectedChoice.short)]
|
|
16148
|
+
.filter(Boolean)
|
|
16149
|
+
.join(' ');
|
|
16169
16150
|
}
|
|
16170
|
-
const
|
|
16171
|
-
|
|
16172
|
-
|
|
16173
|
-
|
|
16151
|
+
const { description } = selectedChoice;
|
|
16152
|
+
const lines = [
|
|
16153
|
+
[prefix, message].filter(Boolean).join(' '),
|
|
16154
|
+
page,
|
|
16155
|
+
' ',
|
|
16156
|
+
description ? theme.style.description(description) : '',
|
|
16157
|
+
helpLine,
|
|
16158
|
+
]
|
|
16159
|
+
.filter(Boolean)
|
|
16160
|
+
.join('\n')
|
|
16161
|
+
.trimEnd();
|
|
16162
|
+
return `${lines}${cursorHide}`;
|
|
16174
16163
|
});
|
|
16175
16164
|
|
|
16176
16165
|
var cjs = {};
|