@optique/core 1.1.9 → 1.1.11

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.
@@ -8,6 +8,7 @@ const require_internal_dependency = require('./internal/dependency.cjs');
8
8
  const require_dependency_runtime = require('./dependency-runtime.cjs');
9
9
  const require_internal_parser = require('./internal/parser.cjs');
10
10
  const require_annotation_state = require('./annotation-state.cjs');
11
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
11
12
  const require_passthrough = require('./internal/passthrough.cjs');
12
13
  const require_command_alias = require('./internal/command-alias.cjs');
13
14
  const require_execution_context = require('./execution-context.cjs');
@@ -1350,6 +1351,7 @@ function or(...args) {
1350
1351
  },
1351
1352
  suggest: createExclusiveSuggest(parsers, combinedMode),
1352
1353
  getDocFragments(state, _defaultValue) {
1354
+ let commandMetadata;
1353
1355
  let brief;
1354
1356
  let description;
1355
1357
  let footer;
@@ -1362,18 +1364,19 @@ function or(...args) {
1362
1364
  state: parserResult.next.state
1363
1365
  } : { kind: "unavailable" };
1364
1366
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1367
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
1365
1368
  brief = docFragments.brief;
1366
1369
  description = docFragments.description;
1367
1370
  footer = docFragments.footer;
1368
1371
  fragments = docFragments.fragments;
1369
1372
  }
1370
1373
  if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
1371
- return {
1374
+ return require_command_doc_metadata.withCommandDocMetadata({
1372
1375
  brief,
1373
1376
  description,
1374
1377
  footer,
1375
1378
  fragments
1376
- };
1379
+ }, commandMetadata);
1377
1380
  }
1378
1381
  };
1379
1382
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1581,6 +1584,7 @@ function createLongestMatch(...args) {
1581
1584
  },
1582
1585
  suggest: createExclusiveSuggest(parsers, combinedMode),
1583
1586
  getDocFragments(state, _defaultValue) {
1587
+ let commandMetadata;
1584
1588
  let brief;
1585
1589
  let description;
1586
1590
  let footer;
@@ -1596,6 +1600,7 @@ function createLongestMatch(...args) {
1596
1600
  kind: "available",
1597
1601
  state: result.next.state
1598
1602
  });
1603
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
1599
1604
  brief = docResult.brief;
1600
1605
  description = docResult.description;
1601
1606
  footer = docResult.footer;
@@ -1606,12 +1611,12 @@ function createLongestMatch(...args) {
1606
1611
  shouldDeduplicate = true;
1607
1612
  }
1608
1613
  }
1609
- return {
1614
+ return require_command_doc_metadata.withCommandDocMetadata({
1610
1615
  brief,
1611
1616
  description,
1612
1617
  fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
1613
1618
  footer
1614
- };
1619
+ }, commandMetadata);
1615
1620
  }
1616
1621
  };
1617
1622
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2583,12 +2588,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2583
2588
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2584
2589
  },
2585
2590
  getDocFragments(state, defaultValue) {
2591
+ let commandMetadata;
2586
2592
  const fragments = parserPairs.flatMap(([field, p]) => {
2587
2593
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2588
2594
  kind: "available",
2589
2595
  state: state.state[field]
2590
2596
  };
2591
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2597
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2598
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
2599
+ return docs.fragments;
2592
2600
  });
2593
2601
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2594
2602
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2603,10 +2611,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2603
2611
  entries
2604
2612
  };
2605
2613
  sections.push(section);
2606
- return { fragments: sections.map((s) => ({
2607
- ...s,
2608
- type: "section"
2609
- })) };
2614
+ return require_command_doc_metadata.withCommandDocMetadata({
2615
+ ...commandMetadata,
2616
+ fragments: sections.map((s) => ({
2617
+ ...s,
2618
+ type: "section"
2619
+ }))
2620
+ }, commandMetadata);
2610
2621
  }
2611
2622
  };
2612
2623
  const fieldNormalizers = [];
@@ -3599,12 +3610,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3599
3610
  return require_mode_dispatch.dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3600
