@optique/core 1.3.2 → 1.3.4

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,87 @@
1
+ //#region src/internal/command-doc-metadata.ts
2
+ function withOrigin(metadata, origin) {
3
+ const result = { ...metadata };
4
+ Object.defineProperty(result, "origin", {
5
+ value: origin,
6
+ enumerable: false
7
+ });
8
+ return result;
9
+ }
10
+ const commandDocMetadata = Symbol.for("@optique/core/commandDocMetadata");
11
+ const commandDocCarrier = Symbol.for("@optique/core/commandDocMetadataCarrier");
12
+ /**
13
+ * Reads effective page metadata, including custom collection-level fields.
14
+ * @param docs The child's documentation.
15
+ * @returns Its selected-command metadata, if any.
16
+ */
17
+ function getCommandDocMetadata(docs) {
18
+ const carrier = docs.fragments[commandDocCarrier];
19
+ if (carrier != null) {
20
+ const brief = docs.brief === carrier.brief ? carrier.metadata.brief : docs.brief;
21
+ const origin = carrier.metadata.origin ?? "entry";
22
+ const customPage = origin === "entry" && (docs.brief !== carrier.brief || docs.footer !== carrier.footer);
23
+ const description = origin === "entry" && !customPage || docs.description === carrier.description ? carrier.metadata.description : docs.description;
24
+ const footer = docs.footer === carrier.footer ? carrier.metadata.footer : docs.footer;
25
+ return withOrigin({
26
+ ...brief == null ? {} : { brief },
27
+ ...description == null ? {} : { description },
28
+ ...footer == null ? {} : { footer }
29
+ }, customPage ? "custom" : origin);
30
+ }
31
+ const metadata = docs[commandDocMetadata];
32
+ if (metadata != null) return metadata;
33
+ return docs.brief != null || docs.description != null || docs.footer != null ? withOrigin({
34
+ brief: docs.brief,
35
+ description: docs.description,
36
+ footer: docs.footer
37
+ }, "custom") : void 0;
38
+ }
39
+ /**
40
+ * Preserves selected-command metadata when rebuilding documentation fragments.
41
+ * @param docs The rebuilt documentation.
42
+ * @param metadata The selected-command metadata to preserve.
43
+ * @returns Documentation with the internal metadata attached.
44
+ */
45
+ function withCommandDocMetadata(docs, metadata) {
46
+ if (metadata == null) return docs;
47
+ metadata = withOrigin(metadata, metadata.origin ?? "entry");
48
+ const fragments = [...docs.fragments];
49
+ Object.defineProperty(fragments, commandDocCarrier, { value: {
50
+ metadata,
51
+ brief: docs.brief,
52
+ description: docs.description,
53
+ footer: docs.footer
54
+ } });
55
+ const result = {
56
+ ...docs,
57
+ fragments
58
+ };
59
+ Object.defineProperty(result, commandDocMetadata, { value: metadata });
60
+ return result;
61
+ }
62
+ /**
63
+ * Collects selected-command metadata in documentation traversal order.
64
+ * @param current Metadata from earlier children.
65
+ * @param docs The next child's documentation.
66
+ * @param includeCustom Whether to retain custom page fields inside merge().
67
+ * @returns The first defined value from children with the same origin.
68
+ */
69
+ function collectCommandDocMetadata(current, docs, includeCustom = false) {
70
+ const next = getCommandDocMetadata(docs);
71
+ if (next == null) return current;
72
+ const origin = next.origin ?? "entry";
73
+ if (origin === "entry" || origin === "custom" && !includeCustom) return current ?? withOrigin({}, "entry");
74
+ if (current?.origin === "command" && origin !== "command") return current;
75
+ if (current?.origin !== origin) current = void 0;
76
+ const brief = current?.brief ?? next.brief;
77
+ const description = current?.description ?? next.description;
78
+ const footer = current?.footer ?? next.footer;
79
+ return withOrigin({
80
+ ...brief == null ? {} : { brief },
81
+ ...description == null ? {} : { description },
82
+ ...footer == null ? {} : { footer }
83
+ }, origin);
84
+ }
85
+
86
+ //#endregion
87
+ export { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata };
package/dist/message.cjs CHANGED
@@ -347,7 +347,8 @@ function renderMessage(msg, options, theme, ambient) {
347
347
  yield {
348
348
  text: match[0],
349
349
  width: require_displaywidth.getDisplayWidth(match[0]),
350
- scopes: []
350
+ scopes: [],
351
+ trimOnWrap: true
351
352
  };
352
353
  }
