@reliverse/relinka 1.2.0 → 1.2.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 +37 -41
- package/dist-npm/components/core/core.d.ts +2 -0
- package/dist-npm/components/core/core.js +2 -0
- package/dist-npm/{utils/constants.d.ts → components/levels/levels.d.ts} +1 -1
- package/dist-npm/components/{prompts/create.d.ts → modes/basic.d.ts} +3 -3
- package/dist-npm/components/{instance → modes}/basic.js +4 -4
- package/dist-npm/components/{instance → modes}/browser.d.ts +2 -2
- package/dist-npm/components/modes/browser.js +12 -0
- package/dist-npm/components/modes/shared.d.ts +5 -0
- package/dist-npm/components/modes/shared.js +2 -0
- package/dist-npm/components/{prompts → relinka}/relinka.d.ts +2 -4
- package/dist-npm/components/{prompts → relinka}/relinka.js +1 -7
- package/dist-npm/components/{instance/reporter → reporters}/basic.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/basic.js +2 -2
- package/dist-npm/components/{instance/reporter → reporters}/browser.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/fancy.d.ts +3 -3
- package/dist-npm/components/{instance/reporter → reporters}/fancy.js +5 -7
- package/dist-npm/main.d.ts +8 -1
- package/dist-npm/main.js +34 -1
- package/dist-npm/types/mod.d.ts +42 -0
- package/dist-npm/utils/color.js +4 -1
- package/dist-npm/utils/mod.d.ts +3 -0
- package/dist-npm/utils/mod.js +9 -0
- package/package.json +1 -1
- package/dist-npm/components/anykey/index.d.ts +0 -7
- package/dist-npm/components/anykey/index.js +0 -61
- package/dist-npm/components/block/block.d.ts +0 -10
- package/dist-npm/components/block/block.js +0 -52
- package/dist-npm/components/checkbox/index.d.ts +0 -3
- package/dist-npm/components/checkbox/index.js +0 -217
- package/dist-npm/components/confirm/confirm-main.d.ts +0 -3
- package/dist-npm/components/confirm/confirm-main.js +0 -98
- package/dist-npm/components/confirm/confirm-three.d.ts +0 -13
- package/dist-npm/components/confirm/confirm-three.js +0 -26
- package/dist-npm/components/confirm/index.d.ts +0 -2
- package/dist-npm/components/confirm/index.js +0 -41
- package/dist-npm/components/core/Separator.d.ts +0 -6
- package/dist-npm/components/core/Separator.js +0 -18
- package/dist-npm/components/core/create-prompt.d.ts +0 -4
- package/dist-npm/components/core/create-prompt.js +0 -107
- package/dist-npm/components/core/errors.d.ts +0 -20
- package/dist-npm/components/core/errors.js +0 -21
- package/dist-npm/components/core/hook-engine.d.ts +0 -23
- package/dist-npm/components/core/hook-engine.js +0 -109
- package/dist-npm/components/core/index.d.ts +0 -13
- package/dist-npm/components/core/index.js +0 -12
- package/dist-npm/components/core/key.d.ts +0 -10
- package/dist-npm/components/core/key.js +0 -16
- package/dist-npm/components/core/lines.d.ts +0 -14
- package/dist-npm/components/core/lines.js +0 -52
- package/dist-npm/components/core/make-theme.d.ts +0 -3
- package/dist-npm/components/core/make-theme.js +0 -28
- package/dist-npm/components/core/position.d.ts +0 -12
- package/dist-npm/components/core/position.js +0 -29
- package/dist-npm/components/core/promise-polyfill.d.ts +0 -7
- package/dist-npm/components/core/promise-polyfill.js +0 -13
- package/dist-npm/components/core/screen-manager.d.ts +0 -14
- package/dist-npm/components/core/screen-manager.js +0 -67
- package/dist-npm/components/core/theme.d.ts +0 -21
- package/dist-npm/components/core/theme.js +0 -24
- package/dist-npm/components/core/use-effect.d.ts +0 -2
- package/dist-npm/components/core/use-effect.js +0 -11
- package/dist-npm/components/core/use-keypress.d.ts +0 -3
- package/dist-npm/components/core/use-keypress.js +0 -21
- package/dist-npm/components/core/use-memo.d.ts +0 -1
- package/dist-npm/components/core/use-memo.js +0 -12
- package/dist-npm/components/core/use-pagination.d.ts +0 -11
- package/dist-npm/components/core/use-pagination.js +0 -34
- package/dist-npm/components/core/use-prefix.d.ts +0 -5
- package/dist-npm/components/core/use-prefix.js +0 -42
- package/dist-npm/components/core/use-ref.d.ts +0 -6
- package/dist-npm/components/core/use-ref.js +0 -4
- package/dist-npm/components/core/use-state.d.ts +0 -4
- package/dist-npm/components/core/use-state.js +0 -17
- package/dist-npm/components/core/useKeyPress.d.ts +0 -4
- package/dist-npm/components/core/useKeyPress.js +0 -16
- package/dist-npm/components/core/usePromptState.d.ts +0 -6
- package/dist-npm/components/core/usePromptState.js +0 -10
- package/dist-npm/components/core/utils.d.ts +0 -2
- package/dist-npm/components/core/utils.js +0 -11
- package/dist-npm/components/date/date.d.ts +0 -6
- package/dist-npm/components/date/date.js +0 -210
- package/dist-npm/components/editor/index.d.ts +0 -2
- package/dist-npm/components/editor/index.js +0 -78
- package/dist-npm/components/expand/index.d.ts +0 -3
- package/dist-npm/components/expand/index.js +0 -119
- package/dist-npm/components/figures/index.d.ts +0 -465
- package/dist-npm/components/figures/index.js +0 -299
- package/dist-npm/components/input/index.d.ts +0 -2
- package/dist-npm/components/input/index.js +0 -66
- package/dist-npm/components/input/text-main.d.ts +0 -3
- package/dist-npm/components/input/text-main.js +0 -103
- package/dist-npm/components/input/text.d.ts +0 -11
- package/dist-npm/components/input/text.js +0 -26
- package/dist-npm/components/instance/basic.d.ts +0 -8
- package/dist-npm/components/instance/browser.js +0 -18
- package/dist-npm/components/instance/shared.d.ts +0 -6
- package/dist-npm/components/instance/shared.js +0 -2
- package/dist-npm/components/mono/mono.d.ts +0 -5
- package/dist-npm/components/mono/mono.js +0 -64
- package/dist-npm/components/mono/monoTwo.d.ts +0 -30
- package/dist-npm/components/mono/monoTwo.js +0 -37
- package/dist-npm/components/multiselect/group-multiselect.d.ts +0 -23
- package/dist-npm/components/multiselect/group-multiselect.js +0 -58
- package/dist-npm/components/multiselect/multi-select-two.d.ts +0 -3
- package/dist-npm/components/multiselect/multi-select-two.js +0 -111
- package/dist-npm/components/multiselect/multi-select.d.ts +0 -21
- package/dist-npm/components/multiselect/multi-select.js +0 -45
- package/dist-npm/components/multiselect/multiselect-main.d.ts +0 -18
- package/dist-npm/components/multiselect/multiselect-main.js +0 -166
- package/dist-npm/components/multiselect/num-multi-select.d.ts +0 -3
- package/dist-npm/components/multiselect/num-multi-select.js +0 -111
- package/dist-npm/components/multiselect/num-multiselect-main.d.ts +0 -6
- package/dist-npm/components/multiselect/num-multiselect-main.js +0 -28
- package/dist-npm/components/next-steps/next-steps.d.ts +0 -2
- package/dist-npm/components/next-steps/next-steps.js +0 -24
- package/dist-npm/components/number/index.d.ts +0 -2
- package/dist-npm/components/number/index.js +0 -100
- package/dist-npm/components/number/number-main.d.ts +0 -3
- package/dist-npm/components/number/number-main.js +0 -95
- package/dist-npm/components/password/index.d.ts +0 -2
- package/dist-npm/components/password/index.js +0 -59
- package/dist-npm/components/password/password-main.d.ts +0 -3
- package/dist-npm/components/password/password-main.js +0 -119
- package/dist-npm/components/password/password-three.d.ts +0 -13
- package/dist-npm/components/password/password-three.js +0 -28
- package/dist-npm/components/progressbar/ProgressBar.d.ts +0 -22
- package/dist-npm/components/progressbar/ProgressBar.js +0 -53
- package/dist-npm/components/progressbar/helper.d.ts +0 -6
- package/dist-npm/components/progressbar/helper.js +0 -38
- package/dist-npm/components/progressbar/index.d.ts +0 -2
- package/dist-npm/components/progressbar/index.js +0 -1
- package/dist-npm/components/prompts/create.js +0 -35
- package/dist-npm/components/prompts/index.d.ts +0 -49
- package/dist-npm/components/prompts/index.js +0 -46
- package/dist-npm/components/prompts/prompt.d.ts +0 -36
- package/dist-npm/components/prompts/prompt.js +0 -232
- package/dist-npm/components/prompts/promptTwo.d.ts +0 -92
- package/dist-npm/components/prompts/promptTwo.js +0 -653
- package/dist-npm/components/range/range.d.ts +0 -62
- package/dist-npm/components/range/range.js +0 -270
- package/dist-npm/components/rawlist/index.d.ts +0 -3
- package/dist-npm/components/rawlist/index.js +0 -104
- package/dist-npm/components/results/results.d.ts +0 -10
- package/dist-npm/components/results/results.js +0 -34
- package/dist-npm/components/search/index.d.ts +0 -3
- package/dist-npm/components/search/index.js +0 -186
- package/dist-npm/components/select/index.d.ts +0 -3
- package/dist-npm/components/select/index.js +0 -176
- package/dist-npm/components/select/num-select-main.d.ts +0 -8
- package/dist-npm/components/select/num-select-main.js +0 -30
- package/dist-npm/components/select/num-select.d.ts +0 -5
- package/dist-npm/components/select/num-select.js +0 -125
- package/dist-npm/components/select/select-key.d.ts +0 -15
- package/dist-npm/components/select/select-key.js +0 -26
- package/dist-npm/components/select/select-main.d.ts +0 -19
- package/dist-npm/components/select/select-main.js +0 -151
- package/dist-npm/components/select/select-three.d.ts +0 -18
- package/dist-npm/components/select/select-three.js +0 -35
- package/dist-npm/components/select/select-two.d.ts +0 -2
- package/dist-npm/components/select/select-two.js +0 -98
- package/dist-npm/components/spinner/index.d.ts +0 -15
- package/dist-npm/components/spinner/index.js +0 -110
- package/dist-npm/components/st-end/end.d.ts +0 -2
- package/dist-npm/components/st-end/end.js +0 -35
- package/dist-npm/components/st-end/start.d.ts +0 -2
- package/dist-npm/components/st-end/start.js +0 -32
- package/dist-npm/components/toggle/index.d.ts +0 -13
- package/dist-npm/components/toggle/index.js +0 -121
- package/dist-npm/components/visual/animate/animate.d.ts +0 -13
- package/dist-npm/components/visual/animate/animate.js +0 -55
- package/dist-npm/components/visual/ascii-art/ascii-art.d.ts +0 -6
- package/dist-npm/components/visual/ascii-art/ascii-art.js +0 -12
- package/dist-npm/testing/index.d.ts +0 -18
- package/dist-npm/testing/index.js +0 -64
- package/dist-npm/types/general.d.ts +0 -134
- package/dist-npm/types/index.d.ts +0 -2
- package/dist-npm/types/index.js +0 -2
- package/dist-npm/types/keypress.d.ts +0 -52
- package/dist-npm/types/keypress.js +0 -37
- package/dist-npm/types/readline.d.ts +0 -30
- package/dist-npm/types/readline.js +0 -0
- package/dist-npm/types/relinka.d.ts +0 -30
- package/dist-npm/types/relinka.js +0 -0
- package/dist-npm/types/utils.d.ts +0 -17
- package/dist-npm/types/utils.js +0 -0
- package/dist-npm/utils/colorize.d.ts +0 -2
- package/dist-npm/utils/colorize.js +0 -130
- package/dist-npm/utils/component.d.ts +0 -101
- package/dist-npm/utils/component.js +0 -630
- package/dist-npm/utils/core.d.ts +0 -2
- package/dist-npm/utils/core.js +0 -2
- package/dist-npm/utils/decoder.d.ts +0 -14
- package/dist-npm/utils/decoder.js +0 -281
- package/dist-npm/utils/errors.d.ts +0 -1
- package/dist-npm/utils/errors.js +0 -15
- package/dist-npm/utils/keypress.d.ts +0 -7
- package/dist-npm/utils/keypress.js +0 -327
- package/dist-npm/utils/mapping.d.ts +0 -4
- package/dist-npm/utils/mapping.js +0 -49
- package/dist-npm/utils/messages.d.ts +0 -17
- package/dist-npm/utils/messages.js +0 -213
- package/dist-npm/utils/platforms.d.ts +0 -1
- package/dist-npm/utils/platforms.js +0 -22
- package/dist-npm/utils/prompt-tmp.d.ts +0 -13
- package/dist-npm/utils/prompt-tmp.js +0 -254
- package/dist-npm/utils/prompt-two.d.ts +0 -13
- package/dist-npm/utils/prompt-two.js +0 -254
- package/dist-npm/utils/readline.d.ts +0 -2
- package/dist-npm/utils/readline.js +0 -9
- package/dist-npm/utils/skeleton.d.ts +0 -7
- package/dist-npm/utils/skeleton.js +0 -145
- package/dist-npm/utils/terminal.d.ts +0 -5
- package/dist-npm/utils/terminal.js +0 -33
- package/dist-npm/utils/types.d.ts +0 -0
- package/dist-npm/utils/types.js +0 -0
- package/dist-npm/utils/utils.d.ts +0 -3
- package/dist-npm/utils/utils.js +0 -9
- package/dist-npm/utils/variants.d.ts +0 -9
- package/dist-npm/utils/variants.js +0 -49
- /package/dist-npm/{utils/constants.js → components/levels/levels.js} +0 -0
- /package/dist-npm/components/{instance/reporter → reporters}/browser.js +0 -0
- /package/dist-npm/types/{general.js → mod.js} +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
|
|
2
|
-
import { HookError, ValidationError } from "./errors.js";
|
|
3
|
-
const hookStorage = new AsyncLocalStorage();
|
|
4
|
-
function createStore(rl) {
|
|
5
|
-
const store = {
|
|
6
|
-
rl,
|
|
7
|
-
hooks: [],
|
|
8
|
-
hooksCleanup: [],
|
|
9
|
-
hooksEffect: [],
|
|
10
|
-
index: 0,
|
|
11
|
-
handleChange() {
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
return store;
|
|
15
|
-
}
|
|
16
|
-
export function withHooks(rl, cb) {
|
|
17
|
-
const store = createStore(rl);
|
|
18
|
-
return hookStorage.run(store, () => {
|
|
19
|
-
function cycle(render) {
|
|
20
|
-
store.handleChange = () => {
|
|
21
|
-
store.index = 0;
|
|
22
|
-
render();
|
|
23
|
-
};
|
|
24
|
-
store.handleChange();
|
|
25
|
-
}
|
|
26
|
-
return cb(cycle);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function getStore() {
|
|
30
|
-
const store = hookStorage.getStore();
|
|
31
|
-
if (!store) {
|
|
32
|
-
throw new HookError(
|
|
33
|
-
"[Relinka] Hook functions can only be called from within a prompt"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
return store;
|
|
37
|
-
}
|
|
38
|
-
export function readline() {
|
|
39
|
-
return getStore().rl;
|
|
40
|
-
}
|
|
41
|
-
export function withUpdates(fn) {
|
|
42
|
-
const wrapped = (...args) => {
|
|
43
|
-
const store = getStore();
|
|
44
|
-
let shouldUpdate = false;
|
|
45
|
-
const oldHandleChange = store.handleChange;
|
|
46
|
-
store.handleChange = () => {
|
|
47
|
-
shouldUpdate = true;
|
|
48
|
-
};
|
|
49
|
-
const returnValue = fn(...args);
|
|
50
|
-
if (shouldUpdate) {
|
|
51
|
-
oldHandleChange();
|
|
52
|
-
}
|
|
53
|
-
store.handleChange = oldHandleChange;
|
|
54
|
-
return returnValue;
|
|
55
|
-
};
|
|
56
|
-
return AsyncResource.bind(wrapped);
|
|
57
|
-
}
|
|
58
|
-
export function withPointer(cb) {
|
|
59
|
-
const store = getStore();
|
|
60
|
-
const { index } = store;
|
|
61
|
-
const pointer = {
|
|
62
|
-
get() {
|
|
63
|
-
return store.hooks[index];
|
|
64
|
-
},
|
|
65
|
-
set(value) {
|
|
66
|
-
store.hooks[index] = value;
|
|
67
|
-
},
|
|
68
|
-
initialized: index in store.hooks
|
|
69
|
-
};
|
|
70
|
-
const returnValue = cb(pointer);
|
|
71
|
-
store.index++;
|
|
72
|
-
return returnValue;
|
|
73
|
-
}
|
|
74
|
-
export function handleChange() {
|
|
75
|
-
getStore().handleChange();
|
|
76
|
-
}
|
|
77
|
-
export const effectScheduler = {
|
|
78
|
-
queue(cb) {
|
|
79
|
-
const store = getStore();
|
|
80
|
-
const { index } = store;
|
|
81
|
-
store.hooksEffect.push(() => {
|
|
82
|
-
store.hooksCleanup[index]?.();
|
|
83
|
-
const cleanFn = cb(readline());
|
|
84
|
-
if (cleanFn != null && typeof cleanFn !== "function") {
|
|
85
|
-
throw new ValidationError(
|
|
86
|
-
"useEffect return value must be a cleanup function or nothing."
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
store.hooksCleanup[index] = cleanFn;
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
run() {
|
|
93
|
-
const store = getStore();
|
|
94
|
-
withUpdates(() => {
|
|
95
|
-
store.hooksEffect.forEach((effect) => {
|
|
96
|
-
effect();
|
|
97
|
-
});
|
|
98
|
-
store.hooksEffect.length = 0;
|
|
99
|
-
})();
|
|
100
|
-
},
|
|
101
|
-
clearAll() {
|
|
102
|
-
const store = getStore();
|
|
103
|
-
store.hooksCleanup.forEach((cleanFn) => {
|
|
104
|
-
cleanFn?.();
|
|
105
|
-
});
|
|
106
|
-
store.hooksEffect.length = 0;
|
|
107
|
-
store.hooksCleanup.length = 0;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from "./key.js";
|
|
2
|
-
export * from "./errors.js";
|
|
3
|
-
export { usePrefix } from "./use-prefix.js";
|
|
4
|
-
export { useState } from "./use-state.js";
|
|
5
|
-
export { useEffect } from "./use-effect.js";
|
|
6
|
-
export { useMemo } from "./use-memo.js";
|
|
7
|
-
export { useRef } from "./use-ref.js";
|
|
8
|
-
export { useKeypress } from "./use-keypress.js";
|
|
9
|
-
export { makeTheme } from "./make-theme.js";
|
|
10
|
-
export type { Theme, Status } from "./theme.js";
|
|
11
|
-
export { usePagination } from "./use-pagination.js";
|
|
12
|
-
export { createPrompt } from "./create-prompt.js";
|
|
13
|
-
export { Separator } from "./Separator.js";
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./key.js";
|
|
2
|
-
export * from "./errors.js";
|
|
3
|
-
export { usePrefix } from "./use-prefix.js";
|
|
4
|
-
export { useState } from "./use-state.js";
|
|
5
|
-
export { useEffect } from "./use-effect.js";
|
|
6
|
-
export { useMemo } from "./use-memo.js";
|
|
7
|
-
export { useRef } from "./use-ref.js";
|
|
8
|
-
export { useKeypress } from "./use-keypress.js";
|
|
9
|
-
export { makeTheme } from "./make-theme.js";
|
|
10
|
-
export { usePagination } from "./use-pagination.js";
|
|
11
|
-
export { createPrompt } from "./create-prompt.js";
|
|
12
|
-
export { Separator } from "./Separator.js";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type KeypressEvent = {
|
|
2
|
-
name: string;
|
|
3
|
-
ctrl: boolean;
|
|
4
|
-
};
|
|
5
|
-
export declare const isUpKey: (key: KeypressEvent) => boolean;
|
|
6
|
-
export declare const isDownKey: (key: KeypressEvent) => boolean;
|
|
7
|
-
export declare const isSpaceKey: (key: KeypressEvent) => boolean;
|
|
8
|
-
export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
|
|
9
|
-
export declare const isNumberKey: (key: KeypressEvent) => boolean;
|
|
10
|
-
export declare const isEnterKey: (key: KeypressEvent) => boolean;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export const isUpKey = (key) => (
|
|
2
|
-
|
|
3
|
-
key.name === "up" ||
|
|
4
|
-
key.name === "k" ||
|
|
5
|
-
key.ctrl && key.name === "p"
|
|
6
|
-
);
|
|
7
|
-
export const isDownKey = (key) => (
|
|
8
|
-
|
|
9
|
-
key.name === "down" ||
|
|
10
|
-
key.name === "j" ||
|
|
11
|
-
key.ctrl && key.name === "n"
|
|
12
|
-
);
|
|
13
|
-
export const isSpaceKey = (key) => key.name === "space";
|
|
14
|
-
export const isBackspaceKey = (key) => key.name === "backspace";
|
|
15
|
-
export const isNumberKey = (key) => "123456789".includes(key.name);
|
|
16
|
-
export const isEnterKey = (key) => key.name === "enter" || key.name === "return";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type Prettify } from "../../types/index.js";
|
|
2
|
-
export type Layout<T> = {
|
|
3
|
-
item: T;
|
|
4
|
-
index: number;
|
|
5
|
-
isActive: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function lines<T>({ items, width, renderItem, active, position: requested, pageSize, }: {
|
|
8
|
-
items: readonly T[];
|
|
9
|
-
width: number;
|
|
10
|
-
renderItem: (layout: Prettify<Layout<T>>) => string;
|
|
11
|
-
active: number;
|
|
12
|
-
position: number;
|
|
13
|
-
pageSize: number;
|
|
14
|
-
}): string[];
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { breakLines } from "./utils.js";
|
|
2
|
-
function split(content, width) {
|
|
3
|
-
return breakLines(content, width).split("\n");
|
|
4
|
-
}
|
|
5
|
-
function rotate(count, items) {
|
|
6
|
-
const max = items.length;
|
|
7
|
-
const offset = (count % max + max) % max;
|
|
8
|
-
return [...items.slice(offset), ...items.slice(0, offset)];
|
|
9
|
-
}
|
|
10
|
-
export function lines({
|
|
11
|
-
items,
|
|
12
|
-
width,
|
|
13
|
-
renderItem,
|
|
14
|
-
active,
|
|
15
|
-
position: requested,
|
|
16
|
-
pageSize
|
|
17
|
-
}) {
|
|
18
|
-
const layouts = items.map((item, index) => ({
|
|
19
|
-
item,
|
|
20
|
-
index,
|
|
21
|
-
isActive: index === active
|
|
22
|
-
}));
|
|
23
|
-
const layoutsInPage = rotate(active - requested, layouts).slice(0, pageSize);
|
|
24
|
-
const renderItemAt = (index) => layoutsInPage[index] == null ? [] : split(renderItem(layoutsInPage[index]), width);
|
|
25
|
-
const pageBuffer = Array.from({ length: pageSize });
|
|
26
|
-
const activeItem = renderItemAt(requested).slice(0, pageSize);
|
|
27
|
-
const position = requested + activeItem.length <= pageSize ? requested : pageSize - activeItem.length;
|
|
28
|
-
pageBuffer.splice(position, activeItem.length, ...activeItem);
|
|
29
|
-
let bufferPointer = position + activeItem.length;
|
|
30
|
-
let layoutPointer = requested + 1;
|
|
31
|
-
while (bufferPointer < pageSize && layoutPointer < layoutsInPage.length) {
|
|
32
|
-
for (const line of renderItemAt(layoutPointer)) {
|
|
33
|
-
pageBuffer[bufferPointer++] = line;
|
|
34
|
-
if (bufferPointer >= pageSize) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
layoutPointer++;
|
|
39
|
-
}
|
|
40
|
-
bufferPointer = position - 1;
|
|
41
|
-
layoutPointer = requested - 1;
|
|
42
|
-
while (bufferPointer >= 0 && layoutPointer >= 0) {
|
|
43
|
-
for (const line of renderItemAt(layoutPointer).reverse()) {
|
|
44
|
-
pageBuffer[bufferPointer--] = line;
|
|
45
|
-
if (bufferPointer < 0) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
layoutPointer--;
|
|
50
|
-
}
|
|
51
|
-
return pageBuffer.filter((line) => typeof line === "string");
|
|
52
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Prettify, PartialDeep } from "../../types/index.js";
|
|
2
|
-
import { type Theme } from "./theme.js";
|
|
3
|
-
export declare function makeTheme<SpecificTheme extends object>(...themes: readonly (undefined | PartialDeep<Theme<SpecificTheme>>)[]): Prettify<Theme<SpecificTheme>>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { defaultTheme } from "./theme.js";
|
|
2
|
-
function isPlainObject(value) {
|
|
3
|
-
if (typeof value !== "object" || value === null) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
let proto = value;
|
|
7
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
8
|
-
proto = Object.getPrototypeOf(proto);
|
|
9
|
-
}
|
|
10
|
-
return Object.getPrototypeOf(value) === proto;
|
|
11
|
-
}
|
|
12
|
-
function deepMerge(...objects) {
|
|
13
|
-
const output = {};
|
|
14
|
-
for (const obj of objects) {
|
|
15
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
16
|
-
const prevValue = output[key];
|
|
17
|
-
output[key] = isPlainObject(prevValue) && isPlainObject(value) ? deepMerge(prevValue, value) : value;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
|
-
export function makeTheme(...themes) {
|
|
23
|
-
const themesToMerge = [
|
|
24
|
-
defaultTheme,
|
|
25
|
-
...themes.filter((theme) => theme != null)
|
|
26
|
-
];
|
|
27
|
-
return deepMerge(...themesToMerge);
|
|
28
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare function finite({ active, pageSize, total, }: {
|
|
2
|
-
active: number;
|
|
3
|
-
pageSize: number;
|
|
4
|
-
total: number;
|
|
5
|
-
}): number;
|
|
6
|
-
export declare function infinite({ active, lastActive, total, pageSize, pointer, }: {
|
|
7
|
-
active: number;
|
|
8
|
-
lastActive: number;
|
|
9
|
-
total: number;
|
|
10
|
-
pageSize: number;
|
|
11
|
-
pointer: number;
|
|
12
|
-
}): number;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export function finite({
|
|
2
|
-
active,
|
|
3
|
-
pageSize,
|
|
4
|
-
total
|
|
5
|
-
}) {
|
|
6
|
-
const middle = Math.floor(pageSize / 2);
|
|
7
|
-
if (total <= pageSize || active < middle) {
|
|
8
|
-
return active;
|
|
9
|
-
}
|
|
10
|
-
if (active >= total - middle) {
|
|
11
|
-
return active + pageSize - total;
|
|
12
|
-
}
|
|
13
|
-
return middle;
|
|
14
|
-
}
|
|
15
|
-
export function infinite({
|
|
16
|
-
active,
|
|
17
|
-
lastActive,
|
|
18
|
-
total,
|
|
19
|
-
pageSize,
|
|
20
|
-
pointer
|
|
21
|
-
}) {
|
|
22
|
-
if (total <= pageSize) {
|
|
23
|
-
return active;
|
|
24
|
-
}
|
|
25
|
-
if (lastActive < active && active - lastActive < pageSize) {
|
|
26
|
-
return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
|
|
27
|
-
}
|
|
28
|
-
return pointer;
|
|
29
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { RelinkaReadline } from "../../types/index.js";
|
|
2
|
-
export default class ScreenManager {
|
|
3
|
-
private readonly rl;
|
|
4
|
-
private height;
|
|
5
|
-
private extraLinesUnderPrompt;
|
|
6
|
-
private cursorPos;
|
|
7
|
-
constructor(rl: RelinkaReadline);
|
|
8
|
-
write(content: string): void;
|
|
9
|
-
render(content: string, bottomContent?: string): void;
|
|
10
|
-
checkCursorPos(): void;
|
|
11
|
-
done({ clearContent }: {
|
|
12
|
-
clearContent: boolean;
|
|
13
|
-
}): void;
|
|
14
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import ansiEscapes from "ansi-escapes";
|
|
2
|
-
import stripAnsi from "strip-ansi";
|
|
3
|
-
import { breakLines, readlineWidth } from "./utils.js";
|
|
4
|
-
const height = (content) => content.split("\n").length;
|
|
5
|
-
const lastLine = (content) => content.split("\n").pop() ?? "";
|
|
6
|
-
function cursorDown(n) {
|
|
7
|
-
return n > 0 ? ansiEscapes.cursorDown(n) : "";
|
|
8
|
-
}
|
|
9
|
-
export default class ScreenManager {
|
|
10
|
-
constructor(rl) {
|
|
11
|
-
this.rl = rl;
|
|
12
|
-
this.rl = rl;
|
|
13
|
-
this.cursorPos = rl.getCursorPos();
|
|
14
|
-
}
|
|
15
|
-
// These variables are keeping information to allow correct prompt re-rendering
|
|
16
|
-
height = 0;
|
|
17
|
-
extraLinesUnderPrompt = 0;
|
|
18
|
-
cursorPos;
|
|
19
|
-
write(content) {
|
|
20
|
-
this.rl.output.unmute();
|
|
21
|
-
this.rl.output.write(content);
|
|
22
|
-
this.rl.output.mute();
|
|
23
|
-
}
|
|
24
|
-
render(content, bottomContent = "") {
|
|
25
|
-
const promptLine = lastLine(content);
|
|
26
|
-
const rawPromptLine = stripAnsi(promptLine);
|
|
27
|
-
let prompt = rawPromptLine;
|
|
28
|
-
if (this.rl.line.length > 0) {
|
|
29
|
-
prompt = prompt.slice(0, -this.rl.line.length);
|
|
30
|
-
}
|
|
31
|
-
this.rl.setPrompt(prompt);
|
|
32
|
-
this.cursorPos = this.rl.getCursorPos();
|
|
33
|
-
const width = readlineWidth();
|
|
34
|
-
content = breakLines(content, width);
|
|
35
|
-
bottomContent = breakLines(bottomContent, width);
|
|
36
|
-
if (rawPromptLine.length % width === 0) {
|
|
37
|
-
content += "\n";
|
|
38
|
-
}
|
|
39
|
-
let output = content + (bottomContent ? "\n" + bottomContent : "");
|
|
40
|
-
const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
|
|
41
|
-
const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
|
|
42
|
-
if (bottomContentHeight > 0) {
|
|
43
|
-
output += ansiEscapes.cursorUp(bottomContentHeight);
|
|
44
|
-
}
|
|
45
|
-
output += ansiEscapes.cursorTo(this.cursorPos.cols);
|
|
46
|
-
this.write(
|
|
47
|
-
cursorDown(this.extraLinesUnderPrompt) + ansiEscapes.eraseLines(this.height) + output
|
|
48
|
-
);
|
|
49
|
-
this.extraLinesUnderPrompt = bottomContentHeight;
|
|
50
|
-
this.height = height(output);
|
|
51
|
-
}
|
|
52
|
-
checkCursorPos() {
|
|
53
|
-
const cursorPos = this.rl.getCursorPos();
|
|
54
|
-
if (cursorPos.cols !== this.cursorPos.cols) {
|
|
55
|
-
this.write(ansiEscapes.cursorTo(cursorPos.cols));
|
|
56
|
-
this.cursorPos = cursorPos;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
done({ clearContent }) {
|
|
60
|
-
this.rl.setPrompt("");
|
|
61
|
-
let output = cursorDown(this.extraLinesUnderPrompt);
|
|
62
|
-
output += clearContent ? ansiEscapes.eraseLines(this.height) : "\n";
|
|
63
|
-
output += ansiEscapes.cursorShow;
|
|
64
|
-
this.write(output);
|
|
65
|
-
this.rl.close();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Prettify } from "../../types/index.js";
|
|
2
|
-
export type Status = "loading" | "idle" | "done" | (string & {});
|
|
3
|
-
type DefaultTheme = {
|
|
4
|
-
prefix: string | Prettify<Omit<Record<Status, string>, "loading">>;
|
|
5
|
-
spinner: {
|
|
6
|
-
interval: number;
|
|
7
|
-
frames: string[];
|
|
8
|
-
};
|
|
9
|
-
style: {
|
|
10
|
-
answer: (text: string) => string;
|
|
11
|
-
message: (text: string, status: Status) => string;
|
|
12
|
-
error: (text: string) => string;
|
|
13
|
-
defaultAnswer: (text: string) => string;
|
|
14
|
-
help: (text: string) => string;
|
|
15
|
-
highlight: (text: string) => string;
|
|
16
|
-
key: (text: string) => string;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
|
|
20
|
-
export declare const defaultTheme: DefaultTheme;
|
|
21
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import colors from "picocolors";
|
|
2
|
-
import figures from "../../components/figures/index.js";
|
|
3
|
-
export const defaultTheme = {
|
|
4
|
-
prefix: {
|
|
5
|
-
idle: colors.blue("?"),
|
|
6
|
-
|
|
7
|
-
done: colors.green(figures.tick)
|
|
8
|
-
},
|
|
9
|
-
spinner: {
|
|
10
|
-
interval: 80,
|
|
11
|
-
frames: ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"].map(
|
|
12
|
-
(frame) => colors.yellow(frame)
|
|
13
|
-
)
|
|
14
|
-
},
|
|
15
|
-
style: {
|
|
16
|
-
answer: colors.cyan,
|
|
17
|
-
message: colors.bold,
|
|
18
|
-
error: (text) => colors.red(`> ${text}`),
|
|
19
|
-
defaultAnswer: (text) => colors.dim(`(${text})`),
|
|
20
|
-
help: colors.dim,
|
|
21
|
-
highlight: colors.cyan,
|
|
22
|
-
key: (text) => colors.cyan(colors.bold(`<${text}>`))
|
|
23
|
-
}
|
|
24
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { withPointer, effectScheduler } from "./hook-engine.js";
|
|
2
|
-
export function useEffect(cb, depArray) {
|
|
3
|
-
withPointer((pointer) => {
|
|
4
|
-
const oldDeps = pointer.get();
|
|
5
|
-
const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
|
|
6
|
-
if (hasChanged) {
|
|
7
|
-
effectScheduler.queue(cb);
|
|
8
|
-
}
|
|
9
|
-
pointer.set(depArray);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { withUpdates } from "./hook-engine.js";
|
|
2
|
-
import { useEffect } from "./use-effect.js";
|
|
3
|
-
import { useRef } from "./use-ref.js";
|
|
4
|
-
export function useKeypress(userHandler) {
|
|
5
|
-
const signal = useRef(userHandler);
|
|
6
|
-
signal.current = userHandler;
|
|
7
|
-
useEffect((rl) => {
|
|
8
|
-
let ignore = false;
|
|
9
|
-
const handler = withUpdates((_input, event) => {
|
|
10
|
-
if (ignore) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
void signal.current(event, rl);
|
|
14
|
-
});
|
|
15
|
-
rl.input.on("keypress", handler);
|
|
16
|
-
return () => {
|
|
17
|
-
ignore = true;
|
|
18
|
-
rl.input.removeListener("keypress", handler);
|
|
19
|
-
};
|
|
20
|
-
}, []);
|
|
21
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useMemo<Value>(fn: () => Value, dependencies: readonly unknown[]): Value;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { withPointer } from "./hook-engine.js";
|
|
2
|
-
export function useMemo(fn, dependencies) {
|
|
3
|
-
return withPointer((pointer) => {
|
|
4
|
-
const prev = pointer.get();
|
|
5
|
-
if (!prev || prev.dependencies.length !== dependencies.length || prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
|
|
6
|
-
const value = fn();
|
|
7
|
-
pointer.set({ value, dependencies });
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
return prev.value;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Prettify } from "../../types/index.js";
|
|
2
|
-
import { type Layout } from "./lines.js";
|
|
3
|
-
import { type Theme } from "./theme.js";
|
|
4
|
-
export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
|
|
5
|
-
items: readonly T[];
|
|
6
|
-
active: number;
|
|
7
|
-
renderItem: (layout: Prettify<Layout<T>>) => string;
|
|
8
|
-
pageSize: number;
|
|
9
|
-
loop?: boolean;
|
|
10
|
-
theme?: Theme;
|
|
11
|
-
}): string;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { lines } from "./lines.js";
|
|
2
|
-
import { finite, infinite } from "./position.js";
|
|
3
|
-
import { useRef } from "./use-ref.js";
|
|
4
|
-
import { readlineWidth } from "./utils.js";
|
|
5
|
-
export function usePagination({
|
|
6
|
-
items,
|
|
7
|
-
active,
|
|
8
|
-
renderItem,
|
|
9
|
-
pageSize,
|
|
10
|
-
loop = true
|
|
11
|
-
}) {
|
|
12
|
-
const state = useRef({ position: 0, lastActive: 0 });
|
|
13
|
-
const position = loop ? infinite({
|
|
14
|
-
active,
|
|
15
|
-
lastActive: state.current.lastActive,
|
|
16
|
-
total: items.length,
|
|
17
|
-
pageSize,
|
|
18
|
-
pointer: state.current.position
|
|
19
|
-
}) : finite({
|
|
20
|
-
active,
|
|
21
|
-
total: items.length,
|
|
22
|
-
pageSize
|
|
23
|
-
});
|
|
24
|
-
state.current.position = position;
|
|
25
|
-
state.current.lastActive = active;
|
|
26
|
-
return lines({
|
|
27
|
-
items,
|
|
28
|
-
width: readlineWidth(),
|
|
29
|
-
renderItem,
|
|
30
|
-
active,
|
|
31
|
-
position,
|
|
32
|
-
pageSize
|
|
33
|
-
}).join("\n");
|
|
34
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AsyncResource } from "node:async_hooks";
|
|
2
|
-
import { makeTheme } from "./make-theme.js";
|
|
3
|
-
import { useEffect } from "./use-effect.js";
|
|
4
|
-
import { useState } from "./use-state.js";
|
|
5
|
-
export function usePrefix({
|
|
6
|
-
status = "idle",
|
|
7
|
-
theme
|
|
8
|
-
}) {
|
|
9
|
-
const [showLoader, setShowLoader] = useState(false);
|
|
10
|
-
const [tick, setTick] = useState(0);
|
|
11
|
-
const { prefix, spinner } = makeTheme(theme);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
if (status === "loading") {
|
|
14
|
-
let tickInterval;
|
|
15
|
-
let inc = -1;
|
|
16
|
-
const delayTimeout = setTimeout(
|
|
17
|
-
AsyncResource.bind(() => {
|
|
18
|
-
setShowLoader(true);
|
|
19
|
-
tickInterval = setInterval(
|
|
20
|
-
AsyncResource.bind(() => {
|
|
21
|
-
inc = inc + 1;
|
|
22
|
-
setTick(inc % spinner.frames.length);
|
|
23
|
-
}),
|
|
24
|
-
spinner.interval
|
|
25
|
-
);
|
|
26
|
-
}),
|
|
27
|
-
300
|
|
28
|
-
);
|
|
29
|
-
return () => {
|
|
30
|
-
clearTimeout(delayTimeout);
|
|
31
|
-
clearInterval(tickInterval);
|
|
32
|
-
};
|
|
33
|
-
} else {
|
|
34
|
-
setShowLoader(false);
|
|
35
|
-
}
|
|
36
|
-
}, [status]);
|
|
37
|
-
if (showLoader) {
|
|
38
|
-
return spinner.frames[tick];
|
|
39
|
-
}
|
|
40
|
-
const iconName = status === "loading" ? "idle" : status;
|
|
41
|
-
return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix.idle;
|
|
42
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
type NotFunction<T> = T extends (...args: never) => unknown ? never : T;
|
|
2
|
-
export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
|
|
3
|
-
export declare function useState<Value>(defaultValue?: NotFunction<Value> | (() => Value)): [Value | undefined, (newValue?: Value) => void];
|
|
4
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { withPointer, handleChange } from "./hook-engine.js";
|
|
2
|
-
export function useState(defaultValue) {
|
|
3
|
-
return withPointer((pointer) => {
|
|
4
|
-
const setFn = (newValue) => {
|
|
5
|
-
if (pointer.get() !== newValue) {
|
|
6
|
-
pointer.set(newValue);
|
|
7
|
-
handleChange();
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
if (pointer.initialized) {
|
|
11
|
-
return [pointer.get(), setFn];
|
|
12
|
-
}
|
|
13
|
-
const value = typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
14
|
-
pointer.set(value);
|
|
15
|
-
return [value, setFn];
|
|
16
|
-
});
|
|
17
|
-
}
|