@reliverse/relinka 1.1.4 → 1.1.6
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-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -86
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -168
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -86
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -98
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -98
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -24
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -96
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -120
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -125
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -95
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.d.ts +1 -1
- package/dist-npm/components/st-end/end.js +26 -35
- package/dist-npm/components/st-end/start.d.ts +1 -1
- package/dist-npm/components/st-end/start.js +15 -30
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.d.ts +2 -1
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,55 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "@figliolia/chalk-animation";
|
|
4
|
-
import { msg } from "../../../utils/messages.js";
|
|
5
|
-
import { deleteLastLine } from "../../../utils/terminal.js";
|
|
1
|
+
import {ChalkAnimation} from '@figliolia/chalk-animation';
|
|
2
|
+
|
|
6
3
|
export const animationMap = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
rainbow: ChalkAnimation.rainbow,
|
|
5
|
+
pulse: ChalkAnimation.pulse,
|
|
6
|
+
glitch: ChalkAnimation.glitch,
|
|
7
|
+
radar: ChalkAnimation.radar,
|
|
8
|
+
neon: ChalkAnimation.neon,
|
|
9
|
+
karaoke: ChalkAnimation.karaoke,
|
|
13
10
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const delayPerCharacter = 50;
|
|
17
|
-
return baseDelay + text.length * delayPerCharacter;
|
|
18
|
-
}
|
|
19
|
-
export async function animateText({
|
|
20
|
-
title,
|
|
21
|
-
anim,
|
|
22
|
-
delay,
|
|
23
|
-
type = "M_INFO",
|
|
24
|
-
titleColor = "cyanBright",
|
|
25
|
-
titleTypography = "bold",
|
|
26
|
-
border = true,
|
|
27
|
-
borderColor = "viceGradient"
|
|
28
|
-
}) {
|
|
29
|
-
const finalDelay = delay ?? calculateDelay(title);
|
|
30
|
-
const animation = animationMap[anim](title);
|
|
31
|
-
try {
|
|
32
|
-
await new Promise((resolve) => {
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
animation.stop();
|
|
35
|
-
deleteLastLine();
|
|
36
|
-
if (title.includes("\u2502 ")) {
|
|
37
|
-
title = title.replace("\u2502 ", "");
|
|
38
|
-
} else if (title.includes("\u2139 ")) {
|
|
39
|
-
title = title.replace("\u2139 ", "");
|
|
40
|
-
}
|
|
41
|
-
msg({
|
|
42
|
-
type,
|
|
43
|
-
title,
|
|
44
|
-
titleColor,
|
|
45
|
-
titleTypography,
|
|
46
|
-
borderColor,
|
|
47
|
-
border
|
|
48
|
-
});
|
|
49
|
-
resolve();
|
|
50
|
-
}, finalDelay);
|
|
51
|
-
});
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error("Animation failed to complete.", error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
11
|
+
|
|
12
|
+
export async function animateText() {}
|
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export async function createAsciiArt({
|
|
3
|
-
message,
|
|
4
|
-
font = "Standard",
|
|
5
|
-
clearConsole = false
|
|
6
|
-
}) {
|
|
7
|
-
if (clearConsole) {
|
|
8
|
-
console.clear();
|
|
9
|
-
}
|
|
10
|
-
const asciiArt = textSync(message, { font });
|
|
11
|
-
console.log(asciiArt);
|
|
12
|
-
}
|
|
1
|
+
export function createAsciiArt() {}
|
package/dist-npm/mod.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from './components/prompts/index.js';
|
|
2
|
+
|
|
@@ -1,64 +1,89 @@
|
|
|
1
|
-
import ansiEscapes from
|
|
2
|
-
import MuteStream from
|
|
3
|
-
import {
|
|
4
|
-
import stripAnsi from
|
|
5
|
-
|
|
1
|
+
import ansiEscapes from 'ansi-escapes';
|
|
2
|
+
import MuteStream from 'mute-stream';
|
|
3
|
+
import {Stream} from 'node:stream';
|
|
4
|
+
import stripAnsi from 'strip-ansi';
|
|
5
|
+
|
|
6
|
+
const isString = (a) => typeof a === 'string';
|
|
7
|
+
const ignoredAnsi = new Set([
|
|
8
|
+
ansiEscapes.cursorHide,
|
|
9
|
+
ansiEscapes.cursorShow,
|
|
10
|
+
]);
|
|
11
|
+
|
|
6
12
|
class BufferedStream extends Stream.Writable {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
#_fullOutput = '';
|
|
14
|
+
#_chunks = [];
|
|
15
|
+
#_rawChunks = [];
|
|
16
|
+
_write(chunk, _encoding, callback) {
|
|
17
|
+
const str = chunk.toString();
|
|
18
|
+
|
|
19
|
+
this.#_fullOutput += str;
|
|
20
|
+
if (!ignoredAnsi.has(str)) {
|
|
21
|
+
this.#_rawChunks.push(str);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (stripAnsi(str).trim().length > 0) {
|
|
25
|
+
this.#_chunks.push(str);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
callback();
|
|
15
29
|
}
|
|
16
|
-
|
|
17
|
-
|
|
30
|
+
|
|
31
|
+
getLastChunk({raw}) {
|
|
32
|
+
const chunks = raw ? this.#_rawChunks : this.#_chunks;
|
|
33
|
+
const lastChunk = chunks.at(-1);
|
|
34
|
+
|
|
35
|
+
return lastChunk ?? '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getFullOutput() {
|
|
39
|
+
return this.#_fullOutput;
|
|
18
40
|
}
|
|
19
|
-
callback();
|
|
20
|
-
}
|
|
21
|
-
getLastChunk({ raw }) {
|
|
22
|
-
const chunks = raw ? this.#_rawChunks : this.#_chunks;
|
|
23
|
-
const lastChunk = chunks.at(-1);
|
|
24
|
-
return lastChunk ?? "";
|
|
25
|
-
}
|
|
26
|
-
getFullOutput() {
|
|
27
|
-
return this.#_fullOutput;
|
|
28
|
-
}
|
|
29
41
|
}
|
|
42
|
+
|
|
30
43
|
export async function render(prompt, props, options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
const input = new MuteStream();
|
|
45
|
+
input.unmute();
|
|
46
|
+
const output = new BufferedStream();
|
|
47
|
+
const answer = prompt(props, {
|
|
48
|
+
input,
|
|
49
|
+
output,
|
|
50
|
+
...options,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
await Promise.resolve();
|
|
54
|
+
await Promise.resolve();
|
|
55
|
+
const events = {
|
|
56
|
+
keypress(key) {
|
|
57
|
+
if (isString(key)) {
|
|
58
|
+
input.emit('keypress', null, {
|
|
59
|
+
name: key,
|
|
60
|
+
});
|
|
61
|
+
} else {
|
|
62
|
+
input.emit('keypress', null, key);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
type(text) {
|
|
66
|
+
input.write(text);
|
|
67
|
+
for (const char of text) {
|
|
68
|
+
input.emit('keypress', null, {
|
|
69
|
+
name: char,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
answer,
|
|
77
|
+
input,
|
|
78
|
+
events,
|
|
79
|
+
getScreen: ({raw} = {}) => {
|
|
80
|
+
const lastScreen = output.getLastChunk({
|
|
81
|
+
raw,
|
|
82
|
+
});
|
|
83
|
+
return raw ? lastScreen : stripAnsi(lastScreen).trim();
|
|
84
|
+
},
|
|
85
|
+
getFullOutput: () => {
|
|
86
|
+
return output.getFullOutput();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
64
89
|
}
|
|
@@ -37,6 +37,7 @@ export type FmtMsgOptions = {
|
|
|
37
37
|
errorMessage?: string;
|
|
38
38
|
addNewLineBefore?: boolean;
|
|
39
39
|
addNewLineAfter?: boolean;
|
|
40
|
+
placeholder?: string;
|
|
40
41
|
};
|
|
41
42
|
export type RequiredPromptOptions = {
|
|
42
43
|
id: string;
|
|
@@ -54,6 +55,7 @@ export type OptionalPromptOptions<T extends TSchema = any> = {
|
|
|
54
55
|
contentTypography?: TypographyName;
|
|
55
56
|
contentVariant?: Variant;
|
|
56
57
|
hint?: string;
|
|
58
|
+
placeholder?: string;
|
|
57
59
|
validate?: (value: any) => boolean | string | Promise<boolean | string>;
|
|
58
60
|
defaultValue?: string | string[] | number | boolean;
|
|
59
61
|
defaultColor?: ColorName;
|
|
@@ -69,7 +71,6 @@ export type OptionalPromptOptions<T extends TSchema = any> = {
|
|
|
69
71
|
borderColor?: ColorName;
|
|
70
72
|
clearConsole?: boolean;
|
|
71
73
|
additionalLinesToDelete?: number;
|
|
72
|
-
answerColor?: ColorName;
|
|
73
74
|
hintColor?: ColorName;
|
|
74
75
|
hints?: string[];
|
|
75
76
|
required?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist-npm/types/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from './relinka.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
|
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
export var KeyName =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
export var KeyName = ((KeyName2) => {
|
|
2
|
+
KeyName2.RETURN = 'return';
|
|
3
|
+
KeyName2.ENTER = 'enter';
|
|
4
|
+
KeyName2.TAB = 'tab';
|
|
5
|
+
KeyName2.BACKSPACE = 'backspace';
|
|
6
|
+
KeyName2.ESCAPE = 'escape';
|
|
7
|
+
KeyName2.SPACE = 'space';
|
|
8
|
+
KeyName2.UP = 'up';
|
|
9
|
+
KeyName2.DOWN = 'down';
|
|
10
|
+
KeyName2.RIGHT = 'right';
|
|
11
|
+
KeyName2.LEFT = 'left';
|
|
12
|
+
KeyName2.F1 = 'f1';
|
|
13
|
+
KeyName2.F2 = 'f2';
|
|
14
|
+
KeyName2.F3 = 'f3';
|
|
15
|
+
KeyName2.F4 = 'f4';
|
|
16
|
+
KeyName2.F5 = 'f5';
|
|
17
|
+
KeyName2.F6 = 'f6';
|
|
18
|
+
KeyName2.F7 = 'f7';
|
|
19
|
+
KeyName2.F8 = 'f8';
|
|
20
|
+
KeyName2.F9 = 'f9';
|
|
21
|
+
KeyName2.F10 = 'f10';
|
|
22
|
+
KeyName2.F11 = 'f11';
|
|
23
|
+
KeyName2.F12 = 'f12';
|
|
24
|
+
KeyName2.CLEAR = 'clear';
|
|
25
|
+
KeyName2.END = 'end';
|
|
26
|
+
KeyName2.HOME = 'home';
|
|
27
|
+
KeyName2.INSERT = 'insert';
|
|
28
|
+
KeyName2.PAGEUP = 'pageup';
|
|
29
|
+
KeyName2.PAGEDOWN = 'pagedown';
|
|
30
|
+
KeyName2.DELETE = 'delete';
|
|
31
|
+
KeyName2.NEXT = 'next';
|
|
32
|
+
KeyName2.PREVIOUS = 'previous';
|
|
33
|
+
KeyName2.SUBMIT = 'submit';
|
|
34
|
+
KeyName2.ABORT = 'abort';
|
|
35
|
+
|
|
36
|
+
return KeyName2;
|
|
36
37
|
})(KeyName || {});
|
|
37
38
|
export default listenForKeys;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist-npm/types/utils.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist-npm/utils/box.js
CHANGED
|
@@ -1,145 +1,147 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import {getColor} from './color.js';
|
|
2
|
+
import {stripAnsi} from './string.js';
|
|
3
|
+
|
|
4
|
+
const isString = (a) => typeof a === 'string';
|
|
5
|
+
|
|
3
6
|
const boxStylePresets = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
7
|
+
solid: {
|
|
8
|
+
tl: '\u250C',
|
|
9
|
+
tr: '\u2510',
|
|
10
|
+
bl: '\u2514',
|
|
11
|
+
br: '\u2518',
|
|
12
|
+
h: '\u2500',
|
|
13
|
+
v: '\u2502',
|
|
14
|
+
},
|
|
15
|
+
double: {
|
|
16
|
+
tl: '\u2554',
|
|
17
|
+
tr: '\u2557',
|
|
18
|
+
bl: '\u255A',
|
|
19
|
+
br: '\u255D',
|
|
20
|
+
h: '\u2550',
|
|
21
|
+
v: '\u2551',
|
|
22
|
+
},
|
|
23
|
+
doubleSingle: {
|
|
24
|
+
tl: '\u2553',
|
|
25
|
+
tr: '\u2556',
|
|
26
|
+
bl: '\u2559',
|
|
27
|
+
br: '\u255C',
|
|
28
|
+
h: '\u2500',
|
|
29
|
+
v: '\u2551',
|
|
30
|
+
},
|
|
31
|
+
doubleSingleRounded: {
|
|
32
|
+
tl: '\u256D',
|
|
33
|
+
tr: '\u256E',
|
|
34
|
+
bl: '\u2570',
|
|
35
|
+
br: '\u256F',
|
|
36
|
+
h: '\u2500',
|
|
37
|
+
v: '\u2551',
|
|
38
|
+
},
|
|
39
|
+
singleThick: {
|
|
40
|
+
tl: '\u250F',
|
|
41
|
+
tr: '\u2513',
|
|
42
|
+
bl: '\u2517',
|
|
43
|
+
br: '\u251B',
|
|
44
|
+
h: '\u2501',
|
|
45
|
+
v: '\u2503',
|
|
46
|
+
},
|
|
47
|
+
singleDouble: {
|
|
48
|
+
tl: '\u2552',
|
|
49
|
+
tr: '\u2555',
|
|
50
|
+
bl: '\u2558',
|
|
51
|
+
br: '\u255B',
|
|
52
|
+
h: '\u2550',
|
|
53
|
+
v: '\u2502',
|
|
54
|
+
},
|
|
55
|
+
singleDoubleRounded: {
|
|
56
|
+
tl: '\u256D',
|
|
57
|
+
tr: '\u256E',
|
|
58
|
+
bl: '\u2570',
|
|
59
|
+
br: '\u256F',
|
|
60
|
+
h: '\u2550',
|
|
61
|
+
v: '\u2502',
|
|
62
|
+
},
|
|
63
|
+
rounded: {
|
|
64
|
+
tl: '\u256D',
|
|
65
|
+
tr: '\u256E',
|
|
66
|
+
bl: '\u2570',
|
|
67
|
+
br: '\u256F',
|
|
68
|
+
h: '\u2500',
|
|
69
|
+
v: '\u2502',
|
|
70
|
+
},
|
|
68
71
|
};
|
|
72
|
+
|
|
69
73
|
const defaultStyle = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
borderColor: 'white',
|
|
75
|
+
borderStyle: 'rounded',
|
|
76
|
+
valign: 'center',
|
|
77
|
+
padding: 2,
|
|
78
|
+
marginLeft: 1,
|
|
79
|
+
marginTop: 1,
|
|
80
|
+
marginBottom: 1,
|
|
77
81
|
};
|
|
82
|
+
|
|
78
83
|
export function box(text, _opts = {}) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
const opts = {
|
|
85
|
+
..._opts,
|
|
86
|
+
style: {
|
|
87
|
+
...defaultStyle,
|
|
88
|
+
..._opts.style,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const textLines = text.split('\n');
|
|
93
|
+
const boxLines = [];
|
|
94
|
+
const _color = getColor(opts.style.borderColor);
|
|
95
|
+
|
|
96
|
+
const borderStyle = {
|
|
97
|
+
...isString(opts.style.borderStyle) ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (_color) {
|
|
101
|
+
for (const key in borderStyle) {
|
|
102
|
+
borderStyle[key] = _color(borderStyle[key]);
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
borderStyle[key] = _color(
|
|
95
|
-
borderStyle[key]
|
|
96
|
-
);
|
|
105
|
+
|
|
106
|
+
const paddingOffset = !(opts.style.padding % 2) ? opts.style.padding : opts.style.padding + 1;
|
|
107
|
+
const height = textLines.length + paddingOffset;
|
|
108
|
+
const width = Math.max(...textLines.map((line) => line.length)) + paddingOffset;
|
|
109
|
+
const widthOffset = width + paddingOffset;
|
|
110
|
+
const leftSpace = opts.style.marginLeft > 0 ? ' '.repeat(opts.style.marginLeft) : '';
|
|
111
|
+
|
|
112
|
+
if (opts.style.marginTop > 0) {
|
|
113
|
+
boxLines.push(''.repeat(opts.style.marginTop));
|
|
97
114
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
if (opts.title) {
|
|
108
|
-
const title = _color ? _color(opts.title) : opts.title;
|
|
109
|
-
const left = borderStyle.h.repeat(
|
|
110
|
-
Math.floor((width - stripAnsi(opts.title).length) / 2)
|
|
111
|
-
);
|
|
112
|
-
const right = borderStyle.h.repeat(
|
|
113
|
-
width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset
|
|
114
|
-
);
|
|
115
|
-
boxLines.push(
|
|
116
|
-
`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
boxLines.push(
|
|
120
|
-
`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
124
|
-
for (let i = 0; i < height; i++) {
|
|
125
|
-
if (i < valignOffset || i >= valignOffset + textLines.length) {
|
|
126
|
-
boxLines.push(
|
|
127
|
-
`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
|
|
128
|
-
);
|
|
115
|
+
|
|
116
|
+
if (opts.title) {
|
|
117
|
+
const title = _color ? _color(opts.title) : opts.title;
|
|
118
|
+
const left = borderStyle.h.repeat(Math.floor((width - stripAnsi(opts.title).length) / 2));
|
|
119
|
+
|
|
120
|
+
const right = borderStyle.h.repeat(width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset);
|
|
121
|
+
|
|
122
|
+
boxLines.push(`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`);
|
|
129
123
|
} else {
|
|
130
|
-
|
|
131
|
-
const left = " ".repeat(paddingOffset);
|
|
132
|
-
const right = " ".repeat(width - stripAnsi(line).length);
|
|
133
|
-
boxLines.push(
|
|
134
|
-
`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
|
|
135
|
-
);
|
|
124
|
+
boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
|
|
136
125
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
|
|
127
|
+
const valignOffset = opts.style.valign === 'center' ? Math.floor((height - textLines.length) / 2) : opts.style.valign === 'top' ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
128
|
+
|
|
129
|
+
for (let i = 0; i < height; i++) {
|
|
130
|
+
if (i < valignOffset || i >= valignOffset + textLines.length) {
|
|
131
|
+
boxLines.push(`${leftSpace}${borderStyle.v}${' '.repeat(widthOffset)}${borderStyle.v}`);
|
|
132
|
+
} else {
|
|
133
|
+
const line = textLines[i - valignOffset];
|
|
134
|
+
const left = ' '.repeat(paddingOffset);
|
|
135
|
+
const right = ' '.repeat(width - stripAnsi(line).length);
|
|
136
|
+
|
|
137
|
+
boxLines.push(`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
boxLines.push(`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`);
|
|
142
|
+
if (opts.style.marginBottom > 0) {
|
|
143
|
+
boxLines.push(''.repeat(opts.style.marginBottom));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return boxLines.join('\n');
|
|
145
147
|
}
|