@optique/core 1.3.0-dev.2538 → 1.3.0-dev.2542

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/doc.cjs CHANGED
@@ -323,9 +323,9 @@ function formatDocPage(programName, page, options = {}) {
323
323
  }, options.theme))].map((token) => token.width)) : 0;
324
324
  const usageMin = page.usage != null && showUsage ? usageLabelWidth + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage, options.theme), programNameWidth + usageLabelWidth)) : 1;
325
325
  let sectionMin = 1;
326
- if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Examples:", "examples")));
327
- if (hasContent(page.author)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Author:", "author")));
328
- if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, require_displaywidth.getDisplayWidth(label("Bugs:", "bugs")));
326
+ if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, ...label("Examples:", "examples").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
327
+ if (hasContent(page.author)) sectionMin = Math.max(sectionMin, ...label("Author:", "author").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
328
+ if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, ...label("Bugs:", "bugs").split("\n").map((line) => require_displaywidth.getDisplayWidth(line)));
329
329
  const minWidth = Math.max(entryMin, usageMin, sectionMin);
330
330
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
331
331
  if (needsDescColumn && minDescWidth > 1) {
package/dist/doc.js CHANGED
@@ -323,9 +323,9 @@ function formatDocPage(programName, page, options = {}) {
323
323
  }, options.theme))].map((token) => token.width)) : 0;
324
324
  const usageMin = page.usage != null && showUsage ? usageLabelWidth + Math.max(programNameWidth, Math.min(maxVisibleAtomicWidth(page.usage, options.theme), programNameWidth + usageLabelWidth)) : 1;
325
325
  let sectionMin = 1;
326
- if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Examples:", "examples")));
327
- if (hasContent(page.author)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Author:", "author")));
328
- if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, getDisplayWidth(label("Bugs:", "bugs")));
326
+ if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, ...label("Examples:", "examples").split("\n").map((line) => getDisplayWidth(line)));
327
+ if (hasContent(page.author)) sectionMin = Math.max(sectionMin, ...label("Author:", "author").split("\n").map((line) => getDisplayWidth(line)));
328
+ if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, ...label("Bugs:", "bugs").split("\n").map((line) => getDisplayWidth(line)));
329
329
  const minWidth = Math.max(entryMin, usageMin, sectionMin);