353
354
  }
@@ -356,7 +357,8 @@ function renderMessage(msg, options, theme, ambient) {
356
357
  if (normalizedText.trim() === "" && normalizedText.length > 0) yield {
357
358
  text: " ",
358
359
  width: 1,
359
- scopes: []
360
+ scopes: [],
361
+ trimOnWrap: true
360
362
  };
361
363
  else {
362
364
  wordPattern.lastIndex = 0;
@@ -366,7 +368,8 @@ function renderMessage(msg, options, theme, ambient) {
366
368
  yield {
367
369
  text: match[0],
368
370
  width: require_displaywidth.getDisplayWidth(match[0]),
369
- scopes: []
371
+ scopes: [],
372
+ trimOnWrap: true
370
373
  };
371
374
  }
372
375
  }
@@ -383,22 +386,46 @@ function renderMessage(msg, options, theme, ambient) {
383
386
  }
384
387
  const tokens = [];
385
388
  let totalWidth = initialWidth;
386
- for (const token of stream()) {
389
+ let pendingWrap = false;
390
+ let atWrappedLineStart = false;
391
+ for (let token of stream()) {
387
392
  if (token.width === -1) {
388
393
  tokens.push(token);
389
394
  totalWidth = 0;
395
+ pendingWrap = false;
396
+ atWrappedLineStart = false;
397
+ continue;
398
+ }
399
+ const wraps = pendingWrap || options.maxWidth != null && totalWidth > 0 && totalWidth + token.width > options.maxWidth;
400
+ if ((wraps || atWrappedLineStart) && token.trimOnWrap) {
401
+ const text$1 = token.text.trimStart();
402
+ token = {
403
+ ...token,
404
+ text: text$1,
405
+ width: token.width - require_displaywidth.getDisplayWidth(token.text.slice(0, token.text.length - text$1.length))
406
+ };
407
+ if (text$1 === "") {
408
+ if (wraps) pendingWrap = true;
409
+ continue;
410
+ }
411
+ }
412
+ if (pendingWrap && require_displaywidth.stripAnsi(token.text) === "") {
413
+ tokens.push(token);
390
414
  continue;
391
415
  }
392
- if (options.maxWidth != null && totalWidth > 0 && totalWidth + token.width > options.maxWidth) {
416
+ if (wraps) {
393
417
  tokens.push({
394
418
  text: "\n",
395
419
  width: -1,
396
420
  scopes: []
397
421
  });
398
422
  totalWidth = 0;
423
+ pendingWrap = false;
424
+ atWrappedLineStart = true;
399
425
  }
400
426
  tokens.push(token);
401
427
  totalWidth += token.width;
428
+ if (token.width > 0) atWrappedLineStart = false;
402
429
  }
403
430
  return require_terminal_internal.serializeTokens(tokens, useColors, ambient == null ? resetSuffix : "", ambient);
404
431
  }
package/dist/message.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getDisplayWidth } from "./displaywidth.js";
1
+ import { getDisplayWidth, stripAnsi } from "./displaywidth.js";
2
2
  import { formatTerminalTerm, fragmentTokens, serializeTokens } from "./terminal-internal.js";
3
3
  import { messageRenderers } from "./message-registry.js";
4
4
 
@@ -347,7 +347,8 @@ function renderMessage(msg, options, theme, ambient) {
347
347
  yield {
348
348
  text: match[0],
349
349
  width: getDisplayWidth(match[0]),
350
- scopes: []
350
+ scopes: [],
351
+ trimOnWrap: true
351
352
  };
352
353
  }
353
354
  }