3611
  },
3601
3612
  getDocFragments(state, defaultValue) {
3613
+ let commandMetadata;
3602
3614
  const fragments = syncParsers.flatMap((p, i) => {
3603
3615
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3604
3616
  kind: "available",
3605
3617
  state: state.state[i]
3606
3618
  };
3607
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3619
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3620
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
3621
+ return docs.fragments;
3608
3622
  });
3609
3623
  const entries = fragments.filter((d) => d.type === "entry");
3610
3624
  const sections = [];
@@ -3618,10 +3632,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3618
3632
  entries
3619
3633
  };
3620
3634
  sections.push(section);
3621
- return { fragments: sections.map((s) => ({
3622
- ...s,
3623
- type: "section"
3624
- })) };
3635
+ return require_command_doc_metadata.withCommandDocMetadata({
3636
+ ...commandMetadata,
3637
+ fragments: sections.map((s) => ({
3638
+ ...s,
3639
+ type: "section"
3640
+ }))
3641
+ }, commandMetadata);
3625
3642
  },
3626
3643
  [Symbol.for("Deno.customInspect")]() {
3627
3644
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4847,6 +4864,7 @@ function merge(...args) {
4847
4864
  }();
4848
4865
  },
4849
4866
  getDocFragments(state, _defaultValue) {
4867
+ let commandMetadata;
4850
4868
  let brief;
4851
4869
  let description;
4852
4870
  let footer;
@@ -4864,6 +4882,7 @@ function merge(...args) {
4864
4882
  state: state.state
4865
4883
  };
4866
4884
  const docFragments = p.getDocFragments(parserState, void 0);
4885
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
4867
4886
  brief ??= docFragments.brief;
4868
4887
  description ??= docFragments.description;
4869
4888
  footer ??= docFragments.footer;
@@ -4883,7 +4902,7 @@ function merge(...args) {
4883
4902
  entries
4884
4903
  };
4885
4904
  sections.push(labeledSection);
4886
- return {
4905
+ return require_command_doc_metadata.withCommandDocMetadata({
4887
4906
  brief,
4888
4907
  description,
4889
4908
  footer,
@@ -4891,9 +4910,9 @@ function merge(...args) {
4891
4910
  ...s,
4892
4911
  type: "section"
4893
4912
  }))
4894
- };
4913
+ }, commandMetadata);
4895
4914
  }
4896
- return {
4915
+ return require_command_doc_metadata.withCommandDocMetadata({
4897
4916
  brief,
4898
4917
  description,
4899
4918
  footer,
@@ -4904,7 +4923,7 @@ function merge(...args) {
4904
4923
  type: "section",
4905
4924
  entries
4906
4925
  }]
4907
- };
4926
+ }, commandMetadata);
4908
4927
  }
4909
4928
  };
4910
4929
  require_internal_parser.defineParseLanes(mergeParser, mergeParseLanes);
@@ -5520,12 +5539,15 @@ function concat(...parsers) {
5520
5539
  }();
5521
5540
  },
5522
5541
  getDocFragments(state, _defaultValue) {
5542
+ let commandMetadata;
5523
5543
  const fragments = syncParsers.flatMap((p, index) => {
5524
5544
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5525
5545
  kind: "available",
5526
5546
  state: state.state[index]
5527
5547
  };
5528
- return p.getDocFragments(indexState, void 0).fragments;
5548
+ const docs = p.getDocFragments(indexState, void 0);
5549
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
5550
+ return docs.fragments;
5529
5551
  });
5530
5552
  const entries = fragments.filter((f) => f.type === "entry");
5531
5553
  const sections = [];
@@ -5542,7 +5564,10 @@ function concat(...parsers) {
5542
5564
  type: "section",
5543
5565
  entries
5544
5566
  });
5545
- return { fragments: result };
5567
+ return require_command_doc_metadata.withCommandDocMetadata({
5568
+ ...commandMetadata,
5569
+ fragments: result
5570
+ }, commandMetadata);
5546
5571
  }
5547
5572
  };
