1 | import {LiteralUnion} from 'type-fest';
|
2 | import {BoxStyle, Boxes} from 'cli-boxes';
|
3 |
|
4 | /**
|
5 | Characters used for custom border.
|
6 |
|
7 | @example
|
8 | ```
|
9 | // affffb
|
10 | // e e
|
11 | // dffffc
|
12 |
|
13 | const border: CustomBorderStyle = {
|
14 | topLeft: 'a',
|
15 | topRight: 'b',
|
16 | bottomRight: 'c',
|
17 | bottomLeft: 'd',
|
18 | vertical: 'e',
|
19 | horizontal: 'f'
|
20 | };
|
21 | ```
|
22 | */
|
23 | export interface CustomBorderStyle extends BoxStyle {}
|
24 |
|
25 | /**
|
26 | Spacing used for `padding` and `margin`.
|
27 | */
|
28 | export interface Spacing {
|
29 | readonly top: number;
|
30 | readonly right: number;
|
31 | readonly bottom: number;
|
32 | readonly left: number;
|
33 | }
|
34 |
|
35 | export interface Options {
|
36 | /**
|
37 | Color of the box border.
|
38 | */
|
39 | readonly borderColor?: LiteralUnion<
|
40 | | 'black'
|
41 | | 'red'
|
42 | | 'green'
|
43 | | 'yellow'
|
44 | | 'blue'
|
45 | | 'magenta'
|
46 | | 'cyan'
|
47 | | 'white'
|
48 | | 'gray'
|
49 | | 'grey'
|
50 | | 'blackBright'
|
51 | | 'redBright'
|
52 | | 'greenBright'
|
53 | | 'yellowBright'
|
54 | | 'blueBright'
|
55 | | 'magentaBright'
|
56 | | 'cyanBright'
|
57 | | 'whiteBright',
|
58 | string
|
59 | >;
|
60 |
|
61 | /**
|
62 | Style of the box border.
|
63 |
|
64 | @default 'single'
|
65 | */
|
66 | readonly borderStyle?: keyof Boxes | CustomBorderStyle;
|
67 |
|
68 | /**
|
69 | Reduce opacity of the border.
|
70 |
|
71 | @default false
|
72 | */
|
73 | readonly dimBorder?: boolean;
|
74 |
|
75 | /**
|
76 | Space between the text and box border.
|
77 |
|
78 | @default 0
|
79 | */
|
80 | readonly padding?: number | Spacing;
|
81 |
|
82 | /**
|
83 | Space around the box.
|
84 |
|
85 | @default 0
|
86 | */
|
87 | readonly margin?: number | Spacing;
|
88 |
|
89 | /**
|
90 | Float the box on the available terminal screen space.
|
91 |
|
92 | @default 'left'
|
93 | */
|
94 | readonly float?: 'left' | 'right' | 'center';
|
95 |
|
96 | /**
|
97 | Color of the background.
|
98 | */
|
99 | readonly backgroundColor?: LiteralUnion<
|
100 | | 'black'
|
101 | | 'red'
|
102 | | 'green'
|
103 | | 'yellow'
|
104 | | 'blue'
|
105 | | 'magenta'
|
106 | | 'cyan'
|
107 | | 'white'
|
108 | | 'blackBright'
|
109 | | 'redBright'
|
110 | | 'greenBright'
|
111 | | 'yellowBright'
|
112 | | 'blueBright'
|
113 | | 'magentaBright'
|
114 | | 'cyanBright'
|
115 | | 'whiteBright',
|
116 | string
|
117 | >;
|
118 |
|
119 | /**
|
120 | Align the text in the box based on the widest line.
|
121 |
|
122 | @default 'left'
|
123 | @deprecated Use `textAlignment` instead.
|
124 | */
|
125 | readonly align?: 'left' | 'right' | 'center';
|
126 |
|
127 | /**
|
128 | Align the text in the box based on the widest line.
|
129 |
|
130 | @default 'left'
|
131 | */
|
132 | readonly textAlignment?: 'left' | 'right' | 'center';
|
133 |
|
134 | /**
|
135 | Display a title at the top of the box.
|
136 | If needed, the box will horizontally expand to fit the title.
|
137 |
|
138 | @example
|
139 | ```
|
140 | console.log(boxen('foo bar', {title: 'example'}));
|
141 | // ┌ example ┐
|
142 | // │foo bar │
|
143 | // └─────────┘
|
144 | ```
|
145 | */
|
146 | readonly title?: string;
|
147 |
|
148 | /**
|
149 | Align the title in the top bar.
|
150 |
|
151 | @default 'left'
|
152 |
|
153 | @example
|
154 | ```
|
155 | console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'center'}));
|
156 | // ┌─── example ───┐
|
157 | // │foo bar foo bar│
|
158 | // └───────────────┘
|
159 |
|
160 | console.log(boxen('foo bar foo bar', {title: 'example', titleAlignment: 'right'}));
|
161 | // ┌────── example ┐
|
162 | // │foo bar foo bar│
|
163 | // └───────────────┘
|
164 | ```
|
165 | */
|
166 | readonly titleAlignment?: 'left' | 'right' | 'center';
|
167 | }
|
168 |
|
169 | /**
|
170 | Creates a box in the terminal.
|
171 |
|
172 | @param text - The text inside the box.
|
173 | @returns The box.
|
174 |
|
175 | @example
|
176 | ```
|
177 | import boxen from 'boxen';
|
178 |
|
179 | console.log(boxen('unicorn', {padding: 1}));
|
180 | // ┌─────────────┐
|
181 | // │ │
|
182 | // │ unicorn │
|
183 | // │ │
|
184 | // └─────────────┘
|
185 |
|
186 | console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
|
187 | //
|
188 | // ╔═════════════╗
|
189 | // ║ ║
|
190 | // ║ unicorn ║
|
191 | // ║ ║
|
192 | // ╚═════════════╝
|
193 | //
|
194 | ```
|
195 | */
|
196 | export default function boxen(text: string, options?: Options): string;
|