@optique/core 1.2.9 → 1.2.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');
@@ -1351,6 +1352,7 @@ function or(...args) {
1351
1352
  },
1352
1353
  suggest: createExclusiveSuggest(parsers, combinedMode),
1353
1354
  getDocFragments(state, _defaultValue) {
1355
+ let commandMetadata;
1354
1356
  let brief;
1355
1357
  let description;
1356
1358
  let footer;
@@ -1363,18 +1365,19 @@ function or(...args) {
1363
1365
  state: parserResult.next.state
1364
1366
  } : { kind: "unavailable" };
1365
1367
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1368
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
1366
1369
  brief = docFragments.brief;
1367
1370
  description = docFragments.description;
1368
1371
  footer = docFragments.footer;
1369
1372
  fragments = docFragments.fragments;
1370
1373
  }
1371
1374
  if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
1372
- return {
1375
+ return require_command_doc_metadata.withCommandDocMetadata({
1373
1376
  brief,
1374
1377
  description,
1375
1378
  footer,
1376
1379
  fragments
1377
- };
1380
+ }, commandMetadata);
1378
1381
  }
1379
1382
  };
1380
1383
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1582,6 +1585,7 @@ function createLongestMatch(...args) {
1582
1585
  },
1583
1586
  suggest: createExclusiveSuggest(parsers, combinedMode),
1584
1587
  getDocFragments(state, _defaultValue) {
1588
+ let commandMetadata;
1585
1589
  let brief;
1586
1590
  let description;
1587
1591
  let footer;
@@ -1597,6 +1601,7 @@ function createLongestMatch(...args) {
1597
1601
  kind: "available",
1598
1602
  state: result.next.state
1599
1603
  });
1604
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
1600
1605
  brief = docResult.brief;
1601
1606
  description = docResult.description;
1602
1607
  footer = docResult.footer;
@@ -1607,12 +1612,12 @@ function createLongestMatch(...args) {
1607
1612
  shouldDeduplicate = true;
1608
1613
  }
1609
1614
  }
1610
- return {
1615
+ return require_command_doc_metadata.withCommandDocMetadata({
1611
1616
  brief,
1612
1617
  description,
1613
1618
  fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
1614
1619
  footer
1615
- };
1620
+ }, commandMetadata);
1616
1621
  }
1617
1622
  };
1618
1623
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2584,12 +2589,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2584
2589
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2585
2590
  },
2586
2591
  getDocFragments(state, defaultValue) {
2592
+ let commandMetadata;
2587
2593
  const fragments = parserPairs.flatMap(([field, p]) => {
2588
2594
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2589
2595
  kind: "available",
2590
2596
  state: state.state[field]
2591
2597
  };
2592
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2598
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2599
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
2600
+ return docs.fragments;
2593
2601
  });
2594
2602
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2595
2603
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2604,10 +2612,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2604
2612
  entries
2605
2613
  };
2606
2614
  sections.push(section);
2607
- return { fragments: sections.map((s) => ({
2608
- ...s,
2609
- type: "section"
2610
- })) };
2615
+ return require_command_doc_metadata.withCommandDocMetadata({
2616
+ ...commandMetadata,
2617
+ fragments: sections.map((s) => ({
2618
+ ...s,
2619
+ type: "section"
2620
+ }))
2621
+ }, commandMetadata);
2611
2622
  }
2612
2623
  };
2613
2624
  const fieldNormalizers = [];
@@ -3600,12 +3611,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3600
3611
  return require_mode_dispatch.dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3601
3612
  },
3602
3613
  getDocFragments(state, defaultValue) {
3614
+ let commandMetadata;
3603
3615
  const fragments = syncParsers.flatMap((p, i) => {
3604
3616
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3605
3617
  kind: "available",
3606
3618
  state: state.state[i]
3607
3619
  };
3608
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3620
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3621
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
3622
+ return docs.fragments;
3609
3623
  });
3610
3624
  const entries = fragments.filter((d) => d.type === "entry");
3611
3625
  const sections = [];
@@ -3619,10 +3633,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3619
3633
  entries
3620
3634
  };
3621
3635
  sections.push(section);
3622
- return { fragments: sections.map((s) => ({
3623
- ...s,
3624
- type: "section"
3625
- })) };
3636
+ return require_command_doc_metadata.withCommandDocMetadata({
3637
+ ...commandMetadata,
3638
+ fragments: sections.map((s) => ({
3639
+ ...s,
3640
+ type: "section"
3641
+ }))
3642
+ }, commandMetadata);
3626
3643
  },