5548
5573
  require_internal_parser.defineInheritedAnnotationParser(concatParser);
@@ -5578,7 +5603,8 @@ function group(label, parser, options = {}) {
5578
5603
  return parser.suggest(context, prefix);
5579
5604
  },
5580
5605
  getDocFragments: (state, defaultValue) => {
5581
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5606
+ const docs = parser.getDocFragments(state, defaultValue);
5607
+ const { brief, description, footer, fragments } = docs;
5582
5608
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5583
5609
  const allEntries = [];
5584
5610
  const titledSections = [];
@@ -5601,7 +5627,7 @@ function group(label, parser, options = {}) {
5601
5627
  title: label,
5602
5628
  entries: allEntries
5603
5629
  } : { entries: allEntries };
5604
- return {
5630
+ return require_command_doc_metadata.withCommandDocMetadata({
5605
5631
  brief,
5606
5632
  description,
5607
5633
  footer,
@@ -5612,7 +5638,7 @@ function group(label, parser, options = {}) {
5612
5638
  type: "section",
5613
5639
  ...labeledSection
5614
5640
  }]
5615
- };
5641
+ }, require_command_doc_metadata.getCommandDocMetadata(docs));
5616
5642
  }
5617
5643
  };
5618
5644
  require_internal_parser.defineParseLanes(groupParser, require_internal_parser.getOwnParseLanes(parser));
@@ -8,6 +8,7 @@ import { createDependencySourceState, dependencyId, isDependencySourceState, isP
8
8
  import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyRuntimeContext, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync } from "./dependency-runtime.js";
9
9
  import { defineInheritedAnnotationParser, defineParseLanes, getOwnParseLanes, getParserSuggestRuntimeNodes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
10
10
  import { annotationViewTargets, getWrappedChildParseState, getWrappedChildState, reconcileObjectChildState, unwrapAnnotationView } from "./annotation-state.js";
11
+ import { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
11
12
  import { combineOptionMatches, combinePassThroughPriorities, defineOptionMatch, definePassThroughPriority, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure } from "./internal/passthrough.js";
12
13
  import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
13
14
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
@@ -1350,6 +1351,7 @@ function or(...args) {
1350
1351
  },
1351
1352
  suggest: createExclusiveSuggest(parsers, combinedMode),
1352
1353
  getDocFragments(state, _defaultValue) {
1354
+ let commandMetadata;
1353
1355
  let brief;
1354
1356
  let description;
1355
1357
  let footer;
@@ -1362,18 +1364,19 @@ function or(...args) {
1362
1364
  state: parserResult.next.state
1363
1365
  } : { kind: "unavailable" };
1364
1366
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1367
+ commandMetadata = getCommandDocMetadata(docFragments);
1365
1368
  brief = docFragments.brief;
1366
1369
  description = docFragments.description;
1367
1370
  footer = docFragments.footer;
1368
1371
  fragments = docFragments.fragments;
1369
1372
  }
1370
1373
  if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
1371
- return {
1374
+ return withCommandDocMetadata({
1372
1375
  brief,
1373
1376
  description,
1374
1377
  footer,
1375
1378
  fragments
1376
- };
1379
+ }, commandMetadata);
1377
1380
  }
1378
1381
  };
1379
1382
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1581,6 +1584,7 @@ function createLongestMatch(...args) {
1581
1584
  },
1582
1585
  suggest: createExclusiveSuggest(parsers, combinedMode),
1583
1586
  getDocFragments(state, _defaultValue) {
1587
+ let commandMetadata;
1584
1588
  let brief;
1585
1589
  let description;
1586
1590
  let footer;
@@ -1596,6 +1600,7 @@ function createLongestMatch(...args) {
1596
1600
  kind: "available",
1597
1601
  state: result.next.state
1598
1602
  });
1603
+ commandMetadata = getCommandDocMetadata(docResult);
1599
1604
  brief = docResult.brief;
1600
1605
  description = docResult.description;
1601
1606
  footer = docResult.footer;