330
330
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
331
331
  if (needsDescColumn && minDescWidth > 1) {
@@ -127,11 +127,19 @@ function sameStyle(a, b) {
127
127
  }
128
128
  function* fragmentTokens(fragment, scopes = [], inherited = {}) {
129
129
  if (fragment.type === "text") {
130
- yield {
131
- text: fragment.text,
132
- width: require_displaywidth.getDisplayWidth(fragment.text),
133
- scopes
134
- };
130
+ const lines = fragment.text.split("\n");
131
+ for (let i = 0; i < lines.length; i++) {
132
+ if (i > 0) yield {
133
+ text: "\n",
134
+ width: -1,
135
+ scopes
136
+ };
137
+ if (lines[i].length > 0 || lines.length === 1) yield {
138
+ text: lines[i],
139
+ width: require_displaywidth.getDisplayWidth(lines[i]),
140
+ scopes
141
+ };
142
+ }
135
143
  return;
136
144
  }
137
145
  let next = scopes;
@@ -193,7 +201,7 @@ function serializeTokens(tokens, colors = false, resetSuffix = "", ambient = {})
193
201
  const items = [...tokens];
194
202
  for (let i = 0; i < items.length; i++) {
195
203
  const token = items[i];
196
- if (colors && token.width === -1) {
204
+ if (colors && token.width === -1 && token.scopes.length === 0) {
197
205
  const next = items.slice(i + 1).find((t) => t.width !== -1)?.scopes ?? [];
198
206
  let common = 0;
199
207
  while (common < active.length && common < next.length && active[common] === next[common]) common++;
@@ -127,11 +127,19 @@ function sameStyle(a, b) {
127
127
  }
128
128
  function* fragmentTokens(fragment, scopes = [], inherited = {}) {
129
129
  if (fragment.type === "text") {
130
- yield {
131
- text: fragment.text,
132
- width: getDisplayWidth(fragment.text),
133
- scopes
134
- };
130
+ const lines = fragment.text.split("\n");
131
+ for (let i = 0; i < lines.length; i++) {
132
+ if (i > 0) yield {
133
+ text: "\n",
134
+ width: -1,
135
+ scopes
136
+ };
137
+ if (lines[i].length > 0 || lines.length === 1) yield {
138
+ text: lines[i],
139
+ width: getDisplayWidth(lines[i]),
140
+ scopes
141
+ };
142
+ }
135
143
  return;
136
144
  }
137
145
  let next = scopes;
@@ -193,7 +201,7 @@ function serializeTokens(tokens, colors = false, resetSuffix = "", ambient = {})
193
201
  const items = [...tokens];
194
202
  for (let i = 0; i < items.length; i++) {
195
203
  const token = items[i];
196
- if (colors && token.width === -1) {
204
+ if (colors && token.width === -1 && token.scopes.length === 0) {
197
205
  const next = items.slice(i + 1).find((t) => t.width !== -1)?.scopes ?? [];
198
206
  let common = 0;
199
207
  while (common < active.length && common < next.length && active[common] === next[common]) common++;
@@ -61,7 +61,8 @@ interface TerminalStyle {
61
61
  readonly underline?: boolean;
62
62
  }
63
63
  /**
64
- * Structured output. Each text leaf is an indivisible wrapping unit.
64
+ * Structured output. Newlines in text leaves force line breaks; each line
65
+ * within a leaf is an indivisible wrapping unit.
65
66
  * @since 1.3.0
66
67
  */
67
68
  type TerminalFragment = {
@@ -61,7 +61,8 @@ interface TerminalStyle {
61
61
  readonly underline?: boolean;
62
62
  }
63
63
  /**
64
- * Structured output. Each text leaf is an indivisible wrapping unit.
64
+ * Structured output. Newlines in text leaves force line breaks; each line
65
+ * within a leaf is an indivisible wrapping unit.
65
66
  * @since 1.3.0
66
67
  */
67
68
  type TerminalFragment = {
package/dist/usage.cjs CHANGED
@@ -490,6 +490,11 @@ function layoutUsageTokens(input, options, initialWidth = 0) {
490
490
  let lineWidth = initialWidth;
491
491
  const output = [];
492
492
  for (const token of input) {
493
+ if (token.width === -1) {
494
+ output.push(token);
495
+ lineWidth = 0;
496
+ continue;
497
+ }
493
498
  if (options.maxWidth != null && lineWidth > 0 && lineWidth + token.width > options.maxWidth) {
494
499
  const last = output.at(-1);
495
500
  if (last?.text.endsWith(" ") && (!options.colors || last.scopes.length === 0)) output[output.length - 1] = {
package/dist/usage.js CHANGED
@@ -490,6 +490,11 @@ function layoutUsageTokens(input, options, initialWidth = 0) {
490
490
  let lineWidth = initialWidth;
491
491
  const output = [];
492
492
  for (const token of input) {
493
+ if (token.width === -1) {
494
+ output.push(token);
495
+ lineWidth = 0;
496
+ continue;
497
+ }
493
498
  if (options.maxWidth != null && lineWidth > 0 && lineWidth + token.width > options.maxWidth) {
494
499
  const last = output.at(-1);
495
500
  if (last?.text.endsWith(" ") && (!options.colors || last.scopes.length === 0)) output[output.length - 1] = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.0-dev.2538",
3
+ "version": "1.3.0-dev.2542",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "sideEffects": false,
239
239
  "devDependencies": {
240
- "@optique/env": "1.3.0-dev.2538+8e1487d7",
240
+ "@optique/env": "1.3.0-dev.2542+1201b1a0",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",