@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,13 @@
1
+
2
+ //#region src/terminal-separators.ts
3
+ /**
4
+ * Text fragments that only separate the items around them, such as the
5
+ * spaces the default `values` formatter puts between values. When message
6
+ * wrapping moves such a fragment to the start of a new line, its leading
7
+ * whitespace may be dropped.
8
+ * @internal
9
+ */
10
+ const wrapTrimmableFragments = /* @__PURE__ */ new WeakSet();
11
+
12
+ //#endregion
13
+ exports.wrapTrimmableFragments = wrapTrimmableFragments;
@@ -0,0 +1,12 @@
1
+ //#region src/terminal-separators.ts
2
+ /**
3
+ * Text fragments that only separate the items around them, such as the
4
+ * spaces the default `values` formatter puts between values. When message
5
+ * wrapping moves such a fragment to the start of a new line, its leading
6
+ * whitespace may be dropped.
7
+ * @internal
8
+ */
9
+ const wrapTrimmableFragments = /* @__PURE__ */ new WeakSet();
10
+
11
+ //#endregion
12
+ export { wrapTrimmableFragments };
package/dist/terminal.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const require_terminal_separators = require('./terminal-separators.cjs');
1
2
 
2
3
  //#region src/terminal.ts
3
4
  const plain = (text) => ({
@@ -9,6 +10,8 @@ const styled = (text, style) => ({
9
10
  style,
10
11
  children: [plain(text)]
11
12
  });
13
+ const valuesSeparator = plain(" ");
14
+ require_terminal_separators.wrapTrimmableFragments.add(valuesSeparator);
12
15
  /**
13
16
  * Optique's built-in terminal theme, with every formatter available for delegation.
14
17
  * @since 1.3.0
@@ -34,7 +37,7 @@ const defaultTerminalTheme = {
34
37
  value: (_term, ctx) => ctx.usage === "literal" ? plain(ctx.text) : styled(ctx.text, { foreground: "green" }),
35
38
  values: (term, ctx) => ({
36
39
  type: "concat",
37
- children: term.values.flatMap((value, i) => [...i === 0 ? [] : [plain(" ")], ctx.format({
40
+ children: term.values.flatMap((value, i) => [...i === 0 ? [] : [valuesSeparator], ctx.format({
38
41
  type: "value",
39
42
  value
40
43
  })])
package/dist/terminal.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { wrapTrimmableFragments } from "./terminal-separators.js";
2
+
1
3
  //#region src/terminal.ts
2
4
  const plain = (text) => ({
3
5
  type: "text",
@@ -8,6 +10,8 @@ const styled = (text, style) => ({
8
10
  style,
9
11
  children: [plain(text)]
10
12
  });
13
+ const valuesSeparator = plain(" ");
14
+ wrapTrimmableFragments.add(valuesSeparator);
11
15
  /**
12
16
  * Optique's built-in terminal theme, with every formatter available for delegation.
13
17
  * @since 1.3.0
@@ -33,7 +37,7 @@ const defaultTerminalTheme = {
33
37
  value: (_term, ctx) => ctx.usage === "literal" ? plain(ctx.text) : styled(ctx.text, { foreground: "green" }),
34
38
  values: (term, ctx) => ({
35
39
  type: "concat",
36
- children: term.values.flatMap((value, i) => [...i === 0 ? [] : [plain(" ")], ctx.format({
40
+ children: term.values.flatMap((value, i) => [...i === 0 ? [] : [valuesSeparator], ctx.format({
37
41
  type: "value",
38
42
  value
39
43
  })])
@@ -51,6 +51,18 @@ function placeText(text, cursor, maxWidth, trailingRoom = 0) {
51
51
  }
52
52
  };
53
53
  }
54
+ const leadingSpacePattern = /^((?:\x1B(?:\[[0-9;:]*[@-~]|\][^\x1B\x07]*(?:\x1B\\|\x07)))*)[^\S\n]+/;
55
+ /**
56
+ * Removes the whitespace that begins a text's first line, keeping any
57
+ * escape sequences before it. Used when layout moves text that starts with
58
+ * a separating space to a fresh line.
59
+ * @param text Rendered text, possibly containing ANSI styles or OSC links.
60
+ * @returns The text without its leading whitespace.
61
+ * @internal
62
+ */
63
+ function trimLeadingSpace(text) {
64
+ return text.replace(leadingSpacePattern, "$1");
65
+ }
54
66
  /**
55
67
  * Measures an annotation's fixed text without invoking theme callbacks.
56
68
  * @param prefix The already joined prefix and optional label.
@@ -84,4 +96,5 @@ function spaceAfterLabel(label) {
84
96
  exports.measureAnnotation = measureAnnotation;
85
97
  exports.measureText = measureText;
86
98
  exports.placeText = placeText;
87
- exports.spaceAfterLabel = spaceAfterLabel;
99
+ exports.spaceAfterLabel = spaceAfterLabel;
100
+ exports.trimLeadingSpace = trimLeadingSpace;
@@ -41,7 +41,14 @@ declare function placeText(text: string, cursor: TextCursor, maxWidth?: number,
41
41
  readonly text: string;
42
42
  readonly cursor: TextCursor;
43
43
  };
44
- /** Fixed annotation geometry shared by preflight and placement. @internal */
44
+ /**
45
+ * Removes the whitespace that begins a text's first line, keeping any
46
+ * escape sequences before it. Used when layout moves text that starts with
47
+ * a separating space to a fresh line.
48
+ * @param text Rendered text, possibly containing ANSI styles or OSC links.
49
+ * @returns The text without its leading whitespace.
50
+ * @internal
51
+ */
45
52
 
46
53
  /**
47
54
  * Adds a separating space only when a label occupies its final physical line.
@@ -41,7 +41,14 @@ declare function placeText(text: string, cursor: TextCursor, maxWidth?: number,
41
41
  readonly text: string;
42
42
  readonly cursor: TextCursor;
43
43
  };
44
- /** Fixed annotation geometry shared by preflight and placement. @internal */
44
+ /**
45
+ * Removes the whitespace that begins a text's first line, keeping any
46
+ * escape sequences before it. Used when layout moves text that starts with
47
+ * a separating space to a fresh line.
48
+ * @param text Rendered text, possibly containing ANSI styles or OSC links.
49
+ * @returns The text without its leading whitespace.
50
+ * @internal
51
+ */
45
52
 
46
53
  /**
47
54
  * Adds a separating space only when a label occupies its final physical line.
@@ -51,6 +51,18 @@ function placeText(text, cursor, maxWidth, trailingRoom = 0) {
51
51
  }
52
52
  };
53
53
  }
54
+ const leadingSpacePattern = /^((?:\x1B(?:\[[0-9;:]*[@-~]|\][^\x1B\x07]*(?:\x1B\\|\x07)))*)[^\S\n]+/;
55
+ /**
56
+ * Removes the whitespace that begins a text's first line, keeping any
57
+ * escape sequences before it. Used when layout moves text that starts with
58
+ * a separating space to a fresh line.
59
+ * @param text Rendered text, possibly containing ANSI styles or OSC links.
60
+ * @returns The text without its leading whitespace.
61
+ * @internal
62
+ */
63
+ function trimLeadingSpace(text) {
64
+ return text.replace(leadingSpacePattern, "$1");
65
+ }
54
66
  /**
55
67
  * Measures an annotation's fixed text without invoking theme callbacks.
56
68
  * @param prefix The already joined prefix and optional label.
@@ -81,4 +93,4 @@ function spaceAfterLabel(label) {
81
93
  }
82
94
 
83
95
  //#endregion
84
- export { measureAnnotation, measureText, placeText, spaceAfterLabel };
96
+ export { measureAnnotation, measureText, placeText, spaceAfterLabel, trimLeadingSpace };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "sideEffects": false,
239
239
  "devDependencies": {
240
- "@optique/env": "1.3.2",
240
+ "@optique/env": "1.3.4",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",