@@ -1606,12 +1611,12 @@ function createLongestMatch(...args) {
1606
1611
  shouldDeduplicate = true;
1607
1612
  }
1608
1613
  }
1609
- return {
1614
+ return withCommandDocMetadata({
1610
1615
  brief,
1611
1616
  description,
1612
1617
  fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
1613
1618
  footer
1614
- };
1619
+ }, commandMetadata);
1615
1620
  }
1616
1621
  };
1617
1622
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2583,12 +2588,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2583
2588
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2584
2589
  },
2585
2590
  getDocFragments(state, defaultValue) {
2591
+ let commandMetadata;
2586
2592
  const fragments = parserPairs.flatMap(([field, p]) => {
2587
2593
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2588
2594
  kind: "available",
2589
2595
  state: state.state[field]
2590
2596
  };
2591
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2597
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2598
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
2599
+ return docs.fragments;
2592
2600
  });
2593
2601
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2594
2602
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2603,10 +2611,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2603
2611
  entries
2604
2612
  };
2605
2613
  sections.push(section);
2606
- return { fragments: sections.map((s) => ({
2607
- ...s,
2608
- type: "section"
2609
- })) };
2614
+ return withCommandDocMetadata({
2615
+ ...commandMetadata,
2616
+ fragments: sections.map((s) => ({
2617
+ ...s,
2618
+ type: "section"
2619
+ }))
2620
+ }, commandMetadata);
2610
2621
  }
2611
2622
  };
2612
2623
  const fieldNormalizers = [];
@@ -3599,12 +3610,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3599
3610
  return dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3600
3611
  },
3601
3612
  getDocFragments(state, defaultValue) {
3613
+ let commandMetadata;
3602
3614
  const fragments = syncParsers.flatMap((p, i) => {
3603
3615
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3604
3616
  kind: "available",
3605
3617
  state: state.state[i]
3606
3618
  };
3607
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3619
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3620
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
3621
+ return docs.fragments;
3608
3622
  });
3609
3623
  const entries = fragments.filter((d) => d.type === "entry");
3610
3624
  const sections = [];
@@ -3618,10 +3632,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3618
3632
  entries
3619
3633
  };
3620
3634
  sections.push(section);
3621
- return { fragments: sections.map((s) => ({
3622
- ...s,
3623
- type: "section"
3624
- })) };
3635
+ return withCommandDocMetadata({
3636
+ ...commandMetadata,
3637
+ fragments: sections.map((s) => ({
3638
+ ...s,
3639
+ type: "section"
3640
+ }))
3641
+ }, commandMetadata);
3625
3642
  },
3626
3643
  [Symbol.for("Deno.customInspect")]() {
3627
3644
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4847,6 +4864,7 @@ function merge(...args) {
4847
4864
  }();
4848
4865
  },
4849
4866
  getDocFragments(state, _defaultValue) {
4867
+ let commandMetadata;
4850
4868
  let brief;
4851
4869
  let description;
4852
4870
  let footer;
@@ -4864,6 +4882,7 @@ function merge(...args) {
4864
4882
  state: state.state
4865
4883
  };
4866
4884
  const docFragments = p.getDocFragments(parserState, void 0);
4885
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
4867
4886
  brief ??= docFragments.brief;
4868
4887
  description ??= docFragments.description;
4869
4888
  footer ??= docFragments.footer;
@@ -4883,7 +4902,7 @@ function merge(...args) {
4883
4902
  entries
4884
4903
  };
4885
4904
  sections.push(labeledSection);
4886
- return {
4905
+ return withCommandDocMetadata({
4887
4906
  brief,
4888
4907
  description,
4889
4908
  footer,
@@ -4891,9 +4910,9 @@ function merge(...args) {
4891
4910
  ...s,
4892
4911
  type: "section"
4893
4912
  }))
4894
- };
4913
+ }, commandMetadata);
4895
4914
  }
4896
- return {
4915
+ return withCommandDocMetadata({
4897
4916
  brief,
4898
4917
  description,
4899
4918
  footer,
@@ -4904,7 +4923,7 @@ function merge(...args) {
4904
4923
  type: "section",
4905
4924
  entries
4906
4925
  }]
4907
- };
4926
+ }, commandMetadata);
4908
4927
  }