@@ -356,7 +357,8 @@ function renderMessage(msg, options, theme, ambient) {
356
357
  if (normalizedText.trim() === "" && normalizedText.length > 0) yield {
357
358
  text: " ",
358
359
  width: 1,
359
- scopes: []
360
+ scopes: [],
361
+ trimOnWrap: true
360
362
  };
361
363
  else {
362
364
  wordPattern.lastIndex = 0;
@@ -366,7 +368,8 @@ function renderMessage(msg, options, theme, ambient) {
366
368
  yield {
367
369
  text: match[0],
368
370
  width: getDisplayWidth(match[0]),
369
- scopes: []
371
+ scopes: [],
372
+ trimOnWrap: true
370
373
  };
371
374
  }
372
375
  }
@@ -383,22 +386,46 @@ function renderMessage(msg, options, theme, ambient) {
383
386
  }
384
387
  const tokens = [];
385
388
  let totalWidth = initialWidth;
386
- for (const token of stream()) {
389
+ let pendingWrap = false;
390
+ let atWrappedLineStart = false;
391
+ for (let token of stream()) {
387
392
  if (token.width === -1) {
388
393
  tokens.push(token);
389
394
  totalWidth = 0;
395
+ pendingWrap = false;
396
+ atWrappedLineStart = false;
397
+ continue;
398
+ }
399
+ const wraps = pendingWrap || options.maxWidth != null && totalWidth > 0 && totalWidth + token.width > options.maxWidth;
400
+ if ((wraps || atWrappedLineStart) && token.trimOnWrap) {
401
+ const text$1 = token.text.trimStart();
402
+ token = {
403
+ ...token,
404
+ text: text$1,
405
+ width: token.width - getDisplayWidth(token.text.slice(0, token.text.length - text$1.length))
406
+ };
407
+ if (text$1 === "") {
408
+ if (wraps) pendingWrap = true;
409
+ continue;
410
+ }
411
+ }
412
+ if (pendingWrap && stripAnsi(token.text) === "") {
413
+ tokens.push(token);
390
414
  continue;
391
415
  }
392
- if (options.maxWidth != null && totalWidth > 0 && totalWidth + token.width > options.maxWidth) {
416
+ if (wraps) {
393
417
  tokens.push({
394
418
  text: "\n",
395
419
  width: -1,
396
420
  scopes: []
397
421
  });
398
422
  totalWidth = 0;
423
+ pendingWrap = false;
424
+ atWrappedLineStart = true;
399
425
  }
400
426
  tokens.push(token);
401
427
  totalWidth += token.width;
428
+ if (token.width > 0) atWrappedLineStart = false;
402
429
  }
403
430
  return serializeTokens(tokens, useColors, ambient == null ? resetSuffix : "", ambient);
404
431
  }
@@ -4,6 +4,7 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
4
4
  const require_dependency_runtime = require('./dependency-runtime.cjs');
5
5
  const require_internal_parser = require('./internal/parser.cjs');
6
6
  const require_annotation_state = require('./annotation-state.cjs');
7
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
7
8
  const require_passthrough = require('./internal/passthrough.cjs');
8
9
  const require_execution_context = require('./execution-context.cjs');
9
10
  const require_phase2_seed = require('./phase2-seed.cjs');
@@ -653,10 +654,10 @@ function withDefault(parser, defaultValue, options) {
653
654
  };
654
655
  return fragment;
655
656
  });
656
- return {
657
+ return require_command_doc_metadata.withCommandDocMetadata({
657
658
  ...fragments,
658
659
  fragments: modifiedFragments
659
- };
660
+ }, require_command_doc_metadata.getCommandDocMetadata(fragments));
660
661
  }
661
662
  return fragments;
662
663
  }
package/dist/modifiers.js CHANGED
@@ -4,6 +4,7 @@ import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } fro
4
4
  import { defineForwardedEffectfulSchedulingNodes } from "./dependency-runtime.js";
5
5
  import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
6
6
  import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
7
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
7
8
  import { defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, getKnownCompletion, getOptionMatch, getPassThroughPriority } from "./internal/passthrough.js";
