@optique/core 0.10.4 → 0.10.5-dev.417

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
@@ -78,18 +78,31 @@ function formatDocPage(programName, page, options = {}) {
78
78
  optionsSeparator: ", ",
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
80
80
  });
81
+ const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
81
82
  let description = entry.description == null ? "" : require_message.formatMessage(entry.description, {
82
83
  colors: options.colors,
83
84
  quotes: !options.colors,
84
- maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
85
+ maxWidth: descColumnWidth
85
86
  });
86
87
  if (options.showDefault && entry.default != null) {
87
88
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
88
89
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
89
- const defaultText = `${prefix}${require_message.formatMessage(entry.default, {
90
+ let defaultStartWidth;
91
+ if (descColumnWidth != null) {
92
+ const lastW = lastLineVisibleLength(description);
93
+ if (lastW + prefix.length >= descColumnWidth) {
94
+ description += "\n";
95
+ defaultStartWidth = prefix.length;
96
+ } else defaultStartWidth = lastW + prefix.length;
97
+ }
98
+ const defaultFormatOptions = {
90
99
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
91
- quotes: !options.colors
92
- })}${suffix}`;
100
+ quotes: !options.colors,
101
+ maxWidth: descColumnWidth,
102
+ startWidth: defaultStartWidth
103
+ };
104
+ const defaultContent = require_message.formatMessage(entry.default, defaultFormatOptions);
105
+ const defaultText = `${prefix}${defaultContent}${suffix}`;
93
106
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
94
107
  description += formattedDefault;
95
108
  }
@@ -114,10 +127,22 @@ function formatDocPage(programName, page, options = {}) {
114
127
  }
115
128
  if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), require_message.text(", ...")];
116
129
  }
117
- const choicesDisplay = require_message.formatMessage(truncatedTerms, {
130
+ let choicesStartWidth;
131
+ if (descColumnWidth != null) {
132
+ const lastW = lastLineVisibleLength(description);
133
+ const prefixLabelLen = prefix.length + label.length;
134
+ if (lastW + prefixLabelLen >= descColumnWidth) {
135
+ description += "\n";
136
+ choicesStartWidth = prefixLabelLen;
137
+ } else choicesStartWidth = lastW + prefixLabelLen;
138
+ }
139
+ const choicesFormatOptions = {
118
140
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
119
- quotes: false
120
- });
141
+ quotes: false,
142
+ maxWidth: descColumnWidth,
143
+ startWidth: choicesStartWidth
144
+ };
145
+ const choicesDisplay = require_message.formatMessage(truncatedTerms, choicesFormatOptions);
121
146
  const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
122
147
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
123
148
  description += formattedChoices;
@@ -174,12 +199,17 @@ function formatDocPage(programName, page, options = {}) {
174
199
  function indentLines(text$1, indent) {
175
200
  return text$1.split("\n").join("\n" + " ".repeat(indent));
176
201
  }
202
+ const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
177
203
  function ansiAwareRightPad(text$1, length, char = " ") {
178
- const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
179
204
  const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
180
205
  if (strippedText.length >= length) return text$1;
181
206
  return text$1 + char.repeat(length - strippedText.length);
182
207
  }
208
+ function lastLineVisibleLength(text$1) {
209
+ const lastNewline = text$1.lastIndexOf("\n");
210
+ const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
211
+ return lastLine.replace(ansiEscapeCodeRegex, "").length;
212
+ }
183
213
 
184
214
  //#endregion
185
215
  exports.formatDocPage = formatDocPage;
package/dist/doc.js CHANGED
@@ -78,18 +78,31 @@ function formatDocPage(programName, page, options = {}) {
78
78
  optionsSeparator: ", ",
79
79
  maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent
80
80
  });
81
+ const descColumnWidth = options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2;
81
82
  let description = entry.description == null ? "" : formatMessage(entry.description, {
82
83
  colors: options.colors,
83
84
  quotes: !options.colors,
84
- maxWidth: options.maxWidth == null ? void 0 : options.maxWidth - termIndent - termWidth - 2
85
+ maxWidth: descColumnWidth
85
86
  });
86
87
  if (options.showDefault && entry.default != null) {
87
88
  const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
88
89
  const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
89
- const defaultText = `${prefix}${formatMessage(entry.default, {
90
+ let defaultStartWidth;
91
+ if (descColumnWidth != null) {
92
+ const lastW = lastLineVisibleLength(description);
93
+ if (lastW + prefix.length >= descColumnWidth) {
94
+ description += "\n";
95
+ defaultStartWidth = prefix.length;
96
+ } else defaultStartWidth = lastW + prefix.length;
97
+ }
98
+ const defaultFormatOptions = {
90
99
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
91
- quotes: !options.colors
92
- })}${suffix}`;
100
+ quotes: !options.colors,
101
+ maxWidth: descColumnWidth,
102
+ startWidth: defaultStartWidth
103
+ };
104
+ const defaultContent = formatMessage(entry.default, defaultFormatOptions);
105
+ const defaultText = `${prefix}${defaultContent}${suffix}`;
93
106
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
94
107
  description += formattedDefault;