4909
4928
  };
4910
4929
  defineParseLanes(mergeParser, mergeParseLanes);
@@ -5520,12 +5539,15 @@ function concat(...parsers) {
5520
5539
  }();
5521
5540
  },
5522
5541
  getDocFragments(state, _defaultValue) {
5542
+ let commandMetadata;
5523
5543
  const fragments = syncParsers.flatMap((p, index) => {
5524
5544
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5525
5545
  kind: "available",
5526
5546
  state: state.state[index]
5527
5547
  };
5528
- return p.getDocFragments(indexState, void 0).fragments;
5548
+ const docs = p.getDocFragments(indexState, void 0);
5549
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
5550
+ return docs.fragments;
5529
5551
  });
5530
5552
  const entries = fragments.filter((f) => f.type === "entry");
5531
5553
  const sections = [];
@@ -5542,7 +5564,10 @@ function concat(...parsers) {
5542
5564
  type: "section",
5543
5565
  entries
5544
5566
  });
5545
- return { fragments: result };
5567
+ return withCommandDocMetadata({
5568
+ ...commandMetadata,
5569
+ fragments: result
5570
+ }, commandMetadata);
5546
5571
  }
5547
5572
  };
5548
5573
  defineInheritedAnnotationParser(concatParser);
@@ -5578,7 +5603,8 @@ function group(label, parser, options = {}) {
5578
5603
  return parser.suggest(context, prefix);
5579
5604
  },
5580
5605
  getDocFragments: (state, defaultValue) => {
5581
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5606
+ const docs = parser.getDocFragments(state, defaultValue);
5607
+ const { brief, description, footer, fragments } = docs;
5582
5608
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5583
5609
  const allEntries = [];
5584
5610
  const titledSections = [];
@@ -5601,7 +5627,7 @@ function group(label, parser, options = {}) {
5601
5627
  title: label,
5602
5628
  entries: allEntries
5603
5629
  } : { entries: allEntries };
5604
- return {
5630
+ return withCommandDocMetadata({
5605
5631
  brief,
5606
5632
  description,
5607
5633
  footer,
@@ -5612,7 +5638,7 @@ function group(label, parser, options = {}) {
5612
5638
  type: "section",
5613
5639
  ...labeledSection
5614
5640
  }]
5615
- };
5641
+ }, getCommandDocMetadata(docs));
5616
5642
  }
5617
5643
  };
5618
5644
  defineParseLanes(groupParser, getOwnParseLanes(parser));
@@ -16,6 +16,17 @@ function getDisplayWidth(text) {
16
16
  for (const { segment } of segmenter.segment(stripped)) width += graphemeWidth(segment);
17
17
  return width;
18
18
  }
19
+ /**
20
+ * Removes ANSI escape sequences (CSI and OSC) from a string, leaving only
21
+ * the text a terminal would print.
22
+ *
23
+ * @param text The string to strip.
24
+ * @returns The string without ANSI escape sequences.
25
+ * @internal
26
+ */
27
+ function stripAnsi(text) {
28
+ return text.replace(ansiRegex, "");
29
+ }
19
30
  const zeroWidthRegex = /^[\p{Cf}\p{Mn}\p{Me}]+$/u;
20
31
  const emojiPresentationRegex = /\p{Emoji_Presentation}/u;
21
32
  const emojiWithVS16Regex = /\p{Emoji}\uFE0F/u;
@@ -41,4 +52,5 @@ function isEastAsianWide(cp) {
41
52
  }
42
53
 
43
54
  //#endregion
44
- exports.getDisplayWidth = getDisplayWidth;
55
+ exports.getDisplayWidth = getDisplayWidth;
56
+ exports.stripAnsi = stripAnsi;
@@ -8,5 +8,14 @@
8
8
  * @internal
9
9
  */
10
10
  declare function getDisplayWidth(text: string): number;
