@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.
Files changed (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +187 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1 +1,12 @@
1
- export function createAsciiArt() {}
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
+ }
@@ -0,0 +1 @@
1
+ export * from "./components/prompts/index.js";
@@ -1,89 +1,64 @@
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
-
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
- #_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();
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
- 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;
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
- 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
- };
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
-
@@ -1,3 +1,2 @@
1
- export * from './relinka.js';
2
- export * from './utils.js';
3
-
1
+ export * from "./relinka.js";
2
+ export * from "./utils.js";
@@ -1,38 +1,37 @@
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;
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
-
@@ -1 +0,0 @@
1
-
@@ -1,147 +1,145 @@
1
- import {getColor} from './color.js';
2
- import {stripAnsi} from './string.js';
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
- 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
- },
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
- borderColor: 'white',
75
- borderStyle: 'rounded',
76
- valign: 'center',
77
- padding: 2,
78
- marginLeft: 1,
79
- marginTop: 1,
80
- marginBottom: 1,
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
- 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
- }
79
+ const opts = {
80
+ ..._opts,
81
+ style: {
82
+ ...defaultStyle,
83
+ ..._opts.style
104
84
  }
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));
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
- 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}`);
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
- boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
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
- 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');
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
  }