3627
3644
  [Symbol.for("Deno.customInspect")]() {
3628
3645
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4848,6 +4865,7 @@ function merge(...args) {
4848
4865
  }();
4849
4866
  },
4850
4867
  getDocFragments(state, _defaultValue) {
4868
+ let commandMetadata;
4851
4869
  let brief;
4852
4870
  let description;
4853
4871
  let footer;
@@ -4865,6 +4883,7 @@ function merge(...args) {
4865
4883
  state: state.state
4866
4884
  };
4867
4885
  const docFragments = p.getDocFragments(parserState, void 0);
4886
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
4868
4887
  brief ??= docFragments.brief;
4869
4888
  description ??= docFragments.description;
4870
4889
  footer ??= docFragments.footer;
@@ -4884,7 +4903,7 @@ function merge(...args) {
4884
4903
  entries
4885
4904
  };
4886
4905
  sections.push(labeledSection);
4887
- return {
4906
+ return require_command_doc_metadata.withCommandDocMetadata({
4888
4907
  brief,
4889
4908
  description,
4890
4909
  footer,
@@ -4892,9 +4911,9 @@ function merge(...args) {
4892
4911
  ...s,
4893
4912
  type: "section"
4894
4913
  }))
4895
- };
4914
+ }, commandMetadata);
4896
4915
  }
4897
- return {
4916
+ return require_command_doc_metadata.withCommandDocMetadata({
4898
4917
  brief,
4899
4918
  description,
4900
4919
  footer,
@@ -4905,7 +4924,7 @@ function merge(...args) {
4905
4924
  type: "section",
4906
4925
  entries
4907
4926
  }]
4908
- };
4927
+ }, commandMetadata);
4909
4928
  }
4910
4929
  };
4911
4930
  require_internal_parser.defineParseLanes(mergeParser, mergeParseLanes);
@@ -5521,12 +5540,15 @@ function concat(...parsers) {
5521
5540
  }();
5522
5541
  },
5523
5542
  getDocFragments(state, _defaultValue) {
5543
+ let commandMetadata;
5524
5544
  const fragments = syncParsers.flatMap((p, index) => {
5525
5545
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5526
5546
  kind: "available",
5527
5547
  state: state.state[index]
5528
5548
  };
5529
- return p.getDocFragments(indexState, void 0).fragments;
5549
+ const docs = p.getDocFragments(indexState, void 0);
5550
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
5551
+ return docs.fragments;
5530
5552
  });
5531
5553
  const entries = fragments.filter((f) => f.type === "entry");
5532
5554
  const sections = [];
@@ -5543,7 +5565,10 @@ function concat(...parsers) {
5543
5565
  type: "section",
5544
5566
  entries
5545
5567
  });
5546
- return { fragments: result };
5568
+ return require_command_doc_metadata.withCommandDocMetadata({
5569
+ ...commandMetadata,
5570
+ fragments: result
5571
+ }, commandMetadata);
5547
5572
  }
5548
5573
  };
5549
5574
  require_internal_parser.defineInheritedAnnotationParser(concatParser);
@@ -5579,7 +5604,8 @@ function group(label, parser, options = {}) {
5579
5604
  return parser.suggest(context, prefix);
5580
5605
  },
5581
5606
  getDocFragments: (state, defaultValue) => {
5582
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5607
+ const docs = parser.getDocFragments(state, defaultValue);
5608
+ const { brief, description, footer, fragments } = docs;
5583
5609
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5584
5610
  const allEntries = [];
5585
5611
  const titledSections = [];
@@ -5602,7 +5628,7 @@ function group(label, parser, options = {}) {
5602
5628
  title: label,
5603
5629
  entries: allEntries
5604
5630
  } : { entries: allEntries };
5605
- return {
5631
+ return require_command_doc_metadata.withCommandDocMetadata({
5606
5632
  brief,
5607
5633
  description,
5608
5634
  footer,
@@ -5613,7 +5639,7 @@ function group(label, parser, options = {}) {
5613
5639
  type: "section",
5614
5640
  ...labeledSection
5615
5641
  }]
5616
- };
5642
+ }, require_command_doc_metadata.getCommandDocMetadata(docs));
5617
5643
  }
5618
5644
  };
5619
5645
  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";
@@ -1351,6 +1352,7 @@ function or(...args) {
1351
1352
  },
1352
1353
  suggest: createExclusiveSuggest(parsers, combinedMode),
