@kaynooo/cli-pkg 0.13.2 → 0.13.3

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 (2) hide show
  1. package/dist/cli.js +16 -17
  2. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -1044,13 +1044,15 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1044
1044
  } };
1045
1045
  const write = stream.write.bind(stream);
1046
1046
  let frame = 0;
1047
- let drawn = [];
1048
- const columns = () => stream.columns === undefined || stream.columns === 0 ? 80 : stream.columns;
1049
- const rowsDrawn = () => drawn.reduce((sum, width) => sum + Math.max(1, Math.ceil(width / columns())), 0);
1047
+ let drawn = false;
1048
+ const columns = () => {
1049
+ const now = stream.getWindowSize?.()[0] ?? stream.columns;
1050
+ return now === undefined || now === 0 ? 80 : now;
1051
+ };
1050
1052
  const clear = () => {
1051
- if (drawn.length > 0)
1052
- write(`${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}`);
1053
- drawn = [];
1053
+ if (drawn)
1054
+ write(CLEAR_BELOW);
1055
+ drawn = false;
1054
1056
  };
1055
1057
  const draw = () => {
1056
1058
  const width = columns() - 1;
@@ -1060,9 +1062,9 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
1060
1062
  clear();
1061
1063
  return;
1062
1064
  }
1063
- write(`${drawn.length > 0 ? `${CLEAR_LINE}${LINE_UP.repeat(rowsDrawn() - 1)}` : CLEAR_LINE}${lines.join(`
1064
- `)}`);
1065
- drawn = lines.map((line) => Bun.stringWidth(line));
1065
+ write(`${CLEAR_BELOW}${lines.join(`
1066
+ `)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
1067
+ drawn = true;
1066
1068
  };
1067
1069
  const timer = setInterval(draw, FRAME_MS);
1068
1070
  stream.on?.("resize", draw);
@@ -1162,7 +1164,7 @@ function interceptOutput(clear) {
1162
1164
  }
1163
1165
  };
1164
1166
  }
1165
- var FRAMES, FRAME_MS = 200, CLEAR_LINE = "\r\x1B[2K", LINE_UP = "\x1B[1A\x1B[2K", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
1167
+ var FRAMES, FRAME_MS = 200, CLEAR_BELOW = "\r\x1B[J", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
1166
1168
  var init_progress = __esm(() => {
1167
1169
  init_format();
1168
1170
  init_process();
@@ -3391,16 +3393,13 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
3391
3393
  if (!isInteractive(terminal))
3392
3394
  fail(`cannot ask "${question}" off a terminal`, 2, hint);
3393
3395
  const colors = paint(stderr);
3394
- let drawn = [];
3395
3396
  let current = "asking";
3396
3397
  let outcome;
3397
3398
  const columns = () => stderr.columns || 80;
3398
- const draw = (state) => {
3399
+ const draw = (state, last = false) => {
3399
3400
  const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
3400
- const rows = drawn.reduce((sum, line) => sum + Math.max(1, Math.ceil(Bun.stringWidth(line) / columns())), 0);
3401
- stderr.write(`${rows > 1 ? `\x1B[${rows - 1}A` : ""}\r\x1B[0J${frame.join(`
3402
- `)}`);
3403
- drawn = frame;
3401
+ stderr.write(`\r\x1B[0J${frame.join(`
3402
+ `)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
3404
3403
  current = state;
3405
3404
  };
3406
3405
  const redraw = () => draw(current);
@@ -3436,7 +3435,7 @@ async function ask(question, { hint, terminal = process19 }, render, press) {
3436
3435
  });
3437
3436
  } finally {
3438
3437
  stderr.off?.("resize", redraw);
3439
- draw(outcome ?? "cancel");
3438
+ draw(outcome ?? "cancel", true);
3440
3439
  stderr.write(`
3441
3440
  \x1B[?25h\x1B[?2004l`);
3442
3441
  stdin.setRawMode(false);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-pkg",
3
3
  "type": "module",
4
- "version": "0.13.2",
4
+ "version": "0.13.3",
5
5
  "description": "pkg: check an npm package before it is added, for a guessed name, a version under two weeks old and install scripts.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -33,6 +33,6 @@
33
33
  "@kaynooo/utils": "3.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@kaynooo/cli-kit": "0.36.1"
36
+ "@kaynooo/cli-kit": "0.37.0"
37
37
  }
38
38
  }