8
9
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
9
10
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
@@ -653,10 +654,10 @@ function withDefault(parser, defaultValue, options) {
653
654
  };
654
655
  return fragment;
655
656
  });
656
- return {
657
+ return withCommandDocMetadata({
657
658
  ...fragments,
658
659
  fragments: modifiedFragments
659
- };
660
+ }, getCommandDocMetadata(fragments));
660
661
  }
661
662
  return fragments;
662
663
  }
@@ -6,6 +6,7 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
6
6
  const require_internal_dependency = require('./internal/dependency.cjs');
7
7
  const require_dependency_runtime = require('./dependency-runtime.cjs');
8
8
  const require_annotation_state = require('./annotation-state.cjs');
9
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
9
10
  const require_passthrough = require('./internal/passthrough.cjs');
10
11
  const require_command_alias = require('./internal/command-alias.cjs');
11
12
  const require_execution_context = require('./execution-context.cjs');
@@ -646,10 +647,10 @@ function option(...args) {
646
647
  return suggestOptionSync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), options.description, context, prefix);
647
648
  },
648
649
  getDocFragments(_state, defaultValue) {
649
- if (require_usage.isDocHidden(options.hidden)) return {
650
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
650
651
  fragments: [],
651
652
  description: options.description
652
- };
653
+ }, {});
653
654
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
654
655
  fallback: "",
655
656
  type: "unit"
@@ -665,10 +666,10 @@ function option(...args) {
665
666
  default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0,
666
667
  choices: choicesMessage
667
668
  }];
668
- return {
669
+ return require_command_doc_metadata.withCommandDocMetadata({
669
670
  fragments,
670
671
  description: options.description
671
- };
672
+ }, {});
672
673
  },
673
674
  [Symbol.for("Deno.customInspect")]() {
674
675
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -937,10 +938,10 @@ function flag(...args) {
937
938
  return suggestions;
938
939
  },
939
940
  getDocFragments(_state, _defaultValue) {
940
- if (require_usage.isDocHidden(options.hidden)) return {
941
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
941
942
  fragments: [],
942
943
  description: options.description
943
- };
944
+ }, {});
944
945
  const fragments = [{
945
946
  type: "entry",
946
947
  term: {
@@ -949,10 +950,10 @@ function flag(...args) {
949
950
  },
950
951
  description: options.description
951
952
  }];
952
- return {
953
+ return require_command_doc_metadata.withCommandDocMetadata({
953
954
  fragments,
954
955
  description: options.description
955
- };
956
+ }, {});
956
957
  },
957
958
  [Symbol.for("Deno.customInspect")]() {
958
959
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1309,10 +1310,10 @@ function argument(valueParser, options = {}) {
1309
1310
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1310
1311
  },
1311
1312
  getDocFragments(_state, defaultValue) {
1312
- if (require_usage.isDocHidden(options.hidden)) return {
1313
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1313
1314
  fragments: [],
1314
1315
  description: options.description
1315
- };
1316
+ }, {});
1316
1317
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1317
1318
  fallback: "",