1353
1354
  getDocFragments(state, _defaultValue) {
1355
+ let commandMetadata;
1354
1356
  let brief;
1355
1357
  let description;
1356
1358
  let footer;
@@ -1363,18 +1365,19 @@ function or(...args) {
1363
1365
  state: parserResult.next.state
1364
1366
  } : { kind: "unavailable" };
1365
1367
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1368
+ commandMetadata = getCommandDocMetadata(docFragments);
1366
1369
  brief = docFragments.brief;
1367
1370
  description = docFragments.description;
1368
1371
  footer = docFragments.footer;
1369
1372
  fragments = docFragments.fragments;
1370
1373
  }
1371
1374
  if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
1372
- return {
1375
+ return withCommandDocMetadata({
1373
1376
  brief,
1374
1377
  description,
1375
1378
  footer,
1376
1379
  fragments
1377
- };
1380
+ }, commandMetadata);
1378
1381
  }
1379
1382
  };
1380
1383
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1582,6 +1585,7 @@ function createLongestMatch(...args) {
1582
1585
  },
1583
1586
  suggest: createExclusiveSuggest(parsers, combinedMode),
1584
1587
  getDocFragments(state, _defaultValue) {
1588
+ let commandMetadata;
1585
1589
  let brief;
1586
1590
  let description;
1587
1591
  let footer;
@@ -1597,6 +1601,7 @@ function createLongestMatch(...args) {
1597
1601
  kind: "available",
1598
1602
  state: result.next.state
1599
1603
  });
1604
+ commandMetadata = getCommandDocMetadata(docResult);
1600
1605
  brief = docResult.brief;
1601
1606
  description = docResult.description;
1602
1607
  footer = docResult.footer;
@@ -1607,12 +1612,12 @@ function createLongestMatch(...args) {
1607
1612
  shouldDeduplicate = true;
1608
1613
  }
1609
1614
  }
1610
- return {
1615
+ return withCommandDocMetadata({
1611
1616
  brief,
1612
1617
  description,
1613
1618
  fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
1614
1619
  footer
1615
- };
1620
+ }, commandMetadata);
1616
1621
  }
1617
1622
  };
1618
1623
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2584,12 +2589,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2584
2589
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2585
2590
  },
2586
2591
  getDocFragments(state, defaultValue) {
2592
+ let commandMetadata;
2587
2593
  const fragments = parserPairs.flatMap(([field, p]) => {
2588
2594
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2589
2595
  kind: "available",
2590
2596
  state: state.state[field]
2591
2597
  };
2592
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2598
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2599
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
2600
+ return docs.fragments;
2593
2601
  });
2594
2602
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2595
2603
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2604,10 +2612,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2604
2612
  entries
2605
2613
  };
2606
2614
  sections.push(section);
2607
- return { fragments: sections.map((s) => ({
2608
- ...s,
2609
- type: "section"
2610
- })) };
2615
+ return withCommandDocMetadata({
2616
+ ...commandMetadata,
2617
+ fragments: sections.map((s) => ({
2618
+ ...s,
2619
+ type: "section"
2620
+ }))
2621
+ }, commandMetadata);
2611
2622
  }
2612
2623
  };
2613
2624
  const fieldNormalizers = [];
@@ -3600,12 +3611,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3600
3611
  return dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3601
3612
  },
3602
3613
  getDocFragments(state, defaultValue) {
3614
+ let commandMetadata;
3603
3615
  const fragments = syncParsers.flatMap((p, i) => {
3604
3616
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3605
3617
  kind: "available",
3606
3618
  state: state.state[i]
3607
3619
  };
3608
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3620
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3621
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
3622
+ return docs.fragments;
3609
3623
  });
3610
3624
  const entries = fragments.filter((d) => d.type === "entry");
3611
3625
  const sections = [];
@@ -3619,10 +3633,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3619
3633
  entries
3620
3634
  };
3621
3635
  sections.push(section);
3622
- return { fragments: sections.map((s) => ({
3623
- ...s,
3624
- type: "section"
3625
- })) };
3636
+ return withCommandDocMetadata({
3637
+ ...commandMetadata,
3638
+ fragments: sections.map((s) => ({
3639
+ ...s,
3640
+ type: "section"
3641
+ }))
3642
+ }, commandMetadata);
3626
3643
  },
3627
3644
  [Symbol.for("Deno.customInspect")]() {
3628
3645
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4848,6 +4865,7 @@ function merge(...args) {
4848
4865
  }();
4849
4866
  },
