@awsless/clui 0.0.4 → 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
@@ -189,15 +189,15 @@ var import_chalk = __toESM(require("chalk"), 1);
189
189
  var color = import_chalk.default;
190
190
 
191
191
  // src/logs.ts
192
- var endMargin = 1;
192
+ var endMargin = 3;
193
193
  var intro = (title = "") => {
194
- (0, import_prompts3.intro)(subString(title, process.stdout.columns - 8 - endMargin));
194
+ (0, import_prompts3.intro)(subString(title, process.stdout.columns - 6 - endMargin));
195
195
  };
196
196
  var outro = (title = "") => {
197
- (0, import_prompts3.outro)(subString(title, process.stdout.columns - 8 - endMargin));
197
+ (0, import_prompts3.outro)(subString(title, process.stdout.columns - 6 - endMargin));
198
198
  };
199
199
  var note = (title, message2) => {
200
- const width = process.stdout.columns - 8 - endMargin;
200
+ const width = process.stdout.columns - 6 - endMargin;
201
201
  (0, import_prompts3.note)(
202
202
  wrapString(message2, width, {
203
203
  hard: true
@@ -207,7 +207,7 @@ var note = (title, message2) => {
207
207
  };
208
208
  var logMessage = (symbol, message2) => {
209
209
  import_prompts3.log.message(
210
- wrapString(message2, process.stdout.columns - 8 - endMargin, {
210
+ wrapString(message2, process.stdout.columns - 6 - endMargin, {
211
211
  hard: true,
212
212
  trim: false
213
213
  }),
@@ -234,11 +234,11 @@ var task = async (opts) => {
234
234
  const spin = (0, import_prompts3.spinner)();
235
235
  spin.start(opts.initialMessage);
236
236
  const stop = (message2, code) => {
237
- 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);
238
238
  };
239
239
  try {
240
240
  const result = await opts.task((m) => {
241
- spin.message(subString(m, process.stdout.columns - 8 - endMargin));
241
+ spin.message(subString(m, process.stdout.columns - 6 - endMargin));
242
242
  last = m;
243
243
  });
244
244
  stop(opts.successMessage);
@@ -250,18 +250,37 @@ var task = async (opts) => {
250
250
  };
251
251
  var table = (props) => {
252
252
  import_prompts3.log.message();
253
- const padding = 2;
254
- const totalPadding = padding * 2;
255
253
  const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
256
- const gap = totalPadding + 1;
257
- const totalGap = (length - 1) * gap;
258
- const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
259
- const column = Math.floor(max / length);
260
- 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
+ }
261
280
  const table2 = new import_cli_table3.default({
262
281
  head: props.head.map(
263
- (h, i) => "\n" + color.reset.whiteBright.bold(
264
- wrapString(h, column + (i + 1 === length ? leftover : 0), {
282
+ (value, x) => "\n" + color.reset.whiteBright.bold(
283
+ wrapString(value, columnSizes[x], {
265
284
  hard: true
266
285
  })
267
286
  )
@@ -286,7 +305,7 @@ var table = (props) => {
286
305
  if (typeof value === "number") {
287
306
  return color.blue(value);
288
307
  }
289
- return wrapString(value, column + (x + 1 === length ? leftover : 0), {
308
+ return wrapString(value, columnSizes[x], {
290
309
  hard: true
291
310
  });
292
311
  });
package/dist/index.js CHANGED
@@ -160,15 +160,15 @@ import chalk from "chalk";
160
160
  var color = chalk;
161
161
 
162
162
  // src/logs.ts
163
- var endMargin = 1;
163
+ var endMargin = 3;
164
164
  var intro = (title = "") => {
165
- p_intro(subString(title, process.stdout.columns - 8 - endMargin));
165
+ p_intro(subString(title, process.stdout.columns - 6 - endMargin));
166
166
  };
167
167
  var outro = (title = "") => {
168
- p_outro(subString(title, process.stdout.columns - 8 - endMargin));
168
+ p_outro(subString(title, process.stdout.columns - 6 - endMargin));
169
169
  };
170
170
  var note = (title, message2) => {
171
- const width = process.stdout.columns - 8 - endMargin;
171
+ const width = process.stdout.columns - 6 - endMargin;
172
172
  p_note(
173
173
  wrapString(message2, width, {
174
174
  hard: true
@@ -178,7 +178,7 @@ var note = (title, message2) => {
178
178
  };
179
179
  var logMessage = (symbol, message2) => {
180
180
  log.message(
181
- wrapString(message2, process.stdout.columns - 8 - endMargin, {
181
+ wrapString(message2, process.stdout.columns - 6 - endMargin, {
182
182
  hard: true,
183
183
  trim: false
184
184
  }),
@@ -205,11 +205,11 @@ var task = async (opts) => {
205
205
  const spin = spinner();
206
206
  spin.start(opts.initialMessage);
207
207
  const stop = (message2, code) => {
208
- 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);
209
209
  };
210
210
  try {
211
211
  const result = await opts.task((m) => {
212
- spin.message(subString(m, process.stdout.columns - 8 - endMargin));
212
+ spin.message(subString(m, process.stdout.columns - 6 - endMargin));
213
213
  last = m;
214
214
  });
215
215
  stop(opts.successMessage);
@@ -221,18 +221,37 @@ var task = async (opts) => {
221
221
  };
222
222
  var table = (props) => {
223
223
  log.message();
224
- const padding = 2;
225
- const totalPadding = padding * 2;
226
224
  const length = Math.max(props.head.length, ...props.body.map((b) => b.length));
227
- const gap = totalPadding + 1;
228
- const totalGap = (length - 1) * gap;
229
- const max = process.stdout.columns - 4 - totalPadding - totalGap - endMargin;
230
- const column = Math.floor(max / length);
231
- 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
+ }
232
251
  const table2 = new Table({
233
252
  head: props.head.map(
234
- (h, i) => "\n" + color.reset.whiteBright.bold(
235
- wrapString(h, column + (i + 1 === length ? leftover : 0), {
253
+ (value, x) => "\n" + color.reset.whiteBright.bold(
254
+ wrapString(value, columnSizes[x], {
236
255
  hard: true
237
256
  })
238
257
  )
@@ -257,7 +276,7 @@ var table = (props) => {
257
276
  if (typeof value === "number") {
258
277
  return color.blue(value);
259
278
  }
260
- return wrapString(value, column + (x + 1 === length ? leftover : 0), {
279
+ return wrapString(value, columnSizes[x], {
261
280
  hard: true
262
281
  });
263
282
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/clui",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {