@optique/core 0.10.5 → 0.10.6-dev.425

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
@@ -79,26 +79,32 @@ function formatDocPage(programName, page, options = {}) {
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
80
80
  });
81
81
  const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
82
- let description = entry.description == null ? "" : require_message.formatMessage(entry.description, {
82
+ const termVisibleWidth = lastLineVisibleLength(term);
83
+ const extraTermOffset = descColumnWidth != null ? Math.max(0, termVisibleWidth - termWidth) : 0;
84
+ const currentExtraOffset = () => description.includes("\n") ? 0 : extraTermOffset;
85
+ const descFormatOptions = {
83
86
  colors: options.colors,
84
87
  quotes: !options.colors,
85
- maxWidth: descColumnWidth
86
- });
88
+ maxWidth: descColumnWidth,
89
+ startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
90
+ };
91
+ let description = entry.description == null ? "" : require_message.formatMessage(entry.description, descFormatOptions);
87
92
  if (options.showDefault && entry.default != null) {
88
93
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
89
94
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
90
95
  let defaultStartWidth;
91
96
  if (descColumnWidth != null) {
92
97
  const lastW = lastLineVisibleLength(description);
93
- if (lastW + prefix.length >= descColumnWidth) {
98
+ const effectiveLastW = lastW + currentExtraOffset();
99
+ if (effectiveLastW + prefix.length >= descColumnWidth) {
94
100
  description += "\n";
95
101
  defaultStartWidth = prefix.length;
96
- } else defaultStartWidth = lastW + prefix.length;
102
+ } else defaultStartWidth = effectiveLastW + prefix.length;
97
103
  }
98
104
  const defaultFormatOptions = {
99
105
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
100
106
  quotes: !options.colors,
101
- maxWidth: descColumnWidth,
107
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
102
108
  startWidth: defaultStartWidth
103
109
  };
104
110
  const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
@@ -130,16 +136,17 @@ function formatDocPage(programName, page, options = {}) {
130
136
  let choicesStartWidth;
131
137
  if (descColumnWidth != null) {
132
138
  const lastW = lastLineVisibleLength(description);
139
+ const effectiveLastW = lastW + currentExtraOffset();
133
140
  const prefixLabelLen = prefix.length + label.length;
134
- if (lastW + prefixLabelLen >= descColumnWidth) {
141
+ if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
135
142
  description += "\n";
136
143
  choicesStartWidth = prefixLabelLen;
137
- } else choicesStartWidth = lastW + prefixLabelLen;
144
+ } else choicesStartWidth = effectiveLastW + prefixLabelLen;
138
145
  }
139
146
  const choicesFormatOptions = {
140
147
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
141
148
  quotes: false,
142
- maxWidth: descColumnWidth,
149
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
143
150
  startWidth: choicesStartWidth
144
151
  };
145
152
  const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
package/dist/doc.js CHANGED
@@ -79,26 +79,32 @@ function formatDocPage(programName, page, options = {}) {
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
80
80
  });
81
81
  const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
