@awsless/clui 0.0.3 → 0.0.5

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/index.cjs CHANGED
@@ -33,13 +33,11 @@ __export(index_exports, {
33
33
  Cancelled: () => Cancelled,
34
34
  ansi: () => ansi_exports,
35
35
  color: () => color,
36
- isCancel: () => import_prompts4.isCancel,
37
36
  log: () => logs_exports,
38
37
  prompt: () => prompts_exports,
39
38
  symbol: () => symbols_exports
40
39
  });
41
40
  module.exports = __toCommonJS(index_exports);
42
- var import_prompts4 = require("@clack/prompts");
43
41
 
44
42
  // src/symbols.ts
45
43
  var symbols_exports = {};
@@ -76,9 +74,9 @@ var Cancelled = class extends Error {
76
74
  super("cancelled");
77
75
  }
78
76
  };
79
- async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
77
+ async function wrapPrompt(cb) {
80
78
  const result = await cb();
81
- if ((0, import_prompts.isCancel)(result) && throwOnCancel) {
79
+ if ((0, import_prompts.isCancel)(result)) {
82
80
  throw new Cancelled();
83
81
  }
84
82
  return result;
@@ -88,12 +86,12 @@ async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
88
86
  var text = async (opts) => {
89
87
  return wrapPrompt(() => {
90
88
  return (0, import_prompts2.text)(opts);
91
- }, opts);
89
+ });
92
90
  };
93
91
  var password = async (opts) => {
94
92
  return wrapPrompt(() => {
95
93
  return (0, import_prompts2.password)({ mask: "*", ...opts });
96
- }, opts);
94
+ });
97
95
  };
98
96
  var integer = async (opts) => {
99
97
  const result = await text({
@@ -107,10 +105,7 @@ var integer = async (opts) => {
107
105
  return;
108
106
  }
109
107
  });
110
- if (typeof result === "string") {
111
- return parseInt(result, 10);
112
- }
113
- return result;
108
+ return parseInt(result, 10);
114
109
  };
115
110
  var float = async (opts) => {
116
111
  const result = await text({
@@ -124,25 +119,22 @@ var float = async (opts) => {
124
119
  return;
125
120
  }
126
121
  });
127
- if (typeof result === "string") {
128
- return parseFloat(result);
129
- }
130
- return result;
122
+ return parseFloat(result);
131
123
  };
132
124
  var confirm = async (opts) => {
133
125
  return wrapPrompt(() => {
134
126
  return (0, import_prompts2.confirm)(opts);
135
- }, opts);
127
+ });
136
128
  };
137
129
  var select = async (opts) => {
138
130
  return wrapPrompt(() => {
139
131
  return (0, import_prompts2.select)(opts);
140
- }, opts);
132
+ });
141
133
  };
142
134
  var multiSelect = async (opts) => {
143
135
  return wrapPrompt(() => {
144
136
  return (0, import_prompts2.multiselect)(opts);
145
- }, opts);
137
+ });
146
138
  };
147
139
 
148
140
  // src/logs.ts
@@ -197,15 +189,15 @@ var import_chalk = __toESM(require("chalk"), 1);
197
189
  var color = import_chalk.default;
198
190
 
199
191
  // src/logs.ts
200
- var endMargin = 1;
192
+ var endMargin = 3;
201
193
  var intro = (title = "") => {
202
- (0, import_prompts3.intro)(subString(title, process.stdout.columns - 8 - endMargin));
194
+ (0, import_prompts3.intro)(subString(title, process.stdout.columns - 6 - endMargin));
203
195
  };
204
196
  var outro = (title = "") => {
205
- (0, import_prompts3.outro)(subString(title, process.stdout.columns - 8 - endMargin));
197
+ (0, import_prompts3.outro)(subString(title, process.stdout.columns - 6 - endMargin));
206
198
  };
