@inquirer/core 5.0.0 → 5.0.1

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.
@@ -94,7 +94,9 @@ exports.effectScheduler = {
94
94
  store.hooksEffect.forEach((effect) => {
95
95
  effect();
96
96
  });
97
+ // Warning: Clean the hooks before exiting the `withUpdates` block.
98
+ // Failure to do so means an updates would hit the same effects again.
99
+ store.hooksEffect.length = 0;
97
100
  })();
98
- store.hooksEffect.length = 0;
99
101
  },
100
102
  };
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const cli_width_1 = __importDefault(require("cli-width"));
7
6
  const strip_ansi_1 = __importDefault(require("strip-ansi"));
8
7
  const ansi_escapes_1 = __importDefault(require("ansi-escapes"));
9
8
  const utils_mjs_1 = require('./utils.js');
@@ -57,7 +56,7 @@ class ScreenManager {
57
56
  this.rl.setPrompt(prompt);
58
57
  // SetPrompt will change cursor position, now we can get correct value
59
58
  this.cursorPos = this.rl.getCursorPos();
60
- const width = (0, cli_width_1.default)({ defaultWidth: 80, output: this.rl.output });
59
+ const width = (0, utils_mjs_1.readlineWidth)();
61
60
  content = (0, utils_mjs_1.breakLines)(content, width);
62
61
  bottomContent = (0, utils_mjs_1.breakLines)(bottomContent, width);
63
62
  // Manually insert an extra line if we're at the end of the line.
@@ -5,17 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.usePagination = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
- const cli_width_1 = __importDefault(require("cli-width"));
9
8
  const utils_mjs_1 = require('./utils.js');
10
- const hook_engine_mjs_1 = require('./hook-engine.js');
11
9
  const use_ref_mjs_1 = require('./use-ref.js');
12
10
  function usePagination(output, { active, pageSize = 7, }) {
13
- const rl = (0, hook_engine_mjs_1.readline)();
14
11
  const state = (0, use_ref_mjs_1.useRef)({
15
12
  pointer: 0,
16
13
  lastIndex: 0,
17
14
  });
18
- const width = (0, cli_width_1.default)({ defaultWidth: 80, output: rl.output });
15
+ const width = (0, utils_mjs_1.readlineWidth)();
19
16
  const lines = (0, utils_mjs_1.breakLines)(output, width).split('\n');
20
17
  // Make sure there's enough lines to paginate
21
18
  if (lines.length <= pageSize) {
@@ -3,8 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.breakLines = void 0;
6
+ exports.readlineWidth = exports.breakLines = void 0;
7
+ const cli_width_1 = __importDefault(require("cli-width"));
7
8
  const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
9
+ const hook_engine_mjs_1 = require('./hook-engine.js');
8
10
  /**
9
11
  * Force line returns at specific width. This function is ANSI code friendly and it'll
10
12
  * ignore invisible codes during width calculation.
@@ -12,10 +14,20 @@ const wrap_ansi_1 = __importDefault(require("wrap-ansi"));
12
14
  * @param {number} width
13
15
  * @return {string}
14
16
  */
15
- const breakLines = (content, width) => content
16
- .split('\n')
17
- .flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
18
- .split('\n')
19
- .map((str) => str.trimEnd()))
20
- .join('\n');
17
+ function breakLines(content, width) {
18
+ return content
19
+ .split('\n')
20
+ .flatMap((line) => (0, wrap_ansi_1.default)(line, width, { trim: false, hard: true })
21
+ .split('\n')
22
+ .map((str) => str.trimEnd()))
23
+ .join('\n');
24
+ }
21
25
  exports.breakLines = breakLines;
26
+ /**
27
+ * Returns the width of the active readline, or 80 as default value.
28
+ * @returns {number}
29
+ */
30
+ function readlineWidth() {
31
+ return (0, cli_width_1.default)({ defaultWidth: 80, output: (0, hook_engine_mjs_1.readline)().output });
32
+ }
33
+ exports.readlineWidth = readlineWidth;
@@ -5,4 +5,9 @@
5
5
  * @param {number} width
6
6
  * @return {string}
7
7
  */
8
- export declare const breakLines: (content: string, width: number) => string;
8
+ export declare function breakLines(content: string, width: number): string;
9
+ /**
10
+ * Returns the width of the active readline, or 80 as default value.
11
+ * @returns {number}
12
+ */
13
+ export declare function readlineWidth(): number;
@@ -85,7 +85,9 @@ export const effectScheduler = {
85
85
  store.hooksEffect.forEach((effect) => {
86
86
  effect();
87
87
  });
88
+ // Warning: Clean the hooks before exiting the `withUpdates` block.
89
+ // Failure to do so means an updates would hit the same effects again.
90
+ store.hooksEffect.length = 0;
88
91
  })();
89
- store.hooksEffect.length = 0;
90
92
  },
91
93
  };
@@ -1,7 +1,6 @@
1
- import cliWidth from 'cli-width';
2
1
  import stripAnsi from 'strip-ansi';
3
2
  import ansiEscapes from 'ansi-escapes';