4850
4867
  getDocFragments(state, _defaultValue) {
4868
+ let commandMetadata;
4851
4869
  let brief;
4852
4870
  let description;
4853
4871
  let footer;
@@ -4865,6 +4883,7 @@ function merge(...args) {
4865
4883
  state: state.state
4866
4884
  };
4867
4885
  const docFragments = p.getDocFragments(parserState, void 0);
4886
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
4868
4887
  brief ??= docFragments.brief;
4869
4888
  description ??= docFragments.description;
4870
4889
  footer ??= docFragments.footer;
@@ -4884,7 +4903,7 @@ function merge(...args) {
4884
4903
  entries
4885
4904
  };
4886
4905
  sections.push(labeledSection);
4887
- return {
4906
+ return withCommandDocMetadata({
4888
4907
  brief,
4889
4908
  description,
4890
4909
  footer,
@@ -4892,9 +4911,9 @@ function merge(...args) {
4892
4911
  ...s,
4893
4912
  type: "section"
4894
4913
  }))
4895
- };
4914
+ }, commandMetadata);
4896
4915
  }
4897
- return {
4916
+ return withCommandDocMetadata({
4898
4917
  brief,
4899
4918
  description,
4900
4919
  footer,
@@ -4905,7 +4924,7 @@ function merge(...args) {
4905
4924
  type: "section",
4906
4925
  entries
4907
4926
  }]
4908
- };
4927
+ }, commandMetadata);
4909
4928
  }
4910
4929
  };
4911
4930
  defineParseLanes(mergeParser, mergeParseLanes);
@@ -5521,12 +5540,15 @@ function concat(...parsers) {
5521
5540
  }();
5522
5541
  },
5523
5542
  getDocFragments(state, _defaultValue) {
5543
+ let commandMetadata;
5524
5544
  const fragments = syncParsers.flatMap((p, index) => {
5525
5545
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5526
5546
  kind: "available",
5527
5547
  state: state.state[index]
5528
5548
  };
5529
- return p.getDocFragments(indexState, void 0).fragments;
5549
+ const docs = p.getDocFragments(indexState, void 0);
5550
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
5551
+ return docs.fragments;
5530
5552
  });
5531
5553
  const entries = fragments.filter((f) => f.type === "entry");
5532
5554
  const sections = [];
@@ -5543,7 +5565,10 @@ function concat(...parsers) {
5543
5565
  type: "section",
5544
5566
  entries
5545
5567
  });
5546
- return { fragments: result };
5568
+ return withCommandDocMetadata({
5569
+ ...commandMetadata,
5570
+ fragments: result
5571
+ }, commandMetadata);
5547
5572
  }
5548
5573
  };
5549
5574
  defineInheritedAnnotationParser(concatParser);
@@ -5579,7 +5604,8 @@ function group(label, parser, options = {}) {
5579
5604
  return parser.suggest(context, prefix);
5580
5605
  },
5581
5606
  getDocFragments: (state, defaultValue) => {
5582
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5607
+ const docs = parser.getDocFragments(state, defaultValue);
5608
+ const { brief, description, footer, fragments } = docs;
5583
5609
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5584
5610
  const allEntries = [];
5585
5611
  const titledSections = [];
@@ -5602,7 +5628,7 @@ function group(label, parser, options = {}) {
5602
5628
  title: label,
5603
5629
  entries: allEntries
5604
5630
  } : { entries: allEntries };
5605
- return {
5631
+ return withCommandDocMetadata({
5606
5632
  brief,
5607
5633
  description,
5608
5634
  footer,
@@ -5613,7 +5639,7 @@ function group(label, parser, options = {}) {
5613
5639
  type: "section",
5614
5640
  ...labeledSection
5615
5641
  }]
5616
- };
5642
+ }, getCommandDocMetadata(docs));
5617
5643
  }
5618
5644
  };
5619
5645
  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
