@awsless/clui 0.0.5 → 0.0.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.
- package/README.MD +87 -0
- package/dist/index.cjs +47 -42
- package/dist/index.d.cts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.js +50 -45
- package/package.json +2 -2
package/README.MD
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
|
|
2
|
+
# @awsless/clui
|
|
3
|
+
|
|
4
|
+
The @awsless/clui package combines a couple of useful npm packages to create easy to use & beautiful terminal applications.
|
|
5
|
+
|
|
6
|
+
Special thanks to:
|
|
7
|
+
- @clack/prompts
|
|
8
|
+
- cli-table3
|
|
9
|
+
- chalk
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Install with (NPM):
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm i @awsless/clui
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Basic Usage
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { log, prompt, color } from '@awsless/clui';
|
|
23
|
+
|
|
24
|
+
log.intro(color.blue.bold('Create a blog post'))
|
|
25
|
+
|
|
26
|
+
const title = await prompt.text({ message: 'Title:' })
|
|
27
|
+
const message = await prompt.text({ message: 'Message:' })
|
|
28
|
+
|
|
29
|
+
log.list('Preview post', {
|
|
30
|
+
title,
|
|
31
|
+
message,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const ok = await prompt.confirm({ message: 'Are you sure?' })
|
|
35
|
+
|
|
36
|
+
if(!ok) {
|
|
37
|
+
log.error('Canceled')
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
await log.task({
|
|
42
|
+
initialMessage: 'Creating post...',
|
|
43
|
+
successMessage: 'You blog post was successfully created!',
|
|
44
|
+
async task() {
|
|
45
|
+
// Create your blog post
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
log.outro('The end!')
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Supported Prompts
|
|
54
|
+
|
|
55
|
+
- prompt.text
|
|
56
|
+
- prompt.password
|
|
57
|
+
- prompt.integer
|
|
58
|
+
- prompt.float
|
|
59
|
+
- prompt.confirm
|
|
60
|
+
- prompt.select
|
|
61
|
+
- prompt.multiSelect
|
|
62
|
+
|
|
63
|
+
## Supported Logs
|
|
64
|
+
|
|
65
|
+
- log.intro
|
|
66
|
+
- log.outro
|
|
67
|
+
- log.note
|
|
68
|
+
- log.message
|
|
69
|
+
- log.step
|
|
70
|
+
- log.info
|
|
71
|
+
- log.warning
|
|
72
|
+
- log.error
|
|
73
|
+
- log.success
|
|
74
|
+
- log.list
|
|
75
|
+
- log.table
|
|
76
|
+
- log.task
|
|
77
|
+
|
|
78
|
+
## Supported Ansi Helpers:
|
|
79
|
+
|
|
80
|
+
- ansi.wrap
|
|
81
|
+
- ansi.length
|
|
82
|
+
- ansi.truncate
|
|
83
|
+
- ansi.pad
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -42,17 +42,21 @@ module.exports = __toCommonJS(index_exports);
|
|
|
42
42
|
// src/symbols.ts
|
|
43
43
|
var symbols_exports = {};
|
|
44
44
|
__export(symbols_exports, {
|
|
45
|
+
ellipsis: () => ellipsis,
|
|
45
46
|
error: () => error,
|
|
46
47
|
info: () => info,
|
|
48
|
+
message: () => message,
|
|
47
49
|
step: () => step,
|
|
48
50
|
success: () => success,
|
|
49
51
|
warning: () => warning
|
|
50
52
|
});
|
|
53
|
+
var message = "\u2502";
|
|
51
54
|
var step = "\u25C7";
|
|
52
55
|
var error = "\xD7";
|
|
53
56
|
var success = "\u25C6";
|
|
54
57
|
var warning = "\u25B2";
|
|
55
58
|
var info = "\xB7";
|
|
59
|
+
var ellipsis = "\u2026";
|
|
56
60
|
|
|
57
61
|
// src/prompts.ts
|
|
58
62
|
var prompts_exports = {};
|
|
@@ -144,7 +148,7 @@ __export(logs_exports, {
|
|
|
144
148
|
info: () => info2,
|
|
145
149
|
intro: () => intro,
|
|
146
150
|
list: () => list,
|
|
147
|
-
message: () =>
|
|
151
|
+
message: () => message2,
|
|
148
152
|
note: () => note,
|
|
149
153
|
outro: () => outro,
|
|
150
154
|
step: () => step2,
|
|
@@ -159,25 +163,26 @@ var import_cli_table3 = __toESM(require("cli-table3"), 1);
|
|
|
159
163
|
// src/ansi.ts
|
|
160
164
|
var ansi_exports = {};
|
|
161
165
|
__export(ansi_exports, {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
+
length: () => length,
|
|
167
|
+
pad: () => pad,
|
|
168
|
+
truncate: () => truncate,
|
|
169
|
+
wrap: () => wrap
|
|
166
170
|
});
|
|
167
|
-
var
|
|
171
|
+
var import_ansi_truncate = __toESM(require("ansi-truncate"), 1);
|
|
168
172
|
var import_string_length = __toESM(require("string-length"), 1);
|
|
169
173
|
var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
|
|
170
|
-
var
|
|
171
|
-
return (0, import_wrap_ansi.default)(
|
|
174
|
+
var wrap = (value, width, options) => {
|
|
175
|
+
return (0, import_wrap_ansi.default)(value, width, options);
|
|
172
176
|
};
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
var length = (value) => {
|
|
178
|
+
return (0, import_string_length.default)(value);
|
|
179
|
+
};
|
|
180
|
+
var truncate = (value, width) => {
|
|
181
|
+
return (0, import_ansi_truncate.default)(value, width, {
|
|
182
|
+
ellipsis
|
|
183
|
+
});
|
|
179
184
|
};
|
|
180
|
-
var
|
|
185
|
+
var pad = (texts) => {
|
|
181
186
|
const size = Math.max(...texts.map((text2) => (0, import_string_length.default)(text2)));
|
|
182
187
|
return (text2, padding = 0, fill) => {
|
|
183
188
|
return text2.padEnd(size + padding, fill);
|
|
@@ -191,37 +196,37 @@ var color = import_chalk.default;
|
|
|
191
196
|
// src/logs.ts
|
|
192
197
|
var endMargin = 3;
|
|
193
198
|
var intro = (title = "") => {
|
|
194
|
-
(0, import_prompts3.intro)(
|
|
199
|
+
(0, import_prompts3.intro)(truncate(title, process.stdout.columns - 6 - endMargin));
|
|
195
200
|
};
|
|
196
201
|
var outro = (title = "") => {
|
|
197
|
-
(0, import_prompts3.outro)(
|
|
202
|
+
(0, import_prompts3.outro)(truncate(title, process.stdout.columns - 6 - endMargin));
|
|
198
203
|
};
|
|
199
|
-
var note = (title,
|
|
204
|
+
var note = (title, message3) => {
|
|
200
205
|
const width = process.stdout.columns - 6 - endMargin;
|
|
201
206
|
(0, import_prompts3.note)(
|
|
202
|
-
|
|
207
|
+
wrap(message3, width, {
|
|
203
208
|
hard: true
|
|
204
209
|
}),
|
|
205
|
-
|
|
210
|
+
truncate(title, width)
|
|
206
211
|
);
|
|
207
212
|
};
|
|
208
|
-
var logMessage = (symbol,
|
|
213
|
+
var logMessage = (symbol, message3) => {
|
|
209
214
|
import_prompts3.log.message(
|
|
210
|
-
|
|
215
|
+
wrap(message3, process.stdout.columns - 6 - endMargin, {
|
|
211
216
|
hard: true,
|
|
212
217
|
trim: false
|
|
213
218
|
}),
|
|
214
219
|
{ symbol }
|
|
215
220
|
);
|
|
216
221
|
};
|
|
217
|
-
var
|
|
218
|
-
var error2 = (
|
|
219
|
-
var info2 = (
|
|
220
|
-
var step2 = (
|
|
221
|
-
var warning2 = (
|
|
222
|
-
var success2 = (
|
|
222
|
+
var message2 = (message3, symbol = color.gray(message)) => logMessage(symbol, message3);
|
|
223
|
+
var error2 = (message3) => logMessage(color.red(error), message3);
|
|
224
|
+
var info2 = (message3) => logMessage(color.blue(info), message3);
|
|
225
|
+
var step2 = (message3) => logMessage(color.green(step), message3);
|
|
226
|
+
var warning2 = (message3) => logMessage(color.yellow(warning), message3);
|
|
227
|
+
var success2 = (message3) => logMessage(color.green(success), message3);
|
|
223
228
|
var list = (title, data) => {
|
|
224
|
-
const padName =
|
|
229
|
+
const padName = pad(Object.keys(data));
|
|
225
230
|
note(
|
|
226
231
|
title,
|
|
227
232
|
Object.entries(data).map(([name, value]) => {
|
|
@@ -233,12 +238,12 @@ var task = async (opts) => {
|
|
|
233
238
|
let last;
|
|
234
239
|
const spin = (0, import_prompts3.spinner)();
|
|
235
240
|
spin.start(opts.initialMessage);
|
|
236
|
-
const stop = (
|
|
237
|
-
spin.stop(
|
|
241
|
+
const stop = (message3, code) => {
|
|
242
|
+
spin.stop(truncate(message3 ?? last ?? opts.initialMessage, process.stdout.columns - 6 - endMargin), code);
|
|
238
243
|
};
|
|
239
244
|
try {
|
|
240
245
|
const result = await opts.task((m) => {
|
|
241
|
-
spin.message(
|
|
246
|
+
spin.message(truncate(m, process.stdout.columns - 6 - endMargin));
|
|
242
247
|
last = m;
|
|
243
248
|
});
|
|
244
249
|
stop(opts.successMessage);
|
|
@@ -250,21 +255,21 @@ var task = async (opts) => {
|
|
|
250
255
|
};
|
|
251
256
|
var table = (props) => {
|
|
252
257
|
import_prompts3.log.message();
|
|
253
|
-
const
|
|
258
|
+
const length2 = Math.max(props.head.length, ...props.body.map((b) => b.length));
|
|
254
259
|
const padding = 2;
|
|
255
|
-
const totalPadding = padding * 2 *
|
|
260
|
+
const totalPadding = padding * 2 * length2;
|
|
256
261
|
const border = 1;
|
|
257
|
-
const totalBorder = (
|
|
262
|
+
const totalBorder = (length2 - 1) * border + 2;
|
|
258
263
|
const windowSize = process.stdout.columns;
|
|
259
|
-
const
|
|
260
|
-
const contentSizes = Array.from({ length }).map((_, i) => {
|
|
261
|
-
return Math.max(props.head[i]
|
|
264
|
+
const maxTableSize = windowSize - totalPadding - totalBorder - endMargin;
|
|
265
|
+
const contentSizes = Array.from({ length: length2 }).map((_, i) => {
|
|
266
|
+
return Math.max(length(props.head[i] ?? ""), ...props.body.map((b) => length(String(b[i]))));
|
|
262
267
|
});
|
|
263
|
-
const columnSizes = Array.from({ length }).map(() => {
|
|
268
|
+
const columnSizes = Array.from({ length: length2 }).map(() => {
|
|
264
269
|
return 0;
|
|
265
270
|
});
|
|
266
271
|
let leftover = Math.min(
|
|
267
|
-
|
|
272
|
+
maxTableSize,
|
|
268
273
|
contentSizes.reduce((total, size) => total + size, 0)
|
|
269
274
|
);
|
|
270
275
|
while (leftover > 0) {
|
|
@@ -280,7 +285,7 @@ var table = (props) => {
|
|
|
280
285
|
const table2 = new import_cli_table3.default({
|
|
281
286
|
head: props.head.map(
|
|
282
287
|
(value, x) => "\n" + color.reset.whiteBright.bold(
|
|
283
|
-
|
|
288
|
+
wrap(value, columnSizes[x], {
|
|
284
289
|
hard: true
|
|
285
290
|
})
|
|
286
291
|
)
|
|
@@ -305,7 +310,7 @@ var table = (props) => {
|
|
|
305
310
|
if (typeof value === "number") {
|
|
306
311
|
return color.blue(value);
|
|
307
312
|
}
|
|
308
|
-
return
|
|
313
|
+
return wrap(value, columnSizes[x], {
|
|
309
314
|
hard: true
|
|
310
315
|
});
|
|
311
316
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
|
|
2
|
-
import stringLength from 'string-length';
|
|
3
2
|
import { Options } from 'wrap-ansi';
|
|
4
3
|
import * as chalk from 'chalk';
|
|
5
4
|
|
|
5
|
+
declare const message$1 = "\u2502";
|
|
6
6
|
declare const step$1 = "\u25C7";
|
|
7
7
|
declare const error$1 = "\u00D7";
|
|
8
8
|
declare const success$1 = "\u25C6";
|
|
9
9
|
declare const warning$1 = "\u25B2";
|
|
10
10
|
declare const info$1 = "\u00B7";
|
|
11
|
+
declare const ellipsis = "\u2026";
|
|
11
12
|
|
|
13
|
+
declare const symbols_ellipsis: typeof ellipsis;
|
|
12
14
|
declare namespace symbols {
|
|
13
|
-
export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
|
|
15
|
+
export { symbols_ellipsis as ellipsis, error$1 as error, info$1 as info, message$1 as message, step$1 as step, success$1 as success, warning$1 as warning };
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
declare const text: (opts: TextOptions) => Promise<string>;
|
|
@@ -76,16 +78,17 @@ declare namespace logs {
|
|
|
76
78
|
export { logs_error as error, logs_info as info, logs_intro as intro, logs_list as list, logs_message as message, logs_note as note, logs_outro as outro, logs_step as step, logs_success as success, logs_table as table, logs_task as task, logs_warning as warning };
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
declare const
|
|
80
|
-
declare const
|
|
81
|
-
declare const
|
|
81
|
+
declare const wrap: (value: string, width: number, options?: Options) => string;
|
|
82
|
+
declare const length: (value: string) => number;
|
|
83
|
+
declare const truncate: (value: string, width: number) => string;
|
|
84
|
+
declare const pad: (texts: string[]) => (text: string, padding?: number, fill?: string) => string;
|
|
82
85
|
|
|
83
|
-
declare const
|
|
84
|
-
declare const
|
|
85
|
-
declare const
|
|
86
|
-
declare const
|
|
86
|
+
declare const ansi_length: typeof length;
|
|
87
|
+
declare const ansi_pad: typeof pad;
|
|
88
|
+
declare const ansi_truncate: typeof truncate;
|
|
89
|
+
declare const ansi_wrap: typeof wrap;
|
|
87
90
|
declare namespace ansi {
|
|
88
|
-
export {
|
|
91
|
+
export { ansi_length as length, ansi_pad as pad, ansi_truncate as truncate, ansi_wrap as wrap };
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
declare const color: chalk.ChalkInstance;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
|
|
2
|
-
import stringLength from 'string-length';
|
|
3
2
|
import { Options } from 'wrap-ansi';
|
|
4
3
|
import * as chalk from 'chalk';
|
|
5
4
|
|
|
5
|
+
declare const message$1 = "\u2502";
|
|
6
6
|
declare const step$1 = "\u25C7";
|
|
7
7
|
declare const error$1 = "\u00D7";
|
|
8
8
|
declare const success$1 = "\u25C6";
|
|
9
9
|
declare const warning$1 = "\u25B2";
|
|
10
10
|
declare const info$1 = "\u00B7";
|
|
11
|
+
declare const ellipsis = "\u2026";
|
|
11
12
|
|
|
13
|
+
declare const symbols_ellipsis: typeof ellipsis;
|
|
12
14
|
declare namespace symbols {
|
|
13
|
-
export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
|
|
15
|
+
export { symbols_ellipsis as ellipsis, error$1 as error, info$1 as info, message$1 as message, step$1 as step, success$1 as success, warning$1 as warning };
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
declare const text: (opts: TextOptions) => Promise<string>;
|
|
@@ -76,16 +78,17 @@ declare namespace logs {
|
|
|
76
78
|
export { logs_error as error, logs_info as info, logs_intro as intro, logs_list as list, logs_message as message, logs_note as note, logs_outro as outro, logs_step as step, logs_success as success, logs_table as table, logs_task as task, logs_warning as warning };
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
declare const
|
|
80
|
-
declare const
|
|
81
|
-
declare const
|
|
81
|
+
declare const wrap: (value: string, width: number, options?: Options) => string;
|
|
82
|
+
declare const length: (value: string) => number;
|
|
83
|
+
declare const truncate: (value: string, width: number) => string;
|
|
84
|
+
declare const pad: (texts: string[]) => (text: string, padding?: number, fill?: string) => string;
|
|
82
85
|
|
|
83
|
-
declare const
|
|
84
|
-
declare const
|
|
85
|
-
declare const
|
|
86
|
-
declare const
|
|
86
|
+
declare const ansi_length: typeof length;
|
|
87
|
+
declare const ansi_pad: typeof pad;
|
|
88
|
+
declare const ansi_truncate: typeof truncate;
|
|
89
|
+
declare const ansi_wrap: typeof wrap;
|
|
87
90
|
declare namespace ansi {
|
|
88
|
-
export {
|
|
91
|
+
export { ansi_length as length, ansi_pad as pad, ansi_truncate as truncate, ansi_wrap as wrap };
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
declare const color: chalk.ChalkInstance;
|
package/dist/index.js
CHANGED
|
@@ -7,17 +7,21 @@ var __export = (target, all) => {
|
|
|
7
7
|
// src/symbols.ts
|
|
8
8
|
var symbols_exports = {};
|
|
9
9
|
__export(symbols_exports, {
|
|
10
|
+
ellipsis: () => ellipsis,
|
|
10
11
|
error: () => error,
|
|
11
12
|
info: () => info,
|
|
13
|
+
message: () => message,
|
|
12
14
|
step: () => step,
|
|
13
15
|
success: () => success,
|
|
14
16
|
warning: () => warning
|
|
15
17
|
});
|
|
18
|
+
var message = "\u2502";
|
|
16
19
|
var step = "\u25C7";
|
|
17
20
|
var error = "\xD7";
|
|
18
21
|
var success = "\u25C6";
|
|
19
22
|
var warning = "\u25B2";
|
|
20
23
|
var info = "\xB7";
|
|
24
|
+
var ellipsis = "\u2026";
|
|
21
25
|
|
|
22
26
|
// src/prompts.ts
|
|
23
27
|
var prompts_exports = {};
|
|
@@ -115,7 +119,7 @@ __export(logs_exports, {
|
|
|
115
119
|
info: () => info2,
|
|
116
120
|
intro: () => intro,
|
|
117
121
|
list: () => list,
|
|
118
|
-
message: () =>
|
|
122
|
+
message: () => message2,
|
|
119
123
|
note: () => note,
|
|
120
124
|
outro: () => outro,
|
|
121
125
|
step: () => step2,
|
|
@@ -130,26 +134,27 @@ import Table from "cli-table3";
|
|
|
130
134
|
// src/ansi.ts
|
|
131
135
|
var ansi_exports = {};
|
|
132
136
|
__export(ansi_exports, {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
length: () => length,
|
|
138
|
+
pad: () => pad,
|
|
139
|
+
truncate: () => truncate,
|
|
140
|
+
wrap: () => wrap
|
|
137
141
|
});
|
|
138
|
-
import
|
|
139
|
-
import
|
|
140
|
-
import
|
|
141
|
-
var
|
|
142
|
-
return
|
|
142
|
+
import ansiTruncate from "ansi-truncate";
|
|
143
|
+
import ansiLength from "string-length";
|
|
144
|
+
import ansiWrap from "wrap-ansi";
|
|
145
|
+
var wrap = (value, width, options) => {
|
|
146
|
+
return ansiWrap(value, width, options);
|
|
143
147
|
};
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
var length = (value) => {
|
|
149
|
+
return ansiLength(value);
|
|
150
|
+
};
|
|
151
|
+
var truncate = (value, width) => {
|
|
152
|
+
return ansiTruncate(value, width, {
|
|
153
|
+
ellipsis
|
|
154
|
+
});
|
|
150
155
|
};
|
|
151
|
-
var
|
|
152
|
-
const size = Math.max(...texts.map((text2) =>
|
|
156
|
+
var pad = (texts) => {
|
|
157
|
+
const size = Math.max(...texts.map((text2) => ansiLength(text2)));
|
|
153
158
|
return (text2, padding = 0, fill) => {
|
|
154
159
|
return text2.padEnd(size + padding, fill);
|
|
155
160
|
};
|
|
@@ -162,37 +167,37 @@ var color = chalk;
|
|
|
162
167
|
// src/logs.ts
|
|
163
168
|
var endMargin = 3;
|
|
164
169
|
var intro = (title = "") => {
|
|
165
|
-
p_intro(
|
|
170
|
+
p_intro(truncate(title, process.stdout.columns - 6 - endMargin));
|
|
166
171
|
};
|
|
167
172
|
var outro = (title = "") => {
|
|
168
|
-
p_outro(
|
|
173
|
+
p_outro(truncate(title, process.stdout.columns - 6 - endMargin));
|
|
169
174
|
};
|
|
170
|
-
var note = (title,
|
|
175
|
+
var note = (title, message3) => {
|
|
171
176
|
const width = process.stdout.columns - 6 - endMargin;
|
|
172
177
|
p_note(
|
|
173
|
-
|
|
178
|
+
wrap(message3, width, {
|
|
174
179
|
hard: true
|
|
175
180
|
}),
|
|
176
|
-
|
|
181
|
+
truncate(title, width)
|
|
177
182
|
);
|
|
178
183
|
};
|
|
179
|
-
var logMessage = (symbol,
|
|
184
|
+
var logMessage = (symbol, message3) => {
|
|
180
185
|
log.message(
|
|
181
|
-
|
|
186
|
+
wrap(message3, process.stdout.columns - 6 - endMargin, {
|
|
182
187
|
hard: true,
|
|
183
188
|
trim: false
|
|
184
189
|
}),
|
|
185
190
|
{ symbol }
|
|
186
191
|
);
|
|
187
192
|
};
|
|
188
|
-
var
|
|
189
|
-
var error2 = (
|
|
190
|
-
var info2 = (
|
|
191
|
-
var step2 = (
|
|
192
|
-
var warning2 = (
|
|
193
|
-
var success2 = (
|
|
193
|
+
var message2 = (message3, symbol = color.gray(message)) => logMessage(symbol, message3);
|
|
194
|
+
var error2 = (message3) => logMessage(color.red(error), message3);
|
|
195
|
+
var info2 = (message3) => logMessage(color.blue(info), message3);
|
|
196
|
+
var step2 = (message3) => logMessage(color.green(step), message3);
|
|
197
|
+
var warning2 = (message3) => logMessage(color.yellow(warning), message3);
|
|
198
|
+
var success2 = (message3) => logMessage(color.green(success), message3);
|
|
194
199
|
var list = (title, data) => {
|
|
195
|
-
const padName =
|
|
200
|
+
const padName = pad(Object.keys(data));
|
|
196
201
|
note(
|
|
197
202
|
title,
|
|
198
203
|
Object.entries(data).map(([name, value]) => {
|
|
@@ -204,12 +209,12 @@ var task = async (opts) => {
|
|
|
204
209
|
let last;
|
|
205
210
|
const spin = spinner();
|
|
206
211
|
spin.start(opts.initialMessage);
|
|
207
|
-
const stop = (
|
|
208
|
-
spin.stop(
|
|
212
|
+
const stop = (message3, code) => {
|
|
213
|
+
spin.stop(truncate(message3 ?? last ?? opts.initialMessage, process.stdout.columns - 6 - endMargin), code);
|
|
209
214
|
};
|
|
210
215
|
try {
|
|
211
216
|
const result = await opts.task((m) => {
|
|
212
|
-
spin.message(
|
|
217
|
+
spin.message(truncate(m, process.stdout.columns - 6 - endMargin));
|
|
213
218
|
last = m;
|
|
214
219
|
});
|
|
215
220
|
stop(opts.successMessage);
|
|
@@ -221,21 +226,21 @@ var task = async (opts) => {
|
|
|
221
226
|
};
|
|
222
227
|
var table = (props) => {
|
|
223
228
|
log.message();
|
|
224
|
-
const
|
|
229
|
+
const length2 = Math.max(props.head.length, ...props.body.map((b) => b.length));
|
|
225
230
|
const padding = 2;
|
|
226
|
-
const totalPadding = padding * 2 *
|
|
231
|
+
const totalPadding = padding * 2 * length2;
|
|
227
232
|
const border = 1;
|
|
228
|
-
const totalBorder = (
|
|
233
|
+
const totalBorder = (length2 - 1) * border + 2;
|
|
229
234
|
const windowSize = process.stdout.columns;
|
|
230
|
-
const
|
|
231
|
-
const contentSizes = Array.from({ length }).map((_, i) => {
|
|
232
|
-
return Math.max(props.head[i]
|
|
235
|
+
const maxTableSize = windowSize - totalPadding - totalBorder - endMargin;
|
|
236
|
+
const contentSizes = Array.from({ length: length2 }).map((_, i) => {
|
|
237
|
+
return Math.max(length(props.head[i] ?? ""), ...props.body.map((b) => length(String(b[i]))));
|
|
233
238
|
});
|
|
234
|
-
const columnSizes = Array.from({ length }).map(() => {
|
|
239
|
+
const columnSizes = Array.from({ length: length2 }).map(() => {
|
|
235
240
|
return 0;
|
|
236
241
|
});
|
|
237
242
|
let leftover = Math.min(
|
|
238
|
-
|
|
243
|
+
maxTableSize,
|
|
239
244
|
contentSizes.reduce((total, size) => total + size, 0)
|
|
240
245
|
);
|
|
241
246
|
while (leftover > 0) {
|
|
@@ -251,7 +256,7 @@ var table = (props) => {
|
|
|
251
256
|
const table2 = new Table({
|
|
252
257
|
head: props.head.map(
|
|
253
258
|
(value, x) => "\n" + color.reset.whiteBright.bold(
|
|
254
|
-
|
|
259
|
+
wrap(value, columnSizes[x], {
|
|
255
260
|
hard: true
|
|
256
261
|
})
|
|
257
262
|
)
|
|
@@ -276,7 +281,7 @@ var table = (props) => {
|
|
|
276
281
|
if (typeof value === "number") {
|
|
277
282
|
return color.blue(value);
|
|
278
283
|
}
|
|
279
|
-
return
|
|
284
|
+
return wrap(value, columnSizes[x], {
|
|
280
285
|
hard: true
|
|
281
286
|
});
|
|
282
287
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@awsless/clui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@clack/prompts": "^0.11.0",
|
|
28
|
-
"ansi-
|
|
28
|
+
"ansi-truncate": "^1.2.0",
|
|
29
29
|
"chalk": "^5.4.1",
|
|
30
30
|
"cli-table3": "^0.6.5",
|
|
31
31
|
"string-length": "^6.0.0",
|