207
199
  var note = (title, message2) => {
208
- const width = process.stdout.columns - 8 - endMargin;
200
+ const width = process.stdout.columns - 6 - endMargin;
209
201
  (0, import_prompts3.note)(
210
202
  wrapString(message2, width, {
211
203
  hard: true
@@ -215,7 +207,7 @@ var note = (title, message2) => {
215
207
  };
216
208
  var logMessage = (symbol, message2) => {
217
209
  import_prompts3.log.message(
218
- wrapString(message2, process.stdout.columns - 8 - endMargin, {
210
+ wrapString(message2, process.stdout.columns - 6 - endMargin, {
219
211
  hard: true,
220
212
  trim: false
221
213
  }),
@@ -242,11 +234,11 @@ var task = async (opts) => {
242
234
  const spin = (0, import_prompts3.spinner)();
243
235
  spin.start(opts.initialMessage);
244
236
  const stop = (message2, code) => {
245
- spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 8 - endMargin), code);
237
+ spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 6 - endMargin), code);
246
238
  };
247
239
  try {
248
240
  const result = await opts.task((m) => {
249
- spin.message(subString(m, process.stdout.columns - 8 - endMargin));
241
+ spin.message(subString(m, process.stdout.columns - 6 - endMargin));
250
242
  last = m;
251
243
  });
252
244
  stop(opts.successMessage);
@@ -258,18 +250,37 @@ var task = async (opts) => {
258
250
  };
259
251
  var table = (props) => {
260
252
  import_prompts3.log.message();
261
- const padding = 2;
262
- const totalPadding = padding * 2;
263
253
  const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
264
- const gap = totalPadding + 1;
265
- const totalGap = (length - 1) * gap;
266
- const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
267
- const column = Math.floor(max / length);
268
- const leftover = Math.floor(max - column * length);
254
+ const padding = 2;
255
+ const totalPadding = padding * 2 * length;
256
+ const border = 1;
257
+ const totalBorder = (length - 1) * border + 2;
258
+ const windowSize = process.stdout.columns;
259
+ const max = windowSize - totalPadding - totalBorder - endMargin;
260
+ const contentSizes = Array.from({ length }).map((_, i) => {
261
+ return Math.max(props.head[i]?.length ?? 0, ...props.body.map((b) => String(b[i])?.length));
262
+ });
263
+ const columnSizes = Array.from({ length }).map(() => {
264
+ return 0;
265
+ });
266
+ let leftover = Math.min(
267
+ max,
268
+ contentSizes.reduce((total, size) => total + size, 0)
269
+ );
270
+ while (leftover > 0) {
271
+ for (const x in columnSizes) {
272
+ const columnSize = columnSizes[x];
273
+ const contentSize = contentSizes[x];
274
+ if (leftover > 0 && columnSize < contentSize) {
275
+ leftover--;
276
+ columnSizes[x] = columnSize + 1;
277
+ }
278
+ }
279
+ }
269
280
  const table2 = new import_cli_table3.default({
270
281
  head: props.head.map(
271
- (h, i) => "\n" + color.reset.whiteBright.bold(
272
- wrapString(h, column + (i + 1 === length ? leftover : 0), {
282
+ (value, x) => "\n" + color.reset.whiteBright.bold(
283
+ wrapString(value, columnSizes[x], {
273
284
  hard: true
274
285
  })
275
286
  )
@@ -294,7 +305,7 @@ var table = (props) => {
294
305
  if (typeof value === "number") {
295
306
  return color.blue(value);
296
307
  }
297
- return wrapString(value, column + (x + 1 === length ? leftover : 0), {
308
+ return wrapString(value, columnSizes[x], {
298
309
  hard: true
299
310
  });
300
311
  });
@@ -307,7 +318,6 @@ var table = (props) => {
307
318
  Cancelled,
308
319
  ansi,
309
320
  color,
310
- isCancel,
311
321
  log,
312
322
  prompt,
313
323
  symbol
package/dist/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
2
- export { isCancel } from '@clack/prompts';
3
2
  import stringLength from 'string-length';
4
3
  import { Options } from 'wrap-ansi';
5
4
  import * as chalk from 'chalk';
@@ -14,26 +13,19 @@ declare namespace symbols {
14
13
  export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
15
14
  }
16
15
 
17
- declare class Cancelled extends Error {
18
- constructor();
19
- }
20
- type WrapPromptOptions<T extends boolean | undefined = boolean> = {
21
- throwOnCancel?: T;
22
- };
23
-
24
- declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
25
- declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
16
+ declare const text: (opts: TextOptions) => Promise<string>;
17
+ declare const password: (opts: PasswordOptions) => Promise<string>;
26
18
  type NumberOptions = {
27
19
  message: string;
28
20
  placeholder?: string;
29
21
  defaultValue?: number;
30
22
  initialValue?: number;
31
23
  };
32
- declare const integer: <T extends boolean | undefined = undefined>(opts: NumberOptions & WrapPromptOptions<T>) => Promise<number | (T extends false ? string | symbol : string)>;
33
- declare const float: <T extends boolean | undefined = undefined>(opts: NumberOptions & WrapPromptOptions<T>) => Promise<number | (T extends false ? string | symbol : string)>;
34
- declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
35
- declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
36
- declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
24
+ declare const integer: (opts: NumberOptions) => Promise<number>;
25
+ declare const float: (opts: NumberOptions) => Promise<number>;
26
+ declare const confirm: (opts: ConfirmOptions) => Promise<boolean>;
27
+ declare const select: <Value>(opts: SelectOptions<Value>) => Promise<Exclude<Value, symbol>>;
28
+ declare const multiSelect: <Value>(opts: MultiSelectOptions<Value>) => Promise<Value[]>;
37
29
 
38
30
  declare const prompts_confirm: typeof confirm;
39
31
  declare const prompts_float: typeof float;
@@ -98,4 +90,8 @@ declare namespace ansi {
98
90
 
99
91
  declare const color: chalk.ChalkInstance;
100
92
 
93
+ declare class Cancelled extends Error {
94
+ constructor();
95
+ }
96
+
101
97
  export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { TextOptions, PasswordOptions, ConfirmOptions, SelectOptions, MultiSelectOptions } from '@clack/prompts';
2
- export { isCancel } from '@clack/prompts';
3
2
  import stringLength from 'string-length';
4
3
  import { Options } from 'wrap-ansi';
5
4
  import * as chalk from 'chalk';
@@ -14,26 +13,19 @@ declare namespace symbols {
14
13
  export { error$1 as error, info$1 as info, step$1 as step, success$1 as success, warning$1 as warning };
15
14
  }
16
15
 
17
- declare class Cancelled extends Error {
18
- constructor();
19
- }
20
- type WrapPromptOptions<T extends boolean | undefined = boolean> = {
21
- throwOnCancel?: T;
22
- };
23
-
24
- declare const text: <T extends boolean | undefined = undefined>(opts: TextOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
25
- declare const password: <T extends boolean | undefined = undefined>(opts: PasswordOptions & WrapPromptOptions<T>) => Promise<T extends false ? string | symbol : string>;
16
+ declare const text: (opts: TextOptions) => Promise<string>;
17
+ declare const password: (opts: PasswordOptions) => Promise<string>;
26
18
  type NumberOptions = {
27
19
  message: string;
28
20
  placeholder?: string;
29
21
  defaultValue?: number;
30
22
  initialValue?: number;
31
23
  };
32
- declare const integer: <T extends boolean | undefined = undefined>(opts: NumberOptions & WrapPromptOptions<T>) => Promise<number | (T extends false ? string | symbol : string)>;
33
- declare const float: <T extends boolean | undefined = undefined>(opts: NumberOptions & WrapPromptOptions<T>) => Promise<number | (T extends false ? string | symbol : string)>;
34
- declare const confirm: <T extends boolean | undefined = undefined>(opts: ConfirmOptions & WrapPromptOptions<T>) => Promise<T extends false ? boolean | symbol : boolean>;
35
- declare const select: <Value, T extends boolean | undefined = undefined>(opts: SelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value : Exclude<Value, symbol>>;
36
- declare const multiSelect: <Value, T extends boolean | undefined = undefined>(opts: MultiSelectOptions<Value> & WrapPromptOptions<T>) => Promise<T extends false ? symbol | Value[] : Value[]>;
24
+ declare const integer: (opts: NumberOptions) => Promise<number>;
25
+ declare const float: (opts: NumberOptions) => Promise<number>;
26
+ declare const confirm: (opts: ConfirmOptions) => Promise<boolean>;
27
+ declare const select: <Value>(opts: SelectOptions<Value>) => Promise<Exclude<Value, symbol>>;
28
+ declare const multiSelect: <Value>(opts: MultiSelectOptions<Value>) => Promise<Value[]>;
37
29
 
38
30
  declare const prompts_confirm: typeof confirm;
39
31
  declare const prompts_float: typeof float;
@@ -98,4 +90,8 @@ declare namespace ansi {
98
90
 
99
91
  declare const color: chalk.ChalkInstance;
100
92
 
93
+ declare class Cancelled extends Error {
94
+ constructor();
95
+ }
96
+
101
97
  export { Cancelled, ansi, color, logs as log, prompts as prompt, symbols as symbol };
package/dist/index.js CHANGED
@@ -4,9 +4,6 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
- // src/index.ts
8
- import { isCancel as isCancel2 } from "@clack/prompts";
9
-
10
7
  // src/symbols.ts
11
8
  var symbols_exports = {};
12
9
  __export(symbols_exports, {
@@ -48,9 +45,9 @@ var Cancelled = class extends Error {
48
45
  super("cancelled");
49
46
  }
50
47
  };
51
- async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
48
+ async function wrapPrompt(cb) {
52
49
  const result = await cb();
53
- if (isCancel(result) && throwOnCancel) {
50
+ if (isCancel(result)) {
54
51
  throw new Cancelled();
55
52
  }
56
53
  return result;
@@ -60,12 +57,12 @@ async function wrapPrompt(cb, { throwOnCancel = true } = {}) {
60
57
  var text = async (opts) => {
61
58
  return wrapPrompt(() => {
62
59
  return p_text(opts);
63
- }, opts);
60
+ });
64
61
  };
65
62
  var password = async (opts) => {
66
63
  return wrapPrompt(() => {
67
64
  return p_password({ mask: "*", ...opts });
68
- }, opts);
65
+ });
69
66
  };
70
67
  var integer = async (opts) => {
71
68
  const result = await text({
@@ -79,10 +76,7 @@ var integer = async (opts) => {
79
76
  return;
80
77
  }
81
78
  });
82
- if (typeof result === "string") {
83
- return parseInt(result, 10);
84
- }
85
- return result;
79
+ return parseInt(result, 10);
86
80
  };
87
81
  var float = async (opts) => {
88
82
  const result = await text({
@@ -96,25 +90,22 @@ var float = async (opts) => {
96
90
  return;
97
91
  }
98
92
  });
99
- if (typeof result === "string") {
100
- return parseFloat(result);
101
- }
102
- return result;
93
+ return parseFloat(result);
103
94
  };
104
95
  var confirm = async (opts) => {
105
96
  return wrapPrompt(() => {
106
97
  return p_confirm(opts);
107
- }, opts);
98
+ });
108
99
  };
109
100
  var select = async (opts) => {
110
101
  return wrapPrompt(() => {
111
102
  return p_select(opts);
112
- }, opts);
103
+ });
113
104
  };
114
105
  var multiSelect = async (opts) => {
115
106
  return wrapPrompt(() => {
116
107
  return p_multiselect(opts);
117
- }, opts);
108
+ });
118
109
  };
119
110
 
120
111
  // src/logs.ts
@@ -169,15 +160,15 @@ import chalk from "chalk";
169
160
  var color = chalk;
170
161
 
171
162
  // src/logs.ts
172
- var endMargin = 1;
163
+ var endMargin = 3;
173
164
  var intro = (title = "") => {
174
- p_intro(subString(title, process.stdout.columns - 8 - endMargin));
165
+ p_intro(subString(title, process.stdout.columns - 6 - endMargin));
175
166
  };
176
167
  var outro = (title = "") => {
177
- p_outro(subString(title, process.stdout.columns - 8 - endMargin));
168
+ p_outro(subString(title, process.stdout.columns - 6 - endMargin));
178
169
  };
179
170
  var note = (title, message2) => {
180
- const width = process.stdout.columns - 8 - endMargin;
171
+ const width = process.stdout.columns - 6 - endMargin;
181
172
  p_note(
182
173
  wrapString(message2, width, {
183
174
  hard: true
@@ -187,7 +178,7 @@ var note = (title, message2) => {
187
178
  };
188
179
  var logMessage = (symbol, message2) => {
189
180
  log.message(
190
- wrapString(message2, process.stdout.columns - 8 - endMargin, {
181
+ wrapString(message2, process.stdout.columns - 6 - endMargin, {
191
182
  hard: true,
192
183
  trim: false
193
184
  }),
@@ -214,11 +205,11 @@ var task = async (opts) => {
214
205
  const spin = spinner();
215
206
  spin.start(opts.initialMessage);
216
207
  const stop = (message2, code) => {
217
- spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 8 - endMargin), code);
208
+ spin.stop(subString(message2 ?? last ?? opts.initialMessage, process.stdout.columns - 6 - endMargin), code);
218
209
  };
219
210
  try {
220
211
  const result = await opts.task((m) => {
221
- spin.message(subString(m, process.stdout.columns - 8 - endMargin));
212
+ spin.message(subString(m, process.stdout.columns - 6 - endMargin));
222
213
  last = m;
223
214
  });
224
215
  stop(opts.successMessage);
@@ -230,18 +221,37 @@ var task = async (opts) => {
230
221
  };
231
222
  var table = (props) => {
232
223
  log.message();
233
- const padding = 2;
234
- const totalPadding = padding * 2;
235
224
  const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
236
- const gap = totalPadding + 1;
237
- const totalGap = (length - 1) * gap;
238
- const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
239
- const column = Math.floor(max / length);
240
- const leftover = Math.floor(max - column * length);
225
+ const padding = 2;
226
+ const totalPadding = padding * 2 * length;
227
+ const border = 1;
228
+ const totalBorder = (length - 1) * border + 2;
229
+ const windowSize = process.stdout.columns;
230
+ const max = windowSize - totalPadding - totalBorder - endMargin;
231
+ const contentSizes = Array.from({ length }).map((_, i) => {
232
+ return Math.max(props.head[i]?.length ?? 0, ...props.body.map((b) => String(b[i])?.length));
233
+ });
234
+ const columnSizes = Array.from({ length }).map(() => {
235
+ return 0;
236
+ });
237
+ let leftover = Math.min(
238
+ max,
239
+ contentSizes.reduce((total, size) => total + size, 0)
240
+ );
241
+ while (leftover > 0) {
242
+ for (const x in columnSizes) {
243
+ const columnSize = columnSizes[x];
244
+ const contentSize = contentSizes[x];
245
+ if (leftover > 0 && columnSize < contentSize) {
246
+ leftover--;
247
+ columnSizes[x] = columnSize + 1;
248
+ }
249
+ }
250
+ }
241
251
  const table2 = new Table({
242
252
  head: props.head.map(
243
- (h, i) => "\n" + color.reset.whiteBright.bold(
244
- wrapString(h, column + (i + 1 === length ? leftover : 0), {
253
+ (value, x) => "\n" + color.reset.whiteBright.bold(
254
+ wrapString(value, columnSizes[x], {
245
255
  hard: true
246
256
  })
247
257
  )
@@ -266,7 +276,7 @@ var table = (props) => {
266
276
  if (typeof value === "number") {
267
277
  return color.blue(value);
268
278
  }
269
- return wrapString(value, column + (x + 1 === length ? leftover : 0), {
279
+ return wrapString(value, columnSizes[x], {
270
280
  hard: true
271
281
  });
272
282
  });
@@ -278,7 +288,6 @@ export {
278
288
  Cancelled,
279
289
  ansi_exports as ansi,
280
290
  color,
281
- isCancel2 as isCancel,
282
291
  logs_exports as log,
283
292
  prompts_exports as prompt,
284
293
  symbols_exports as symbol
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/clui",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {