@listr2/manager 3.0.0 → 3.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.
@@ -0,0 +1,134 @@
1
+ const require_string_width = require('./string-width-fWmCaoVR.cjs');
2
+
3
+ //#region ../../node_modules/.pnpm/wrap-ansi@9.0.0/node_modules/wrap-ansi/index.js
4
+ const ESCAPES = new Set(["\x1B", "›"]);
5
+ const END_CODE = 39;
6
+ const ANSI_ESCAPE_BELL = "\x07";
7
+ const ANSI_CSI = "[";
8
+ const ANSI_OSC = "]";
9
+ const ANSI_SGR_TERMINATOR = "m";
10
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
11
+ const wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
12
+ const wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
13
+ const wordLengths = (string) => string.split(" ").map((character) => require_string_width.stringWidth(character));
14
+ const wrapWord = (rows, word, columns) => {
15
+ const characters = [...word];
16
+ let isInsideEscape = false;
17
+ let isInsideLinkEscape = false;
18
+ let visible = require_string_width.stringWidth(require_string_width.stripAnsi(rows.at(-1)));
19
+ for (const [index, character] of characters.entries()) {
20
+ const characterLength = require_string_width.stringWidth(character);
21
+ if (visible + characterLength <= columns) rows[rows.length - 1] += character;
22
+ else {
23
+ rows.push(character);
24
+ visible = 0;
25
+ }
26
+ if (ESCAPES.has(character)) {
27
+ isInsideEscape = true;
28
+ const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
29
+ isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
30
+ }
31
+ if (isInsideEscape) {
32
+ if (isInsideLinkEscape) {
33
+ if (character === ANSI_ESCAPE_BELL) {
34
+ isInsideEscape = false;
35
+ isInsideLinkEscape = false;
36
+ }
37
+ } else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
38
+ continue;
39
+ }
40
+ visible += characterLength;
41
+ if (visible === columns && index < characters.length - 1) {
42
+ rows.push("");
43
+ visible = 0;
44
+ }
45
+ }
46
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) rows[rows.length - 2] += rows.pop();
47
+ };
48
+ const stringVisibleTrimSpacesRight = (string) => {
49
+ const words = string.split(" ");
50
+ let last = words.length;
51
+ while (last > 0) {
52
+ if (require_string_width.stringWidth(words[last - 1]) > 0) break;
53
+ last--;
54
+ }
55
+ if (last === words.length) return string;
56
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
57
+ };
58
+ const exec = (string, columns, options = {}) => {
59
+ if (options.trim !== false && string.trim() === "") return "";
60
+ let returnValue = "";
61
+ let escapeCode;
62
+ let escapeUrl;
63
+ const lengths = wordLengths(string);
64
+ let rows = [""];
65
+ for (const [index, word] of string.split(" ").entries()) {
66
+ if (options.trim !== false) rows[rows.length - 1] = rows.at(-1).trimStart();
67
+ let rowLength = require_string_width.stringWidth(rows.at(-1));
68
+ if (index !== 0) {
69
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
70
+ rows.push("");
71
+ rowLength = 0;
72
+ }
73
+ if (rowLength > 0 || options.trim === false) {
74
+ rows[rows.length - 1] += " ";
75
+ rowLength++;
76
+ }
77
+ }
78
+ if (options.hard && lengths[index] > columns) {
79
+ const remainingColumns = columns - rowLength;
80
+ const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
81
+ const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
82
+ if (breaksStartingNextLine < breaksStartingThisLine) rows.push("");
83
+ wrapWord(rows, word, columns);
84
+ continue;
85
+ }
86
+ if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
87
+ if (options.wordWrap === false && rowLength < columns) {
88
+ wrapWord(rows, word, columns);
89
+ continue;
90
+ }
91
+ rows.push("");
92
+ }
93
+ if (rowLength + lengths[index] > columns && options.wordWrap === false) {
94
+ wrapWord(rows, word, columns);
95
+ continue;
96
+ }
97
+ rows[rows.length - 1] += word;
98
+ }
99
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
100
+ const preString = rows.join("\n");
101
+ const pre = [...preString];
102
+ let preStringIndex = 0;
103
+ for (const [index, character] of pre.entries()) {
104
+ returnValue += character;
105
+ if (ESCAPES.has(character)) {
106
+ const { groups } = (/* @__PURE__ */ new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`)).exec(preString.slice(preStringIndex)) || { groups: {} };
107
+ if (groups.code !== void 0) {
108
+ const code$1 = Number.parseFloat(groups.code);
109
+ escapeCode = code$1 === END_CODE ? void 0 : code$1;
110
+ } else if (groups.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
111
+ }
112
+ const code = require_string_width.ansi_styles_default.codes.get(Number(escapeCode));
113
+ if (pre[index + 1] === "\n") {
114
+ if (escapeUrl) returnValue += wrapAnsiHyperlink("");
115
+ if (escapeCode && code) returnValue += wrapAnsiCode(code);
116
+ } else if (character === "\n") {
117
+ if (escapeCode && code) returnValue += wrapAnsiCode(escapeCode);
118
+ if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
119
+ }
120
+ preStringIndex += character.length;
121
+ }
122
+ return returnValue;
123
+ };
124
+ function wrapAnsi(string, columns, options) {
125
+ return String(string).normalize().replaceAll("\r\n", "\n").split("\n").map((line) => exec(line, columns, options)).join("\n");
126
+ }
127
+
128
+ //#endregion
129
+ Object.defineProperty(exports, 'wrapAnsi', {
130
+ enumerable: true,
131
+ get: function () {
132
+ return wrapAnsi;
133
+ }
134
+ });
@@ -0,0 +1,129 @@
1
+ import { ansi_styles_default, stringWidth, stripAnsi } from "./string-width-BnS-vObO.js";
2
+
3
+ //#region ../../node_modules/.pnpm/wrap-ansi@9.0.0/node_modules/wrap-ansi/index.js
4
+ const ESCAPES = new Set(["\x1B", "›"]);
5
+ const END_CODE = 39;
6
+ const ANSI_ESCAPE_BELL = "\x07";
7
+ const ANSI_CSI = "[";
8
+ const ANSI_OSC = "]";
9
+ const ANSI_SGR_TERMINATOR = "m";
10
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
11
+ const wrapAnsiCode = (code) => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
12
+ const wrapAnsiHyperlink = (url) => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
13
+ const wordLengths = (string) => string.split(" ").map((character) => stringWidth(character));
14
+ const wrapWord = (rows, word, columns) => {
15
+ const characters = [...word];
16
+ let isInsideEscape = false;
17
+ let isInsideLinkEscape = false;
18
+ let visible = stringWidth(stripAnsi(rows.at(-1)));
19
+ for (const [index, character] of characters.entries()) {
20
+ const characterLength = stringWidth(character);
21
+ if (visible + characterLength <= columns) rows[rows.length - 1] += character;
22
+ else {
23
+ rows.push(character);
24
+ visible = 0;
25
+ }
26
+ if (ESCAPES.has(character)) {
27
+ isInsideEscape = true;
28
+ const ansiEscapeLinkCandidate = characters.slice(index + 1, index + 1 + ANSI_ESCAPE_LINK.length).join("");
29
+ isInsideLinkEscape = ansiEscapeLinkCandidate === ANSI_ESCAPE_LINK;
30
+ }
31
+ if (isInsideEscape) {
32
+ if (isInsideLinkEscape) {
33
+ if (character === ANSI_ESCAPE_BELL) {
34
+ isInsideEscape = false;
35
+ isInsideLinkEscape = false;
36
+ }
37
+ } else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
38
+ continue;
39
+ }
40
+ visible += characterLength;
41
+ if (visible === columns && index < characters.length - 1) {
42
+ rows.push("");
43
+ visible = 0;
44
+ }
45
+ }
46
+ if (!visible && rows.at(-1).length > 0 && rows.length > 1) rows[rows.length - 2] += rows.pop();
47
+ };
48
+ const stringVisibleTrimSpacesRight = (string) => {
49
+ const words = string.split(" ");
50
+ let last = words.length;
51
+ while (last > 0) {
52
+ if (stringWidth(words[last - 1]) > 0) break;
53
+ last--;
54
+ }
55
+ if (last === words.length) return string;
56
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
57
+ };
58
+ const exec = (string, columns, options = {}) => {
59
+ if (options.trim !== false && string.trim() === "") return "";
60
+ let returnValue = "";
61
+ let escapeCode;
62
+ let escapeUrl;
63
+ const lengths = wordLengths(string);
64
+ let rows = [""];
65
+ for (const [index, word] of string.split(" ").entries()) {
66
+ if (options.trim !== false) rows[rows.length - 1] = rows.at(-1).trimStart();
67
+ let rowLength = stringWidth(rows.at(-1));
68
+ if (index !== 0) {
69
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
70
+ rows.push("");
71
+ rowLength = 0;
72
+ }
73
+ if (rowLength > 0 || options.trim === false) {
74
+ rows[rows.length - 1] += " ";
75
+ rowLength++;
76
+ }
77
+ }
78
+ if (options.hard && lengths[index] > columns) {
79
+ const remainingColumns = columns - rowLength;
80
+ const breaksStartingThisLine = 1 + Math.floor((lengths[index] - remainingColumns - 1) / columns);
81
+ const breaksStartingNextLine = Math.floor((lengths[index] - 1) / columns);
82
+ if (breaksStartingNextLine < breaksStartingThisLine) rows.push("");
83
+ wrapWord(rows, word, columns);
84
+ continue;
85
+ }
86
+ if (rowLength + lengths[index] > columns && rowLength > 0 && lengths[index] > 0) {
87
+ if (options.wordWrap === false && rowLength < columns) {
88
+ wrapWord(rows, word, columns);
89
+ continue;
90
+ }
91
+ rows.push("");
92
+ }
93
+ if (rowLength + lengths[index] > columns && options.wordWrap === false) {
94
+ wrapWord(rows, word, columns);
95
+ continue;
96
+ }
97
+ rows[rows.length - 1] += word;
98
+ }
99
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
100
+ const preString = rows.join("\n");
101
+ const pre = [...preString];
102
+ let preStringIndex = 0;
103
+ for (const [index, character] of pre.entries()) {
104
+ returnValue += character;
105
+ if (ESCAPES.has(character)) {
106
+ const { groups } = (/* @__PURE__ */ new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`)).exec(preString.slice(preStringIndex)) || { groups: {} };
107
+ if (groups.code !== void 0) {
108
+ const code$1 = Number.parseFloat(groups.code);
109
+ escapeCode = code$1 === END_CODE ? void 0 : code$1;
110
+ } else if (groups.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
111
+ }
112
+ const code = ansi_styles_default.codes.get(Number(escapeCode));
113
+ if (pre[index + 1] === "\n") {
114
+ if (escapeUrl) returnValue += wrapAnsiHyperlink("");
115
+ if (escapeCode && code) returnValue += wrapAnsiCode(code);
116
+ } else if (character === "\n") {
117
+ if (escapeCode && code) returnValue += wrapAnsiCode(escapeCode);
118
+ if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
119
+ }
120
+ preStringIndex += character.length;
121
+ }
122
+ return returnValue;
123
+ };
124
+ function wrapAnsi(string, columns, options) {
125
+ return String(string).normalize().replaceAll("\r\n", "\n").split("\n").map((line) => exec(line, columns, options)).join("\n");
126
+ }
127
+
128
+ //#endregion
129
+ export { wrapAnsi };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@listr2/manager",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Extension for Listr2 to easily create sane defaults for task lists.",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/listr2/listr2",
@@ -33,8 +33,8 @@
33
33
  "node": ">=20.0.0"
34
34
  },
35
35
  "scripts": {
36
- "build": "tsup-node",
37
- "dev:start": "tsup-node --watch",
36
+ "build": "tsdown",
37
+ "dev:start": "tsdown --watch",
38
38
  "format": "prettier --log-level warn --write src/ tests/ && pnpm run lint --fix",
39
39
  "lint": "eslint --flag v10_config_lookup_from_file src/ tests/",
40
40
  "test": "NO_COLOR=1 TS_NODE_PROJECT=tests/tsconfig.json NODE_OPTIONS='--no-warnings --experimental-specifier-resolution=node --experimental-vm-modules' jest --config tests/jest.config.ts",
@@ -71,7 +71,7 @@
71
71
  ],
72
72
  "dependencies": {},
73
73
  "devDependencies": {
74
- "listr2": "9.0.0"
74
+ "listr2": "9.0.1"
75
75
  },
76
76
  "peerDependencies": {}
77
77
  }