@@ -342,13 +342,15 @@ function formatDocPage(programName, page, options = {}) {
342
342
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
343
343
  const prefixWidth = require_displaywidth.getDisplayWidth(prefix);
344
344
  const suffixWidth = require_displaywidth.getDisplayWidth(suffix);
345
+ let defaultPrefix = prefix;
345
346
  let defaultStartWidth;
346
347
  if (descColumnWidth != null) {
347
348
  const lastW = lastLineVisibleLength(description);
348
349
  const effectiveLastW = lastW + currentExtraOffset();
349
350
  if (effectiveLastW + prefixWidth >= descColumnWidth) {
350
351
  description += "\n";
351
- defaultStartWidth = prefixWidth;
352
+ defaultPrefix = prefix.trimStart();
353
+ defaultStartWidth = require_displaywidth.getDisplayWidth(defaultPrefix);
352
354
  } else defaultStartWidth = effectiveLastW + prefixWidth;
353
355
  }
354
356
  const defaultFormatOptions = {
@@ -358,7 +360,7 @@ function formatDocPage(programName, page, options = {}) {
358
360
  startWidth: defaultStartWidth
359
361
  };
360
362
  const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
361
- const defaultText = `${prefix}${defaultContent}${suffix}`;
363
+ const defaultText = `${defaultPrefix}${defaultContent}${suffix}`;
362
364
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
363
365
  description += formattedDefault;
364
366
  }
@@ -386,6 +388,7 @@ function formatDocPage(programName, page, options = {}) {
386
388
  const choicesPrefixWidth = require_displaywidth.getDisplayWidth(prefix);
387
389
  const choicesSuffixWidth = require_displaywidth.getDisplayWidth(suffix);
388
390
  const choicesLabelWidth = require_displaywidth.getDisplayWidth(label);
391
+ let choicesHeading = `${prefix}${label}`;
389
392
  let choicesStartWidth;
390
393
  if (descColumnWidth != null) {
391
394
  const lastW = lastLineVisibleLength(description);
@@ -393,7 +396,8 @@ function formatDocPage(programName, page, options = {}) {
393
396
  const prefixLabelLen = choicesPrefixWidth + choicesLabelWidth;
394
397
  if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
395
398
  description += "\n";
396
- choicesStartWidth = prefixLabelLen;
399
+ choicesHeading = choicesHeading.trimStart();
400
+ choicesStartWidth = require_displaywidth.getDisplayWidth(choicesHeading);
397
401
  } else choicesStartWidth = effectiveLastW + prefixLabelLen;
398
402
  }
399
403
  const choicesFormatOptions = {
@@ -403,7 +407,7 @@ function formatDocPage(programName, page, options = {}) {
403
407
  startWidth: choicesStartWidth
404
408
  };
405
409
  const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
406
- const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
410
+ const choicesText = `${choicesHeading}${choicesDisplay}${suffix}`;
407
411
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
408
412
  description += formattedChoices;
409
413
  }
package/dist/doc.js CHANGED
@@ -342,13 +342,15 @@ function formatDocPage(programName, page, options = {}) {
342
342
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
343
343
  const prefixWidth = getDisplayWidth(prefix);
344
344
  const suffixWidth = getDisplayWidth(suffix);
345
+ let defaultPrefix = prefix;
345
346
  let defaultStartWidth;
346
347
  if (descColumnWidth != null) {
347
348
  const lastW = lastLineVisibleLength(description);
348
349
  const effectiveLastW = lastW + currentExtraOffset();
349
350
  if (effectiveLastW + prefixWidth >= descColumnWidth) {
350
351
  description += "\n";
351
- defaultStartWidth = prefixWidth;
352
+ defaultPrefix = prefix.trimStart();
353
+ defaultStartWidth = getDisplayWidth(defaultPrefix);
352
354
  } else defaultStartWidth = effectiveLastW + prefixWidth;
353
355
  }
354
356
  const defaultFormatOptions = {
@@ -358,7 +360,7 @@ function formatDocPage(programName, page, options = {}) {
358
360
  startWidth: defaultStartWidth
359
361
  };
360
362
  const defaultContent = formatMessage(entry.default, defaultFormatOptions);
361
- const defaultText = `${prefix}${defaultContent}${suffix}`;
363
+ const defaultText = `${defaultPrefix}${defaultContent}${suffix}`;
362
364
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
363
365
  description += formattedDefault;
364
366
  }
@@ -386,6 +388,7 @@ function formatDocPage(programName, page, options = {}) {
386
388
  const choicesPrefixWidth = getDisplayWidth(prefix);
387
389
  const choicesSuffixWidth = getDisplayWidth(suffix);
388
390
  const choicesLabelWidth = getDisplayWidth(label);
391
+ let choicesHeading = `${prefix}${label}`;
389
392
  let choicesStartWidth;
390
393
  if (descColumnWidth != null) {
391
394
  const lastW = lastLineVisibleLength(description);
@@ -393,7 +396,8 @@ function formatDocPage(programName, page, options = {}) {
393
396
  const prefixLabelLen = choicesPrefixWidth + choicesLabelWidth;
394
397
  if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
395
398
  description += "\n";
396
- choicesStartWidth = prefixLabelLen;
399
+ choicesHeading = choicesHeading.trimStart();
400
+ choicesStartWidth = getDisplayWidth(choicesHeading);
397
401
  } else choicesStartWidth = effectiveLastW + prefixLabelLen;
398
402
  }
399
403
  const choicesFormatOptions = {
@@ -403,7 +407,7 @@ function formatDocPage(programName, page, options = {}) {
403
407
  startWidth: choicesStartWidth
404
408
  };
405
409
  const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
406
- const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
410
+ const choicesText = `${choicesHeading}${choicesDisplay}${suffix}`;
407
411
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
408
412
  description += formattedChoices;
409
413
  }