4
- import { breakLines } from './utils.mjs';
3
+ import { breakLines, readlineWidth } from './utils.mjs';
5
4
  const height = (content) => content.split('\n').length;
6
5
  const lastLine = (content) => content.split('\n').pop() ?? '';
7
6
  export default class ScreenManager {
@@ -33,7 +32,7 @@ export default class ScreenManager {
33
32
  this.rl.setPrompt(prompt);
34
33
  // SetPrompt will change cursor position, now we can get correct value
35
34
  this.cursorPos = this.rl.getCursorPos();
36
- const width = cliWidth({ defaultWidth: 80, output: this.rl.output });
35
+ const width = readlineWidth();
37
36
  content = breakLines(content, width);
38
37
  bottomContent = breakLines(bottomContent, width);
39
38
  // Manually insert an extra line if we're at the end of the line.
@@ -1,15 +1,12 @@
1
1
  import chalk from 'chalk';
2
- import cliWidth from 'cli-width';
3
- import { breakLines } from './utils.mjs';
4
- import { readline } from './hook-engine.mjs';
2
+ import { breakLines, readlineWidth } from './utils.mjs';
5
3
  import { useRef } from './use-ref.mjs';
6
4
  export function usePagination(output, { active, pageSize = 7, }) {
7
- const rl = readline();
8
5
  const state = useRef({
9
6
  pointer: 0,
10
7
  lastIndex: 0,
11
8
  });
12
- const width = cliWidth({ defaultWidth: 80, output: rl.output });
9
+ const width = readlineWidth();
13
10
  const lines = breakLines(output, width).split('\n');
14
11
  // Make sure there's enough lines to paginate
15
12
  if (lines.length <= pageSize) {
@@ -1,4 +1,6 @@
1
+ import cliWidth from 'cli-width';
1
2
  import wrapAnsi from 'wrap-ansi';
3
+ import { readline } from './hook-engine.mjs';
2
4
  /**
3
5
  * Force line returns at specific width. This function is ANSI code friendly and it'll
4
6
  * ignore invisible codes during width calculation.
@@ -6,9 +8,18 @@ import wrapAnsi from 'wrap-ansi';
6
8
  * @param {number} width
7
9
  * @return {string}
8
10
  */
9
- export const breakLines = (content, width) => content
10
- .split('\n')
11
- .flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true })
12
- .split('\n')
13
- .map((str) => str.trimEnd()))
14
- .join('\n');
11
+ export function breakLines(content, width) {
12
+ return content
13
+ .split('\n')
14
+ .flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true })
15
+ .split('\n')
16
+ .map((str) => str.trimEnd()))
17
+ .join('\n');
18
+ }
19
+ /**
20
+ * Returns the width of the active readline, or 80 as default value.
21
+ * @returns {number}
22
+ */
23
+ export function readlineWidth() {
24
+ return cliWidth({ defaultWidth: 80, output: readline().output });
25
+ }
@@ -5,4 +5,9 @@
5
5
  * @param {number} width
6
6
  * @return {string}
7
7
  */
8
- export declare const breakLines: (content: string, width: number) => string;
8
+ export declare function breakLines(content: string, width: number): string;
9
+ /**
10
+ * Returns the width of the active readline, or 80 as default value.
11
+ * @returns {number}
12
+ */
13
+ export declare function readlineWidth(): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "engines": {
5
5
  "node": ">=14.18.0"
6
6
  },
@@ -57,13 +57,13 @@
57
57
  "license": "MIT",
58
58
  "homepage": "https://github.com/SBoudrias/Inquirer.js/blob/master/packages/core/README.md",
59
59
  "dependencies": {
60
- "@inquirer/type": "^1.1.4",
60
+ "@inquirer/type": "^1.1.5",
61
61
  "@types/mute-stream": "^0.0.1",
62
- "@types/node": "^20.6.0",
62
+ "@types/node": "^20.6.5",
63
63
  "@types/wrap-ansi": "^3.0.0",
64
64
  "ansi-escapes": "^4.3.2",
65
65
  "chalk": "^4.1.2",
66
- "cli-spinners": "^2.9.0",
66
+ "cli-spinners": "^2.9.1",
67
67
  "cli-width": "^4.1.0",
68
68
  "figures": "^3.2.0",
69
69
  "mute-stream": "^1.0.0",
@@ -73,7 +73,7 @@
73
73
  "wrap-ansi": "^6.2.0"
74
74
  },
75
75
  "devDependencies": {
76
- "@inquirer/testing": "^2.1.6"
76
+ "@inquirer/testing": "^2.1.7"
77
77
  },
78
78
  "scripts": {
79
79
  "tsc": "yarn run tsc:esm && yarn run tsc:cjs",
@@ -95,5 +95,5 @@
95
95
  }
96
96
  }
97
97
  },
98
- "gitHead": "c2d1c5fdfd1029f78351fb04e06f1cfb29d55bb6"
98
+ "gitHead": "85784061d702778bc9dd48ca08f09ee9976b06ee"
99
99
  }