@reliverse/relinka 1.1.5 → 1.1.7

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