82
- let description = entry.description == null ? "" : formatMessage(entry.description, {
82
+ const termVisibleWidth = lastLineVisibleLength(term);
83
+ const extraTermOffset = descColumnWidth != null ? Math.max(0, termVisibleWidth - termWidth) : 0;
84
+ const currentExtraOffset = () => description.includes("\n") ? 0 : extraTermOffset;
85
+ const descFormatOptions = {
83
86
  colors: options.colors,
84
87
  quotes: !options.colors,
85
- maxWidth: descColumnWidth
86
- });
88
+ maxWidth: descColumnWidth,
89
+ startWidth: extraTermOffset > 0 ? extraTermOffset : void 0
90
+ };
91
+ let description = entry.description == null ? "" : formatMessage(entry.description, descFormatOptions);
87
92
  if (options.showDefault && entry.default != null) {
88
93
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
89
94
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
90
95
  let defaultStartWidth;
91
96
  if (descColumnWidth != null) {
92
97
  const lastW = lastLineVisibleLength(description);
93
- if (lastW + prefix.length >= descColumnWidth) {
98
+ const effectiveLastW = lastW + currentExtraOffset();
99
+ if (effectiveLastW + prefix.length >= descColumnWidth) {
94
100
  description += "\n";
95
101
  defaultStartWidth = prefix.length;
96
- } else defaultStartWidth = lastW + prefix.length;
102
+ } else defaultStartWidth = effectiveLastW + prefix.length;
97
103
  }
98
104
  const defaultFormatOptions = {
99
105
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
100
106
  quotes: !options.colors,
101
- maxWidth: descColumnWidth,
107
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
102
108
  startWidth: defaultStartWidth
103
109
  };
104
110
  const defaultContent = formatMessage(entry.default, defaultFormatOptions);
@@ -130,16 +136,17 @@ function formatDocPage(programName, page, options = {}) {
130
136
  let choicesStartWidth;
131
137
  if (descColumnWidth != null) {
132
138
  const lastW = lastLineVisibleLength(description);
139
+ const effectiveLastW = lastW + currentExtraOffset();
133
140
  const prefixLabelLen = prefix.length + label.length;
134
- if (lastW + prefixLabelLen >= descColumnWidth) {
141
+ if (effectiveLastW + prefixLabelLen >= descColumnWidth) {
135
142
  description += "\n";
136
143
  choicesStartWidth = prefixLabelLen;
137
- } else choicesStartWidth = lastW + prefixLabelLen;
144
+ } else choicesStartWidth = effectiveLastW + prefixLabelLen;
138
145
  }
139
146
  const choicesFormatOptions = {
140
147
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
141
148
  quotes: false,
142
- maxWidth: descColumnWidth,
149
+ maxWidth: descColumnWidth == null ? void 0 : descColumnWidth - suffix.length,
143
150
  startWidth: choicesStartWidth
144
151
  };
145
152
  const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
package/dist/facade.cjs CHANGED
@@ -1048,6 +1048,7 @@ function runWithAsync(parser, programName, contexts, options) {
1048
1048
  * @returns A new parser with annotations in its initial state.
1049
1049
  */
1050
1050
  function injectAnnotationsIntoParser(parser, annotations) {
1051
+ if (parser.initialState == null) return parser;
1051
1052
  const newInitialState = {
1052
1053
  ...parser.initialState,
1053
1054
  [require_annotations.annotationKey]: annotations
package/dist/facade.js CHANGED
@@ -1048,6 +1048,7 @@ function runWithAsync(parser, programName, contexts, options) {
1048
1048
  * @returns A new parser with annotations in its initial state.
1049
1049
  */
1050
1050
  function injectAnnotationsIntoParser(parser, annotations) {
1051
+ if (parser.initialState == null) return parser;
1051
1052
  const newInitialState = {
1052
1053
  ...parser.initialState,
1053
1054
  [annotationKey]: annotations
package/dist/parser.cjs CHANGED
@@ -30,8 +30,8 @@ const require_primitives = require('./primitives.cjs');
30
30
  */
31
31
  function parseSync(parser, args, options) {
32
32
  let initialState = parser.initialState;
33
- if (options?.annotations) initialState = {
34
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
33
+ if (options?.annotations && initialState != null) initialState = {
34
+ ...typeof initialState === "object" ? initialState : {},
35
35
  [require_annotations.annotationKey]: options.annotations
36
36
  };
37
37
  let context = {
@@ -83,8 +83,8 @@ function parseSync(parser, args, options) {
83
83
  */
84
84
  async function parseAsync(parser, args, options) {
85
85
  let initialState = parser.initialState;
86
- if (options?.annotations) initialState = {
87
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
86
+ if (options?.annotations && initialState != null) initialState = {
87
+ ...typeof initialState === "object" ? initialState : {},
88
88
  [require_annotations.annotationKey]: options.annotations
89
89
  };
90
90
  let context = {
@@ -181,8 +181,8 @@ function suggestSync(parser, args, options) {
181
181
  const allButLast = args.slice(0, -1);
182
182
  const prefix = args[args.length - 1];
183
183
  let initialState = parser.initialState;
184
- if (options?.annotations) initialState = {
185
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
184
+ if (options?.annotations && initialState != null) initialState = {
185
+ ...typeof initialState === "object" ? initialState : {},
186
186
  [require_annotations.annotationKey]: options.annotations
187
187
  };
188
188
  let context = {
@@ -224,8 +224,8 @@ async function suggestAsync(parser, args, options) {
224
224
  const allButLast = args.slice(0, -1);
225
225
  const prefix = args[args.length - 1];
226
226
  let initialState = parser.initialState;
227
- if (options?.annotations) initialState = {
228
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
227
+ if (options?.annotations && initialState != null) initialState = {
228
+ ...typeof initialState === "object" ? initialState : {},
229
229
  [require_annotations.annotationKey]: options.annotations
230
230
  };
231
231
  let context = {
@@ -340,8 +340,8 @@ function getDocPage(parser, args = [], options) {
340
340
  */
341
341
  function getDocPageSyncImpl(parser, args, options) {
342
342
  let initialState = parser.initialState;
343
- if (options?.annotations) initialState = {
344
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
343
+ if (options?.annotations && initialState != null) initialState = {
344
+ ...typeof initialState === "object" ? initialState : {},
345
345
  [require_annotations.annotationKey]: options.annotations
346
346
  };
347
347
  let context = {
@@ -362,8 +362,8 @@ function getDocPageSyncImpl(parser, args, options) {
362
362
  */
363
363
  async function getDocPageAsyncImpl(parser, args, options) {
364
364
  let initialState = parser.initialState;
365
- if (options?.annotations) initialState = {
366
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
365
+ if (options?.annotations && initialState != null) initialState = {
366
+ ...typeof initialState === "object" ? initialState : {},
367
367
  [require_annotations.annotationKey]: options.annotations
368
368
  };
369
369
  let context = {
package/dist/parser.js CHANGED
@@ -30,8 +30,8 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
30
30
  */
31
31
  function parseSync(parser, args, options) {
32
32
  let initialState = parser.initialState;
33
- if (options?.annotations) initialState = {
34
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
33
+ if (options?.annotations && initialState != null) initialState = {
34
+ ...typeof initialState === "object" ? initialState : {},
35
35
  [annotationKey]: options.annotations
36
36
  };
37
37
  let context = {
@@ -83,8 +83,8 @@ function parseSync(parser, args, options) {
83
83
  */
84
84
  async function parseAsync(parser, args, options) {
85
85
  let initialState = parser.initialState;
86
- if (options?.annotations) initialState = {
87
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
86
+ if (options?.annotations && initialState != null) initialState = {
87
+ ...typeof initialState === "object" ? initialState : {},
88
88
  [annotationKey]: options.annotations
89
89
  };
90
90
  let context = {
@@ -181,8 +181,8 @@ function suggestSync(parser, args, options) {
181
181
  const allButLast = args.slice(0, -1);
182
182
  const prefix = args[args.length - 1];
183
183
  let initialState = parser.initialState;
184
- if (options?.annotations) initialState = {
185
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
184
+ if (options?.annotations && initialState != null) initialState = {
185
+ ...typeof initialState === "object" ? initialState : {},
186
186
  [annotationKey]: options.annotations
187
187
  };
188
188
  let context = {
@@ -224,8 +224,8 @@ async function suggestAsync(parser, args, options) {
224
224
  const allButLast = args.slice(0, -1);
225
225
  const prefix = args[args.length - 1];
226
226
  let initialState = parser.initialState;
227
- if (options?.annotations) initialState = {
228
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
227
+ if (options?.annotations && initialState != null) initialState = {
228
+ ...typeof initialState === "object" ? initialState : {},
229
229
  [annotationKey]: options.annotations
230
230
  };
231
231
  let context = {
@@ -340,8 +340,8 @@ function getDocPage(parser, args = [], options) {
340
340
  */
341
341
  function getDocPageSyncImpl(parser, args, options) {
342
342
  let initialState = parser.initialState;
343
- if (options?.annotations) initialState = {
344
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
343
+ if (options?.annotations && initialState != null) initialState = {
344
+ ...typeof initialState === "object" ? initialState : {},
345
345
  [annotationKey]: options.annotations
346
346
  };
347
347
  let context = {
@@ -362,8 +362,8 @@ function getDocPageSyncImpl(parser, args, options) {
362
362
  */
363
363
  async function getDocPageAsyncImpl(parser, args, options) {
364
364
  let initialState = parser.initialState;
365
- if (options?.annotations) initialState = {
366
- ...typeof initialState === "object" && initialState !== null ? initialState : {},
365
+ if (options?.annotations && initialState != null) initialState = {
366
+ ...typeof initialState === "object" ? initialState : {},
367
367
  [annotationKey]: options.annotations
368
368
  };
369
369
  let context = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.5",
3
+ "version": "0.10.6-dev.425+c46aa184",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",