11
+ /**
12
+ * Removes ANSI escape sequences (CSI and OSC) from a string, leaving only
13
+ * the text a terminal would print.
14
+ *
15
+ * @param text The string to strip.
16
+ * @returns The string without ANSI escape sequences.
17
+ * @internal
18
+ */
19
+ declare function stripAnsi(text: string): string;
11
20
  //#endregion
12
- export { getDisplayWidth };
21
+ export { getDisplayWidth, stripAnsi };
@@ -8,5 +8,14 @@
8
8
  * @internal
9
9
  */
10
10
  declare function getDisplayWidth(text: string): number;
11
+ /**
12
+ * Removes ANSI escape sequences (CSI and OSC) from a string, leaving only
13
+ * the text a terminal would print.
14
+ *
15
+ * @param text The string to strip.
16
+ * @returns The string without ANSI escape sequences.
17
+ * @internal
18
+ */
19
+ declare function stripAnsi(text: string): string;
11
20
  //#endregion
12
- export { getDisplayWidth };
21
+ export { getDisplayWidth, stripAnsi };
@@ -15,6 +15,17 @@ function getDisplayWidth(text) {
15
15
  for (const { segment } of segmenter.segment(stripped)) width += graphemeWidth(segment);
16
16
  return width;
17
17
  }
18
+ /**
19
+ * Removes ANSI escape sequences (CSI and OSC) from a string, leaving only
20
+ * the text a terminal would print.
21
+ *
22
+ * @param text The string to strip.
23
+ * @returns The string without ANSI escape sequences.
24
+ * @internal
25
+ */
26
+ function stripAnsi(text) {
27
+ return text.replace(ansiRegex, "");
28
+ }
18
29
  const zeroWidthRegex = /^[\p{Cf}\p{Mn}\p{Me}]+$/u;
19
30
  const emojiPresentationRegex = /\p{Emoji_Presentation}/u;
20
31
  const emojiWithVS16Regex = /\p{Emoji}\uFE0F/u;
@@ -40,4 +51,4 @@ function isEastAsianWide(cp) {
40
51
  }
41
52
 
42
53
  //#endregion