1318
1319
  type: "unit"
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`,
1325
1326
  choices: choicesMessage
1326
1327
  }];
1327
- return {
1328
+ return require_command_doc_metadata.withCommandDocMetadata({
1328
1329
  fragments,
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  },
1332
1333
  [Symbol.for("Deno.customInspect")]() {
1333
1334
  return `argument()`;
@@ -1678,11 +1679,11 @@ function command(name, parser, options = {}) {
1678
1679
  getDocFragments(state, defaultValue) {
1679
1680
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1680
1681
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1681
- if (require_usage.isDocHidden(options.hidden)) return {
1682
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1682
1683
  fragments: [],
1683
1684
  description: options.description
1684
- };
1685
- return {
1685
+ }, {});
1686
+ return require_command_doc_metadata.withCommandDocMetadata({
1686
1687
  description: options.description,
1687
1688
  fragments: [{
1688
1689
  type: "entry",
@@ -1692,7 +1693,7 @@ function command(name, parser, options = {}) {
1692
1693
  },
1693
1694
  description: options.brief ?? options.description
1694
1695
  }]
1695
- };
1696
+ }, {});
1696
1697
  }
1697
1698
  const innerState = commandState[0] === "parsing" ? {
1698
1699
  kind: "available",
@@ -1702,12 +1703,18 @@ function command(name, parser, options = {}) {
1702
1703
  state: getCommandChildState(state.state, parser.initialState, parser)
1703
1704
  };
1704
1705
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1705
- return {
1706
+ const innerMetadata = require_command_doc_metadata.getCommandDocMetadata(innerFragments) ?? innerFragments;
1707
+ return require_command_doc_metadata.withCommandDocMetadata({
1706
1708
  ...innerFragments,
1707
1709
  brief: innerFragments.brief ?? options.brief,
1708
1710
  description: innerFragments.description ?? options.description,
1709
1711
  footer: innerFragments.footer ?? options.footer
1710
- };
1712
+ }, {
1713
+ origin: "command",
1714
+ brief: innerMetadata?.brief ?? options.brief,
1715
+ description: innerMetadata?.description ?? options.description,
1716
+ footer: innerMetadata?.footer ?? options.footer
1717
+ });
1711
1718
  },
1712
1719
  [Symbol.for("Deno.customInspect")]() {
1713
1720
  return `command(${JSON.stringify(name)})`;
@@ -1932,18 +1939,18 @@ function passThrough(options = {}) {
1932
1939
  return [];
1933
1940
  },
1934
1941
  getDocFragments(_state, _defaultValue) {
1935
- if (require_usage.isDocHidden(options.hidden)) return {
1942
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1936
1943
  fragments: [],
1937
1944
  description: options.description
1938
- };
1939
- return {
1945
+ }, {});
1946
+ return require_command_doc_metadata.withCommandDocMetadata({
1940
1947
  fragments: [{
1941
1948
  type: "entry",
1942
1949
  term: { type: "passthrough" },
1943
1950
  description: options.description
1944
1951
  }],
1945
1952
  description: options.description
1946
- };
1953
+ }, {});
1947
1954
  },
1948
1955
  [Symbol.for("Deno.customInspect")]() {
1949
1956
  return `passThrough(${format})`;
@@ -6,6 +6,7 @@ import { dispatchByMode, dispatchIterableByMode, wrapForMode } from "./internal/
6
6
  import { getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDerivedValueParser, suggestWithDependency } from "./internal/dependency.js";
7
7
  import { effectfulSchedulingNodesKey, exclusiveSourceScopeKey, includeSourceFailureChain, recordDerivedRawInput, replayDerivedParser, replayDerivedParserAsync, sourceCollectionExpansionKey } from "./dependency-runtime.js";
8
8
  import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedInitialState, normalizeInjectedAnnotationState } from "./annotation-state.js";
9
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
9
10
  import { defineKnownCompletion, defineOptionMatch, definePassThroughPriority, getOptionMatch, getPassThroughFailure, getPassThroughPriority } from "./internal/passthrough.js";
10
11
  import { hiddenCommandAliasesKey } from "./internal/command-alias.js";
11
12
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
@@ -646,10 +647,10 @@ function option(...args) {
646
647
  return suggestOptionSync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), options.description, context, prefix);
647
648
  },
648
649
  getDocFragments(_state, defaultValue) {
649
- if (isDocHidden(options.hidden)) return {
650
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
650
651
  fragments: [],
651
652
  description: options.description
652
- };
653
+ }, {});
653
654
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
654
655
  fallback: "",
655
656
  type: "unit"
@@ -665,10 +666,10 @@ function option(...args) {
665
666
  default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0,
666
667
  choices: choicesMessage
667
668
  }];
668
- return {
669
+ return withCommandDocMetadata({
669
670
  fragments,
670
671
  description: options.description
671
- };
672
+ }, {});
672
673
  },
673
674
  [Symbol.for("Deno.customInspect")]() {
674
675
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -937,10 +938,10 @@ function flag(...args) {
937
938
  return suggestions;
938
939
  },
939
940
  getDocFragments(_state, _defaultValue) {
940
- if (isDocHidden(options.hidden)) return {
941
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
941
942
  fragments: [],
942
943
  description: options.description
943
- };
944
+ }, {});
944
945
  const fragments = [{
945
946
  type: "entry",
946
947
  term: {
@@ -949,10 +950,10 @@ function flag(...args) {
949
950
  },
950
951
  description: options.description
951
952
  }];
952
- return {
953
+ return withCommandDocMetadata({
953
954
  fragments,
954
955
  description: options.description
955
- };
956
+ }, {});
956
957
  },
957
958
  [Symbol.for("Deno.customInspect")]() {
958
959
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1309,10 +1310,10 @@ function argument(valueParser, options = {}) {
1309
1310
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1310
1311
  },
1311
1312
  getDocFragments(_state, defaultValue) {
1312
- if (isDocHidden(options.hidden)) return {
1313
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1313
1314
  fragments: [],
1314
1315
  description: options.description
1315
- };
1316
+ }, {});
1316
1317
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1317
1318
  fallback: "",
1318
1319
  type: "unit"
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`,
1325
1326
  choices: choicesMessage