95
108
  }
@@ -114,10 +127,22 @@ function formatDocPage(programName, page, options = {}) {
114
127
  }
115
128
  if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), text(", ...")];
116
129
  }
117
- const choicesDisplay = formatMessage(truncatedTerms, {
130
+ let choicesStartWidth;
131
+ if (descColumnWidth != null) {
132
+ const lastW = lastLineVisibleLength(description);
133
+ const prefixLabelLen = prefix.length + label.length;
134
+ if (lastW + prefixLabelLen >= descColumnWidth) {
135
+ description += "\n";
136
+ choicesStartWidth = prefixLabelLen;
137
+ } else choicesStartWidth = lastW + prefixLabelLen;
138
+ }
139
+ const choicesFormatOptions = {
118
140
  colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
119
- quotes: false
120
- });
141
+ quotes: false,
142
+ maxWidth: descColumnWidth,
143
+ startWidth: choicesStartWidth
144
+ };
145
+ const choicesDisplay = formatMessage(truncatedTerms, choicesFormatOptions);
121
146
  const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
122
147
  const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
123
148
  description += formattedChoices;
@@ -174,12 +199,17 @@ function formatDocPage(programName, page, options = {}) {
174
199
  function indentLines(text$1, indent) {
175
200
  return text$1.split("\n").join("\n" + " ".repeat(indent));
176
201
  }
202
+ const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
177
203
  function ansiAwareRightPad(text$1, length, char = " ") {
178
- const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
179
204
  const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
180
205
  if (strippedText.length >= length) return text$1;
181
206
  return text$1 + char.repeat(length - strippedText.length);
182
207
  }
208
+ function lastLineVisibleLength(text$1) {
209
+ const lastNewline = text$1.lastIndexOf("\n");
210
+ const lastLine = lastNewline === -1 ? text$1 : text$1.slice(lastNewline + 1);
211
+ return lastLine.replace(ansiEscapeCodeRegex, "").length;
212
+ }
183
213
 
184
214
  //#endregion
185
215
  export { formatDocPage };
package/dist/message.cjs CHANGED
@@ -237,14 +237,6 @@ function valueSet(values$1, options) {
237
237
  });
238
238
  return result;
239
239
  }
240
- /**
241
- * Formats a {@link Message} into a human-readable string for
242
- * the terminal.
243
- * @param msg The message to format, which is an array of
244
- * {@link MessageTerm} objects.
245
- * @param options Optional formatting options to customize the output.
246
- * @returns A formatted string representation of the message.
247
- */
248
240
  function formatMessage(msg, options = {}) {
249
241
  const colorConfig = options.colors ?? false;
250
242
  const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
@@ -373,7 +365,7 @@ function formatMessage(msg, options = {}) {
373
365
  }
374
366
  }
375
367
  let output = "";
376
- let totalWidth = 0;
368
+ let totalWidth = options.startWidth ?? 0;
377
369
  for (const { text: text$1, width } of stream()) {
378
370
  if (width === -1) {
379
371
  output += text$1;
package/dist/message.js CHANGED
@@ -236,14 +236,6 @@ function valueSet(values$1, options) {
236
236
  });
237
237
  return result;
238
238
  }
239
- /**
240
- * Formats a {@link Message} into a human-readable string for
241
- * the terminal.
242
- * @param msg The message to format, which is an array of
243
- * {@link MessageTerm} objects.
244
- * @param options Optional formatting options to customize the output.
245
- * @returns A formatted string representation of the message.
246
- */
247
239
  function formatMessage(msg, options = {}) {
248
240
  const colorConfig = options.colors ?? false;
249
241
  const useColors = typeof colorConfig === "boolean" ? colorConfig : true;
@@ -372,7 +364,7 @@ function formatMessage(msg, options = {}) {
372
364
  }
373
365
  }
374
366
  let output = "";
375
- let totalWidth = 0;
367
+ let totalWidth = options.startWidth ?? 0;
376
368
  for (const { text: text$1, width } of stream()) {
377
369
  if (width === -1) {
378
370
  output += text$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.4",
3
+ "version": "0.10.5-dev.417+90e0f90a",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",