43
- export { getDisplayWidth };
54
+ export { getDisplayWidth, stripAnsi };
package/dist/doc.cjs CHANGED
@@ -341,13 +341,15 @@ function formatDocPage(programName, page, options = {}) {
341
341
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
342
342
  const prefixWidth = require_displaywidth.getDisplayWidth(prefix);
343
343
  const suffixWidth = require_displaywidth.getDisplayWidth(suffix);
344
+ let defaultPrefix = prefix;
344
345
  let defaultStartWidth;
345
346
  if (descColumnWidth != null) {
346
347
  const lastW = lastLineVisibleLength(description);
347
348
  const effectiveLastW = lastW + currentExtraOffset();
348
349
  if (effectiveLastW + prefixWidth >= descColumnWidth) {
349
350
  description += "\n";
350
- defaultStartWidth = prefixWidth;
351
+ defaultPrefix = prefix.trimStart();
352
+ defaultStartWidth = require_displaywidth.getDisplayWidth(defaultPrefix);
351
353
  } else defaultStartWidth = effectiveLastW + prefixWidth;
352
354
  }
353
355
  const defaultFormatOptions = {
@@ -357,7 +359,7 @@ function formatDocPage(programName, page, options = {}) {
357
359
  startWidth: defaultStartWidth
358
360
  };
359
361
  const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
360
- const defaultText = `${prefix}${defaultContent}${suffix}`;
362
+ const defaultText = `${defaultPrefix}${defaultContent}${suffix}`;
361
363
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
362
364
  description += formattedDefault;
363
365
  }
@@ -385,6 +387,7 @@ function formatDocPage(programName, page, options = {}) {
385
387
  const choicesPrefixWidth = require_displaywidth.getDisplayWidth(prefix);
386
388
  const choicesSuffixWidth = require_displaywidth.getDisplayWidth(suffix);
387
389
  const choicesLabelWidth = require_displaywidth.getDisplayWidth(label);
390
+ let choicesHeading = `${prefix}${label}`;
388
391
  let choicesStartWidth;
389
392
  if (descColumnWidth != null) {
390
393
  const lastW = lastLineVisibleLength(description);
@@ -392,7 +395,8 @@ function formatDocPage(programName, page, options = {}) {
392
395
  const prefixLabelLen = choicesPrefixWidth + choicesLabelWidth;
393
396
  if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
394
397
  description += "\n";
395
- choicesStartWidth = prefixLabelLen;
398
+ choicesHeading = choicesHeading.trimStart();
399
+ choicesStartWidth = require_displaywidth.getDisplayWidth(choicesHeading);
396
400
  } else choicesStartWidth = effectiveLastW + prefixLabelLen;
397
401
  }
398
402
  const choicesFormatOptions = {
@@ -402,7 +406,7 @@ function formatDocPage(programName, page, options = {}) {
402
406
  startWidth: choicesStartWidth
403
407
  };
404
408
  const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
405
- const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
409
+ const choicesText = `${choicesHeading}${choicesDisplay}${suffix}`;
406
410
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
407
411
  description += formattedChoices;
408
412
  }
package/dist/doc.js CHANGED
@@ -341,13 +341,15 @@ function formatDocPage(programName, page, options = {}) {
341
341
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
342
342
  const prefixWidth = getDisplayWidth(prefix);
343
343
  const suffixWidth = getDisplayWidth(suffix);
344
+ let defaultPrefix = prefix;
344
345
  let defaultStartWidth;
345
346
  if (descColumnWidth != null) {
346
347
  const lastW = lastLineVisibleLength(description);
347
348
  const effectiveLastW = lastW + currentExtraOffset();
348
349
  if (effectiveLastW + prefixWidth >= descColumnWidth) {
349
350
  description += "\n";
350
- defaultStartWidth = prefixWidth;
351
+ defaultPrefix = prefix.trimStart();
352
+ defaultStartWidth = getDisplayWidth(defaultPrefix);
351
353
  } else defaultStartWidth = effectiveLastW + prefixWidth;
352
354
  }
353
355
  const defaultFormatOptions = {
@@ -357,7 +359,7 @@ function formatDocPage(programName, page, options = {}) {
357
359
  startWidth: defaultStartWidth
358
360
  };
359
361
  const defaultContent = formatMessage(entry.default, defaultFormatOptions);
360
- const defaultText = `${prefix}${defaultContent}${suffix}`;
362
+ const defaultText = `${defaultPrefix}${defaultContent}${suffix}`;
361
363
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
362
364
  description += formattedDefault;
363
365
  }
@@ -385,6 +387,7 @@ function formatDocPage(programName, page, options = {}) {
385
387
  const choicesPrefixWidth = getDisplayWidth(prefix);
386
388
  const choicesSuffixWidth = getDisplayWidth(suffix);
387
389
  const choicesLabelWidth = getDisplayWidth(label);
390
+ let choicesHeading = `${prefix}${label}`;
388
391
  let choicesStartWidth;
389
392
  if (descColumnWidth != null) {
390
393
  const lastW = lastLineVisibleLength(description);
@@ -392,7 +395,8 @@ function formatDocPage(programName, page, options = {}) {
392
395
  const prefixLabelLen = choicesPrefixWidth + choicesLabelWidth;
393
396
  if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
394
397
  description += "\n";
395
- choicesStartWidth = prefixLabelLen;
398
+ choicesHeading = choicesHeading.trimStart();
399
+ choicesStartWidth = getDisplayWidth(choicesHeading);
396
400
  } else choicesStartWidth = effectiveLastW + prefixLabelLen;
397
401
  }
398
402
  const choicesFormatOptions = {
@@ -402,7 +406,7 @@ function formatDocPage(programName, page, options = {}) {
402
406
  startWidth: choicesStartWidth
403
407
  };
404
408
  const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
405
- const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
409
+ const choicesText = `${choicesHeading}${choicesDisplay}${suffix}`;
406
410
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
407
411
  description += formattedChoices;
408
412
  }