1326
1327
  }];
1327
- return {
1328
+ return withCommandDocMetadata({
1328
1329
  fragments,
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  },
1332
1333
  [Symbol.for("Deno.customInspect")]() {
1333
1334
  return `argument()`;
@@ -1678,11 +1679,11 @@ function command(name, parser, options = {}) {
1678
1679
  getDocFragments(state, defaultValue) {
1679
1680
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1680
1681
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1681
- if (isDocHidden(options.hidden)) return {
1682
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1682
1683
  fragments: [],
1683
1684
  description: options.description
1684
- };
1685
- return {
1685
+ }, {});
1686
+ return withCommandDocMetadata({
1686
1687
  description: options.description,
1687
1688
  fragments: [{
1688
1689
  type: "entry",
@@ -1692,7 +1693,7 @@ function command(name, parser, options = {}) {
1692
1693
  },
1693
1694
  description: options.brief ?? options.description
1694
1695
  }]
1695
- };
1696
+ }, {});
1696
1697
  }
1697
1698
  const innerState = commandState[0] === "parsing" ? {
1698
1699
  kind: "available",
@@ -1702,12 +1703,18 @@ function command(name, parser, options = {}) {
1702
1703
  state: getCommandChildState(state.state, parser.initialState, parser)
1703
1704
  };
1704
1705
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1705
- return {
1706
+ const innerMetadata = getCommandDocMetadata(innerFragments) ?? innerFragments;
1707
+ return withCommandDocMetadata({
1706
1708
  ...innerFragments,
1707
1709
  brief: innerFragments.brief ?? options.brief,
1708
1710
  description: innerFragments.description ?? options.description,
1709
1711
  footer: innerFragments.footer ?? options.footer
1710
- };
1712
+ }, {
1713
+ origin: "command",
1714
+ brief: innerMetadata?.brief ?? options.brief,
1715
+ description: innerMetadata?.description ?? options.description,
1716
+ footer: innerMetadata?.footer ?? options.footer
1717
+ });
1711
1718
  },
1712
1719
  [Symbol.for("Deno.customInspect")]() {
1713
1720
  return `command(${JSON.stringify(name)})`;
@@ -1932,18 +1939,18 @@ function passThrough(options = {}) {
1932
1939
  return [];
1933
1940
  },
1934
1941
  getDocFragments(_state, _defaultValue) {
1935
- if (isDocHidden(options.hidden)) return {
1942
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1936
1943
  fragments: [],
1937
1944
  description: options.description
1938
- };
1939
- return {
1945
+ }, {});
1946
+ return withCommandDocMetadata({
1940
1947
  fragments: [{
1941
1948
  type: "entry",
1942
1949
  term: { type: "passthrough" },
1943
1950
  description: options.description
1944
1951
  }],
1945
1952
  description: options.description
1946
- };
1953
+ }, {});
1947
1954
  },
1948
1955
  [Symbol.for("Deno.customInspect")]() {
1949
1956
  return `passThrough(${format})`;
@@ -1,4 +1,5 @@
1
1
  const require_displaywidth = require('./displaywidth.cjs');
2
+ const require_terminal_separators = require('./terminal-separators.cjs');
2
3
  const require_terminal = require('./terminal.cjs');
3
4
 
4
5
  //#region src/terminal-internal.ts
@@ -151,6 +152,7 @@ function sameStyle(a, b) {
151
152
  }
152
153
  function* fragmentTokens(fragment, scopes = [], inherited = {}) {
153
154
  if (fragment.type === "text") {
155
+ const marks = require_terminal_separators.wrapTrimmableFragments.has(fragment) ? { trimOnWrap: true } : {};
154
156
  const lines = fragment.text.split("\n");
155
157
  for (let i = 0; i < lines.length; i++) {
156
158
  if (i > 0) yield {
@@ -161,7 +163,8 @@ function* fragmentTokens(fragment, scopes = [], inherited = {}) {
161
163
  if (lines[i].length > 0 || lines.length === 1) yield {
162
164
  text: lines[i],
163
165
  width: require_displaywidth.getDisplayWidth(lines[i]),
164
- scopes
166
+ scopes,
167
+ ...marks
165
168
  };
166
169
  }
167
170
  return;
@@ -16,6 +16,11 @@ interface TerminalToken {
16
16
  readonly programBoundary?: boolean;
17
17
  /** Enables only the legacy default formatter whitespace behavior. */
18
18
  readonly legacyWhitespace?: boolean;
19
+ /**
20
+ * Leading whitespace only separates the token from preceding content, so
21
+ * message wrapping may drop it when the token starts a wrapped line.
22
+ */
23
+ readonly trimOnWrap?: boolean;
19
24
  }
20
25
  declare function terminalText(text: string): TerminalFragment;
21
26
  declare function formatTerminalTerm(term: TerminalTerm, theme?: TerminalTheme, quotes?: boolean, usage?: TerminalFormatContext["usage"]): TerminalFragment;
@@ -16,6 +16,11 @@ interface TerminalToken {
16
16
  readonly programBoundary?: boolean;
17
17
  /** Enables only the legacy default formatter whitespace behavior. */
18
18
  readonly legacyWhitespace?: boolean;
19
+ /**
20
+ * Leading whitespace only separates the token from preceding content, so
21
+ * message wrapping may drop it when the token starts a wrapped line.
22
+ */
23
+ readonly trimOnWrap?: boolean;
19
24
  }
20
25
  declare function terminalText(text: string): TerminalFragment;
21
26
  declare function formatTerminalTerm(term: TerminalTerm, theme?: TerminalTheme, quotes?: boolean, usage?: TerminalFormatContext["usage"]): TerminalFragment;
@@ -1,4 +1,5 @@
1
1
  import { getDisplayWidth } from "./displaywidth.js";
2
+ import { wrapTrimmableFragments } from "./terminal-separators.js";
2
3
  import { defaultTerminalTheme } from "./terminal.js";
3
4
 
4
5
  //#region src/terminal-internal.ts
@@ -151,6 +152,7 @@ function sameStyle(a, b) {
151
152
  }
152
153
  function* fragmentTokens(fragment, scopes = [], inherited = {}) {
153
154
  if (fragment.type === "text") {
155
+ const marks = wrapTrimmableFragments.has(fragment) ? { trimOnWrap: true } : {};
154
156
  const lines = fragment.text.split("\n");
155
157
  for (let i = 0; i < lines.length; i++) {
156
158
  if (i > 0) yield {
@@ -161,7 +163,8 @@ function* fragmentTokens(fragment, scopes = [], inherited = {}) {
161
163
  if (lines[i].length > 0 || lines.length === 1) yield {
162
164
  text: lines[i],
163
165
  width: getDisplayWidth(lines[i]),
164
- scopes
166
+ scopes,
167
+ ...marks
165
168
  };
166
169
  }
167
170
  return;