@reliverse/relinka 1.1.7 → 1.1.9
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 +57 -77
- package/dist-npm/components/block/block.js +48 -61
- package/dist-npm/components/checkbox/index.js +178 -211
- package/dist-npm/components/confirm/confirm-main.js +85 -122
- package/dist-npm/components/confirm/confirm-three.js +24 -27
- package/dist-npm/components/confirm/index.js +36 -45
- package/dist-npm/components/core/Separator.js +15 -17
- package/dist-npm/components/core/create-prompt.js +101 -124
- package/dist-npm/components/core/errors.js +19 -15
- package/dist-npm/components/core/hook-engine.js +91 -120
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +16 -6
- package/dist-npm/components/core/lines.js +45 -54
- package/dist-npm/components/core/make-theme.js +21 -30
- package/dist-npm/components/core/position.js +27 -23
- package/dist-npm/components/core/promise-polyfill.js +11 -14
- package/dist-npm/components/core/screen-manager.js +59 -74
- package/dist-npm/components/core/theme.js +22 -32
- package/dist-npm/components/core/use-effect.js +9 -15
- package/dist-npm/components/core/use-keypress.js +19 -23
- package/dist-npm/components/core/use-memo.js +10 -16
- package/dist-npm/components/core/use-pagination.js +33 -32
- package/dist-npm/components/core/use-prefix.js +40 -38
- package/dist-npm/components/core/use-ref.js +2 -5
- package/dist-npm/components/core/use-state.js +15 -23
- package/dist-npm/components/core/useKeyPress.js +14 -17
- package/dist-npm/components/core/usePromptState.js +8 -14
- package/dist-npm/components/core/utils.js +7 -16
- package/dist-npm/components/date/date.js +187 -204
- package/dist-npm/components/editor/index.js +71 -92
- package/dist-npm/components/expand/index.js +96 -124
- package/dist-npm/components/figures/index.js +283 -294
- package/dist-npm/components/input/index.js +61 -87
- package/dist-npm/components/input/text-main.js +97 -124
- package/dist-npm/components/input/text.js +24 -28
- package/dist-npm/components/instance/basic.js +17 -25
- package/dist-npm/components/instance/browser.js +14 -18
- package/dist-npm/components/instance/reporter/basic.js +46 -65
- package/dist-npm/components/instance/reporter/browser.js +44 -47
- package/dist-npm/components/instance/reporter/fancy.js +83 -96
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +52 -62
- package/dist-npm/components/mono/monoTwo.js +35 -49
- package/dist-npm/components/multiselect/group-multiselect.js +55 -71
- package/dist-npm/components/multiselect/multi-select-two.js +97 -130
- package/dist-npm/components/multiselect/multi-select.js +43 -49
- package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
- package/dist-npm/components/multiselect/multiselect-main.js +158 -145
- package/dist-npm/components/multiselect/num-multi-select.js +97 -130
- package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
- package/dist-npm/components/next-steps/next-steps.js +23 -25
- package/dist-npm/components/number/index.js +78 -112
- package/dist-npm/components/number/number-main.js +95 -2
- package/dist-npm/components/password/index.js +54 -73
- package/dist-npm/components/password/password-main.js +119 -2
- package/dist-npm/components/password/password-three.js +26 -30
- package/dist-npm/components/progressbar/ProgressBar.js +45 -64
- package/dist-npm/components/progressbar/helper.js +33 -40
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +29 -44
- package/dist-npm/components/prompts/index.d.ts +1 -0
- package/dist-npm/components/prompts/index.js +46 -45
- package/dist-npm/components/prompts/prompt.js +211 -260
- package/dist-npm/components/prompts/promptTwo.js +561 -605
- package/dist-npm/components/prompts/relinka.js +237 -295
- package/dist-npm/components/range/range.js +247 -294
- package/dist-npm/components/rawlist/index.js +87 -107
- package/dist-npm/components/results/results.js +31 -37
- package/dist-npm/components/search/index.js +148 -193
- package/dist-npm/components/select/index.js +148 -186
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +124 -5
- package/dist-npm/components/select/select-key.js +24 -25
- package/dist-npm/components/select/select-main.d.ts +1 -0
- package/dist-npm/components/select/select-main.js +143 -133
- package/dist-npm/components/select/select-three.js +32 -36
- package/dist-npm/components/select/select-two.js +94 -87
- package/dist-npm/components/spinner/index.js +107 -136
- package/dist-npm/components/st-end/end.js +34 -26
- package/dist-npm/components/st-end/start.js +29 -15
- package/dist-npm/components/toggle/index.js +113 -137
- package/dist-npm/components/visual/animate/animate.js +53 -10
- package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
- package/dist-npm/main.js +1 -0
- package/dist-npm/testing/index.js +58 -83
- package/dist-npm/types/general.d.ts +1 -1
- package/dist-npm/types/general.js +0 -1
- package/dist-npm/types/index.js +2 -3
- package/dist-npm/types/keypress.js +35 -36
- package/dist-npm/types/readline.js +0 -1
- package/dist-npm/types/relinka.js +0 -1
- package/dist-npm/types/utils.js +0 -1
- package/dist-npm/utils/box.js +135 -137
- package/dist-npm/utils/color.js +65 -74
- package/dist-npm/utils/colorize.js +124 -156
- package/dist-npm/utils/component.js +532 -657
- package/dist-npm/utils/constants.js +64 -63
- package/dist-npm/utils/core.js +2 -3
- package/dist-npm/utils/decoder.js +244 -223
- package/dist-npm/utils/error.js +4 -9
- package/dist-npm/utils/errors.js +14 -4
- package/dist-npm/utils/format.js +19 -24
- package/dist-npm/utils/keypress.js +316 -414
- package/dist-npm/utils/log.js +11 -15
- package/dist-npm/utils/mapping.js +45 -52
- package/dist-npm/utils/messages.js +196 -183
- package/dist-npm/utils/platforms.js +16 -20
- package/dist-npm/utils/prompt-tmp.js +235 -286
- package/dist-npm/utils/prompt-two.js +235 -286
- package/dist-npm/utils/readline.js +5 -7
- package/dist-npm/utils/skeleton.js +130 -170
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +44 -58
- package/dist-npm/utils/terminal.js +23 -34
- package/dist-npm/utils/tree.js +30 -41
- package/dist-npm/utils/types.js +0 -1
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +36 -44
- package/package.json +14 -14
- package/dist-npm/mod.js +0 -2
- /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { textSync } from "figlet";
|
|
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
|
+
}
|
package/dist-npm/main.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/prompts/index.js";
|
|
@@ -1,89 +1,64 @@
|
|
|
1
|
-
import ansiEscapes from
|
|
2
|
-
import MuteStream from
|
|
3
|
-
import {Stream} from
|
|
4
|
-
import stripAnsi from
|
|
5
|
-
|
|
6
|
-
const isString = (a) => typeof a === 'string';
|
|
7
|
-
const ignoredAnsi = new Set([
|
|
8
|
-
ansiEscapes.cursorHide,
|
|
9
|
-
ansiEscapes.cursorShow,
|
|
10
|
-
]);
|
|
11
|
-
|
|
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
|
+
const ignoredAnsi = new Set([ansiEscapes.cursorHide, ansiEscapes.cursorShow]);
|
|
12
6
|
class BufferedStream extends Stream.Writable {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.#_rawChunks.push(str);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (stripAnsi(str).trim().length > 0) {
|
|
25
|
-
this.#_chunks.push(str);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
callback();
|
|
7
|
+
#_fullOutput = "";
|
|
8
|
+
#_chunks = [];
|
|
9
|
+
#_rawChunks = [];
|
|
10
|
+
_write(chunk, _encoding, callback) {
|
|
11
|
+
const str = chunk.toString();
|
|
12
|
+
this.#_fullOutput += str;
|
|
13
|
+
if (!ignoredAnsi.has(str)) {
|
|
14
|
+
this.#_rawChunks.push(str);
|
|
29
15
|
}
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
16
|
+
if (stripAnsi(str).trim().length > 0) {
|
|
17
|
+
this.#_chunks.push(str);
|
|
40
18
|
}
|
|
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
|
+
}
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
export async function render(prompt, props, options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
};
|
|
31
|
+
const input = new MuteStream();
|
|
32
|
+
input.unmute();
|
|
33
|
+
const output = new BufferedStream();
|
|
34
|
+
const answer = prompt(props, { input, output, ...options });
|
|
35
|
+
await Promise.resolve();
|
|
36
|
+
await Promise.resolve();
|
|
37
|
+
const events = {
|
|
38
|
+
keypress(key) {
|
|
39
|
+
if (typeof key === "string") {
|
|
40
|
+
input.emit("keypress", null, { name: key });
|
|
41
|
+
} else {
|
|
42
|
+
input.emit("keypress", null, key);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
type(text) {
|
|
46
|
+
input.write(text);
|
|
47
|
+
for (const char of text) {
|
|
48
|
+
input.emit("keypress", null, { name: char });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
answer,
|
|
54
|
+
input,
|
|
55
|
+
events,
|
|
56
|
+
getScreen: ({ raw } = {}) => {
|
|
57
|
+
const lastScreen = output.getLastChunk({ raw });
|
|
58
|
+
return raw ? lastScreen : stripAnsi(lastScreen).trim();
|
|
59
|
+
},
|
|
60
|
+
getFullOutput: () => {
|
|
61
|
+
return output.getFullOutput();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
89
64
|
}
|
|
@@ -2,7 +2,7 @@ import type { AnimationName } from "@figliolia/chalk-animation";
|
|
|
2
2
|
import type { TSchema } from "@sinclair/typebox";
|
|
3
3
|
import type { LogLevel, LogType } from "../utils/constants.js";
|
|
4
4
|
export type State = "initial" | "active" | "cancel" | "submit" | "error";
|
|
5
|
-
export type MsgType = "M_NULL" | "M_START" | "M_MIDDLE" | "M_GENERAL" | "M_INFO" | "M_INFO_NULL" | "M_NEWLINE" | "M_END" | "M_ERROR";
|
|
5
|
+
export type MsgType = "M_NULL" | "M_START" | "M_MIDDLE" | "M_GENERAL" | "M_GENERAL_NULL" | "M_INFO" | "M_INFO_NULL" | "M_NEWLINE" | "M_END" | "M_ERROR" | "M_ERROR_NULL";
|
|
6
6
|
export type TypographyName = "bold" | "strikethrough" | "underline" | "italic";
|
|
7
7
|
export type Variant = "box" | "doubleBox" | "banner" | "underline" | "none" | "animated";
|
|
8
8
|
export type ColorName = "dim" | "inverse" | "black" | "red" | "redBright" | "bgRed" | "bgRedBright" | "green" | "greenBright" | "bgGreen" | "bgGreenBright" | "yellow" | "yellowBright" | "blue" | "blueBright" | "magenta" | "cyan" | "cyanBright" | "bgCyan" | "bgCyanBright" | "white" | "gray" | "gradientGradient" | "rainbowGradient" | "cristalGradient" | "mindGradient" | "passionGradient" | "viceGradient" | "retroGradient" | "none";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist-npm/types/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
|
|
1
|
+
export * from "./relinka.js";
|
|
2
|
+
export * from "./utils.js";
|
|
@@ -1,38 +1,37 @@
|
|
|
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
|
-
|
|
36
|
-
return KeyName2;
|
|
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
|
+
return KeyName2;
|
|
37
36
|
})(KeyName || {});
|
|
38
37
|
export default listenForKeys;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist-npm/types/utils.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist-npm/utils/box.js
CHANGED
|
@@ -1,147 +1,145 @@
|
|
|
1
|
-
import {getColor} from
|
|
2
|
-
import {stripAnsi} from
|
|
3
|
-
|
|
4
|
-
const isString = (a) => typeof a === 'string';
|
|
5
|
-
|
|
1
|
+
import { getColor } from "./color.js";
|
|
2
|
+
import { stripAnsi } from "./string.js";
|
|
6
3
|
const boxStylePresets = {
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
4
|
+
solid: {
|
|
5
|
+
tl: "\u250C",
|
|
6
|
+
tr: "\u2510",
|
|
7
|
+
bl: "\u2514",
|
|
8
|
+
br: "\u2518",
|
|
9
|
+
h: "\u2500",
|
|
10
|
+
v: "\u2502"
|
|
11
|
+
},
|
|
12
|
+
double: {
|
|
13
|
+
tl: "\u2554",
|
|
14
|
+
tr: "\u2557",
|
|
15
|
+
bl: "\u255A",
|
|
16
|
+
br: "\u255D",
|
|
17
|
+
h: "\u2550",
|
|
18
|
+
v: "\u2551"
|
|
19
|
+
},
|
|
20
|
+
doubleSingle: {
|
|
21
|
+
tl: "\u2553",
|
|
22
|
+
tr: "\u2556",
|
|
23
|
+
bl: "\u2559",
|
|
24
|
+
br: "\u255C",
|
|
25
|
+
h: "\u2500",
|
|
26
|
+
v: "\u2551"
|
|
27
|
+
},
|
|
28
|
+
doubleSingleRounded: {
|
|
29
|
+
tl: "\u256D",
|
|
30
|
+
tr: "\u256E",
|
|
31
|
+
bl: "\u2570",
|
|
32
|
+
br: "\u256F",
|
|
33
|
+
h: "\u2500",
|
|
34
|
+
v: "\u2551"
|
|
35
|
+
},
|
|
36
|
+
singleThick: {
|
|
37
|
+
tl: "\u250F",
|
|
38
|
+
tr: "\u2513",
|
|
39
|
+
bl: "\u2517",
|
|
40
|
+
br: "\u251B",
|
|
41
|
+
h: "\u2501",
|
|
42
|
+
v: "\u2503"
|
|
43
|
+
},
|
|
44
|
+
singleDouble: {
|
|
45
|
+
tl: "\u2552",
|
|
46
|
+
tr: "\u2555",
|
|
47
|
+
bl: "\u2558",
|
|
48
|
+
br: "\u255B",
|
|
49
|
+
h: "\u2550",
|
|
50
|
+
v: "\u2502"
|
|
51
|
+
},
|
|
52
|
+
singleDoubleRounded: {
|
|
53
|
+
tl: "\u256D",
|
|
54
|
+
tr: "\u256E",
|
|
55
|
+
bl: "\u2570",
|
|
56
|
+
br: "\u256F",
|
|
57
|
+
h: "\u2550",
|
|
58
|
+
v: "\u2502"
|
|
59
|
+
},
|
|
60
|
+
rounded: {
|
|
61
|
+
tl: "\u256D",
|
|
62
|
+
tr: "\u256E",
|
|
63
|
+
bl: "\u2570",
|
|
64
|
+
br: "\u256F",
|
|
65
|
+
h: "\u2500",
|
|
66
|
+
v: "\u2502"
|
|
67
|
+
}
|
|
71
68
|
};
|
|
72
|
-
|
|
73
69
|
const defaultStyle = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
borderColor: "white",
|
|
71
|
+
borderStyle: "rounded",
|
|
72
|
+
valign: "center",
|
|
73
|
+
padding: 2,
|
|
74
|
+
marginLeft: 1,
|
|
75
|
+
marginTop: 1,
|
|
76
|
+
marginBottom: 1
|
|
81
77
|
};
|
|
82
|
-
|
|
83
78
|
export function box(text, _opts = {}) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
}
|
|
79
|
+
const opts = {
|
|
80
|
+
..._opts,
|
|
81
|
+
style: {
|
|
82
|
+
...defaultStyle,
|
|
83
|
+
..._opts.style
|
|
104
84
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
85
|
+
};
|
|
86
|
+
const textLines = text.split("\n");
|
|
87
|
+
const boxLines = [];
|
|
88
|
+
const _color = getColor(opts.style.borderColor);
|
|
89
|
+
const borderStyle = {
|
|
90
|
+
...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
|
|
91
|
+
};
|
|
92
|
+
if (_color) {
|
|
93
|
+
for (const key in borderStyle) {
|
|
94
|
+
borderStyle[key] = _color(
|
|
95
|
+
borderStyle[key]
|
|
96
|
+
);
|
|
114
97
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
98
|
+
}
|
|
99
|
+
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
|
100
|
+
const height = textLines.length + paddingOffset;
|
|
101
|
+
const width = Math.max(...textLines.map((line) => line.length)) + paddingOffset;
|
|
102
|
+
const widthOffset = width + paddingOffset;
|
|
103
|
+
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
|
104
|
+
if (opts.style.marginTop > 0) {
|
|
105
|
+
boxLines.push("".repeat(opts.style.marginTop));
|
|
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
|
+
);
|
|
123
129
|
} else {
|
|
124
|
-
|
|
130
|
+
const line = textLines[i - valignOffset];
|
|
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
|
+
);
|
|
125
136
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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');
|
|
137
|
+
}
|
|
138
|
+
boxLines.push(
|
|
139
|
+
`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
|
|
140
|
+
);
|
|
141
|
+
if (opts.style.marginBottom > 0) {
|
|
142
|
+
boxLines.push("".repeat(opts.style.marginBottom));
|
|
143
|
+
}
|
|
144
|
+
return boxLines.join("\n");
|
|
147
145
|
}
|