gsd-pi 2.34.0-dev.bbb5216 → 2.34.0-dev.ed0bfbf
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/resources/extensions/mcp-client/index.js +2 -1
- package/package.json +1 -1
- package/packages/native/dist/native.d.ts +0 -2
- package/packages/native/dist/native.js +0 -2
- package/packages/native/src/native.ts +0 -3
- package/packages/pi-agent-core/dist/proxy.d.ts +1 -25
- package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
- package/packages/pi-agent-core/dist/proxy.js +1 -1
- package/packages/pi-agent-core/dist/proxy.js.map +1 -1
- package/packages/pi-agent-core/src/proxy.ts +1 -1
- package/packages/pi-ai/dist/api-registry.d.ts +0 -2
- package/packages/pi-ai/dist/api-registry.d.ts.map +1 -1
- package/packages/pi-ai/dist/api-registry.js +0 -10
- package/packages/pi-ai/dist/api-registry.js.map +1 -1
- package/packages/pi-ai/dist/providers/anthropic.d.ts +0 -8
- package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/anthropic.js +1 -1
- package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
- package/packages/pi-ai/dist/providers/github-copilot-headers.d.ts +0 -1
- package/packages/pi-ai/dist/providers/github-copilot-headers.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/github-copilot-headers.js +1 -1
- package/packages/pi-ai/dist/providers/github-copilot-headers.js.map +1 -1
- package/packages/pi-ai/dist/providers/google-gemini-cli.d.ts +1 -43
- package/packages/pi-ai/dist/providers/google-gemini-cli.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/google-gemini-cli.js +2 -2
- package/packages/pi-ai/dist/providers/google-gemini-cli.js.map +1 -1
- package/packages/pi-ai/dist/providers/google-shared.d.ts +0 -4
- package/packages/pi-ai/dist/providers/google-shared.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/google-shared.js +1 -1
- package/packages/pi-ai/dist/providers/google-shared.js.map +1 -1
- package/packages/pi-ai/dist/providers/register-builtins.d.ts +0 -1
- package/packages/pi-ai/dist/providers/register-builtins.d.ts.map +1 -1
- package/packages/pi-ai/dist/providers/register-builtins.js +1 -1
- package/packages/pi-ai/dist/providers/register-builtins.js.map +1 -1
- package/packages/pi-ai/dist/utils/event-stream.d.ts +0 -2
- package/packages/pi-ai/dist/utils/event-stream.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/event-stream.js +0 -4
- package/packages/pi-ai/dist/utils/event-stream.js.map +1 -1
- package/packages/pi-ai/dist/utils/overflow.d.ts +0 -4
- package/packages/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/overflow.js +0 -6
- package/packages/pi-ai/dist/utils/overflow.js.map +1 -1
- package/packages/pi-ai/dist/utils/validation.d.ts +0 -8
- package/packages/pi-ai/dist/utils/validation.d.ts.map +1 -1
- package/packages/pi-ai/dist/utils/validation.js +0 -14
- package/packages/pi-ai/dist/utils/validation.js.map +1 -1
- package/packages/pi-ai/src/api-registry.ts +0 -12
- package/packages/pi-ai/src/providers/anthropic.ts +1 -1
- package/packages/pi-ai/src/providers/github-copilot-headers.ts +1 -1
- package/packages/pi-ai/src/providers/google-gemini-cli.ts +2 -2
- package/packages/pi-ai/src/providers/google-shared.ts +1 -1
- package/packages/pi-ai/src/providers/register-builtins.ts +1 -1
- package/packages/pi-ai/src/utils/event-stream.ts +0 -5
- package/packages/pi-ai/src/utils/overflow.ts +1 -8
- package/packages/pi-ai/src/utils/validation.ts +0 -15
- package/packages/pi-coding-agent/dist/config.d.ts +0 -9
- package/packages/pi-coding-agent/dist/config.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/config.js +4 -8
- package/packages/pi-coding-agent/dist/config.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.d.ts +0 -4
- package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.js +1 -1
- package/packages/pi-coding-agent/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +0 -5
- package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/runner.js +0 -13
- package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts +0 -8
- package/packages/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/keybindings.js +2 -2
- package/packages/pi-coding-agent/dist/core/keybindings.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.d.ts +0 -17
- package/packages/pi-coding-agent/dist/core/lsp/client.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/client.js +3 -62
- package/packages/pi-coding-agent/dist/core/lsp/client.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts +0 -2
- package/packages/pi-coding-agent/dist/core/lsp/config.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/config.js +0 -7
- package/packages/pi-coding-agent/dist/core/lsp/config.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/edits.d.ts +0 -5
- package/packages/pi-coding-agent/dist/core/lsp/edits.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/edits.js +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/edits.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts +0 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts +1 -6
- package/packages/pi-coding-agent/dist/core/lsp/utils.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/lsp/utils.js +1 -28
- package/packages/pi-coding-agent/dist/core/lsp/utils.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/messages.d.ts +0 -8
- package/packages/pi-coding-agent/dist/core/messages.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/messages.js +5 -5
- package/packages/pi-coding-agent/dist/core/messages.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts +0 -3
- package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-registry.js +1 -3
- package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.d.ts +1 -26
- package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/model-resolver.js +3 -59
- package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/prompt-templates.d.ts +0 -17
- package/packages/pi-coding-agent/dist/core/prompt-templates.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/prompt-templates.js +2 -2
- package/packages/pi-coding-agent/dist/core/prompt-templates.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts +0 -4
- package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/session-manager.js +2 -4
- package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +0 -12
- package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/settings-manager.js +2 -2
- package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
- package/packages/pi-coding-agent/dist/migrations.d.ts +0 -16
- package/packages/pi-coding-agent/dist/migrations.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/migrations.js +2 -2
- package/packages/pi-coding-agent/dist/migrations.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts +0 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js +2 -2
- package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -24
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +50 -512
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts +71 -0
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +514 -0
- package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts +0 -4
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js +0 -7
- package/packages/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
- package/packages/pi-coding-agent/dist/utils/changelog.d.ts +0 -4
- package/packages/pi-coding-agent/dist/utils/changelog.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/utils/changelog.js +1 -1
- package/packages/pi-coding-agent/dist/utils/changelog.js.map +1 -1
- package/packages/pi-coding-agent/dist/utils/clipboard-image.d.ts +0 -1
- package/packages/pi-coding-agent/dist/utils/clipboard-image.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/utils/clipboard-image.js +1 -1
- package/packages/pi-coding-agent/dist/utils/clipboard-image.js.map +1 -1
- package/packages/pi-coding-agent/dist/utils/photon.d.ts +0 -19
- package/packages/pi-coding-agent/dist/utils/photon.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/utils/photon.js +1 -120
- package/packages/pi-coding-agent/dist/utils/photon.js.map +1 -1
- package/packages/pi-coding-agent/dist/utils/tools-manager.d.ts +0 -1
- package/packages/pi-coding-agent/dist/utils/tools-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/utils/tools-manager.js +1 -1
- package/packages/pi-coding-agent/dist/utils/tools-manager.js.map +1 -1
- package/packages/pi-coding-agent/src/config.ts +5 -10
- package/packages/pi-coding-agent/src/core/export-html/ansi-to-html.ts +1 -1
- package/packages/pi-coding-agent/src/core/extensions/runner.ts +0 -13
- package/packages/pi-coding-agent/src/core/keybindings.ts +2 -2
- package/packages/pi-coding-agent/src/core/lsp/client.ts +3 -73
- package/packages/pi-coding-agent/src/core/lsp/config.ts +0 -11
- package/packages/pi-coding-agent/src/core/lsp/edits.ts +1 -1
- package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +1 -1
- package/packages/pi-coding-agent/src/core/lsp/utils.ts +1 -33
- package/packages/pi-coding-agent/src/core/messages.ts +5 -5
- package/packages/pi-coding-agent/src/core/model-registry.ts +0 -2
- package/packages/pi-coding-agent/src/core/model-resolver.ts +3 -77
- package/packages/pi-coding-agent/src/core/prompt-templates.ts +2 -2
- package/packages/pi-coding-agent/src/core/session-manager.ts +2 -4
- package/packages/pi-coding-agent/src/core/settings-manager.ts +2 -2
- package/packages/pi-coding-agent/src/migrations.ts +2 -2
- package/packages/pi-coding-agent/src/modes/interactive/components/session-selector-search.ts +2 -2
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +50 -561
- package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +653 -0
- package/packages/pi-coding-agent/src/modes/interactive/theme/theme.ts +0 -8
- package/packages/pi-coding-agent/src/utils/changelog.ts +1 -1
- package/packages/pi-coding-agent/src/utils/clipboard-image.ts +1 -1
- package/packages/pi-coding-agent/src/utils/photon.ts +0 -137
- package/packages/pi-coding-agent/src/utils/tools-manager.ts +1 -1
- package/packages/pi-tui/dist/components/editor.d.ts +0 -10
- package/packages/pi-tui/dist/components/editor.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/editor.js +1 -1
- package/packages/pi-tui/dist/components/editor.js.map +1 -1
- package/packages/pi-tui/dist/overlay-layout.d.ts +55 -0
- package/packages/pi-tui/dist/overlay-layout.d.ts.map +1 -0
- package/packages/pi-tui/dist/overlay-layout.js +288 -0
- package/packages/pi-tui/dist/overlay-layout.js.map +1 -0
- package/packages/pi-tui/dist/tui.d.ts +0 -22
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +6 -272
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/dist/utils.d.ts +0 -7
- package/packages/pi-tui/dist/utils.d.ts.map +1 -1
- package/packages/pi-tui/dist/utils.js +0 -44
- package/packages/pi-tui/dist/utils.js.map +1 -1
- package/packages/pi-tui/src/components/editor.ts +1 -1
- package/packages/pi-tui/src/overlay-layout.ts +372 -0
- package/packages/pi-tui/src/tui.ts +11 -312
- package/packages/pi-tui/src/utils.ts +0 -43
- package/pkg/dist/core/export-html/ansi-to-html.d.ts +0 -4
- package/pkg/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/pkg/dist/core/export-html/ansi-to-html.js +1 -1
- package/pkg/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/pkg/dist/modes/interactive/theme/theme.d.ts +0 -4
- package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/pkg/dist/modes/interactive/theme/theme.js +0 -7
- package/pkg/dist/modes/interactive/theme/theme.js.map +1 -1
- package/src/resources/extensions/mcp-client/index.ts +2 -1
|
@@ -10,13 +10,6 @@ export declare function isWhitespaceChar(char: string): boolean;
|
|
|
10
10
|
* Check if a character is punctuation.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isPunctuationChar(char: string): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Extract ANSI escape sequences from a string at the given position.
|
|
15
|
-
*/
|
|
16
|
-
export declare function extractAnsiCode(str: string, pos: number): {
|
|
17
|
-
code: string;
|
|
18
|
-
length: number;
|
|
19
|
-
} | null;
|
|
20
13
|
/**
|
|
21
14
|
* Calculate the visible width of a string in terminal columns.
|
|
22
15
|
* Delegates to the native Rust implementation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAAC,SAAS,CAE7C;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAAC,SAAS,CAE7C;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD;AAMD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEtE;AAaD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,QAAQ,GAAE,MAAc,EACxB,GAAG,GAAE,OAAe,GAClB,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAQ,GAAG,MAAM,CAEpG;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,UAAQ,GACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAEjC;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,WAAW,UAAQ,GACjB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAE5E;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAOzG"}
|
|
@@ -20,50 +20,6 @@ export function isWhitespaceChar(char) {
|
|
|
20
20
|
export function isPunctuationChar(char) {
|
|
21
21
|
return PUNCTUATION_REGEX.test(char);
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Extract ANSI escape sequences from a string at the given position.
|
|
25
|
-
*/
|
|
26
|
-
export function extractAnsiCode(str, pos) {
|
|
27
|
-
if (pos >= str.length || str[pos] !== "\x1b")
|
|
28
|
-
return null;
|
|
29
|
-
const next = str[pos + 1];
|
|
30
|
-
// CSI sequence: ESC [ ... m/G/K/H/J
|
|
31
|
-
if (next === "[") {
|
|
32
|
-
let j = pos + 2;
|
|
33
|
-
while (j < str.length && !/[mGKHJ]/.test(str[j]))
|
|
34
|
-
j++;
|
|
35
|
-
if (j < str.length)
|
|
36
|
-
return { code: str.substring(pos, j + 1), length: j + 1 - pos };
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
// OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \)
|
|
40
|
-
// Used for hyperlinks (OSC 8), window titles, etc.
|
|
41
|
-
if (next === "]") {
|
|
42
|
-
let j = pos + 2;
|
|
43
|
-
while (j < str.length) {
|
|
44
|
-
if (str[j] === "\x07")
|
|
45
|
-
return { code: str.substring(pos, j + 1), length: j + 1 - pos };
|
|
46
|
-
if (str[j] === "\x1b" && str[j + 1] === "\\")
|
|
47
|
-
return { code: str.substring(pos, j + 2), length: j + 2 - pos };
|
|
48
|
-
j++;
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
// APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \)
|
|
53
|
-
// Used for cursor marker and application-specific commands
|
|
54
|
-
if (next === "_") {
|
|
55
|
-
let j = pos + 2;
|
|
56
|
-
while (j < str.length) {
|
|
57
|
-
if (str[j] === "\x07")
|
|
58
|
-
return { code: str.substring(pos, j + 1), length: j + 1 - pos };
|
|
59
|
-
if (str[j] === "\x1b" && str[j + 1] === "\\")
|
|
60
|
-
return { code: str.substring(pos, j + 2), length: j + 2 - pos };
|
|
61
|
-
j++;
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
23
|
// ---------------------------------------------------------------------------
|
|
68
24
|
// Native text module wrappers
|
|
69
25
|
// ---------------------------------------------------------------------------
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,kBAAkB,EAClC,gBAAgB,IAAI,sBAAsB,EAC1C,eAAe,IAAI,qBAAqB,EACxC,cAAc,IAAI,oBAAoB,EACtC,eAAe,IAAI,qBAAqB,EACxC,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B,uCAAu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AY,EACZ,QAAgB,EAChB,MAAc,EACd,MAAM,GAAG,KAAK;IAEd,OAAO,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,SAAiB,EACjB,UAAkB,EAClB,QAAgB,EAChB,WAAW,GAAG,KAAK;IAEnB,OAAO,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa,EAAE,IAA8B;IAChG,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAE1C,MAAM,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC;IACnC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n\tvisibleWidth as nativeVisibleWidth,\n\twrapTextWithAnsi as nativeWrapTextWithAnsi,\n\ttruncateToWidth as nativeTruncateToWidth,\n\tsliceWithWidth as nativeSliceWithWidth,\n\textractSegments as nativeExtractSegments,\n\tEllipsisKind,\n} from \"@gsd/native/text\";\n\n// Grapheme segmenter (shared instance)\nconst segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/**\n * Get the shared grapheme segmenter instance.\n */\nexport function getSegmenter(): Intl.Segmenter {\n\treturn segmenter;\n}\n\nconst PUNCTUATION_REGEX = /[(){}[\\]<>.,;:'\"!?+\\-=*/\\\\|&%^$#@~`]/;\n\n/**\n * Check if a character is whitespace.\n */\nexport function isWhitespaceChar(char: string): boolean {\n\treturn /\\s/.test(char);\n}\n\n/**\n * Check if a character is punctuation.\n */\nexport function isPunctuationChar(char: string): boolean {\n\treturn PUNCTUATION_REGEX.test(char);\n}\n\n/**\n * Extract ANSI escape sequences from a string at the given position.\n */\nexport function extractAnsiCode(str: string, pos: number): { code: string; length: number } | null {\n\tif (pos >= str.length || str[pos] !== \"\\x1b\") return null;\n\n\tconst next = str[pos + 1];\n\n\t// CSI sequence: ESC [ ... m/G/K/H/J\n\tif (next === \"[\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length && !/[mGKHJ]/.test(str[j]!)) j++;\n\t\tif (j < str.length) return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\treturn null;\n\t}\n\n\t// OSC sequence: ESC ] ... BEL or ESC ] ... ST (ESC \\)\n\t// Used for hyperlinks (OSC 8), window titles, etc.\n\tif (next === \"]\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\t// APC sequence: ESC _ ... BEL or ESC _ ... ST (ESC \\)\n\t// Used for cursor marker and application-specific commands\n\tif (next === \"_\") {\n\t\tlet j = pos + 2;\n\t\twhile (j < str.length) {\n\t\t\tif (str[j] === \"\\x07\") return { code: str.substring(pos, j + 1), length: j + 1 - pos };\n\t\t\tif (str[j] === \"\\x1b\" && str[j + 1] === \"\\\\\") return { code: str.substring(pos, j + 2), length: j + 2 - pos };\n\t\t\tj++;\n\t\t}\n\t\treturn null;\n\t}\n\n\treturn null;\n}\n\n// ---------------------------------------------------------------------------\n// Native text module wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * Delegates to the native Rust implementation.\n */\nexport function visibleWidth(str: string): number {\n\treturn nativeVisibleWidth(str);\n}\n\n/**\n * Wrap text with ANSI codes preserved.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to wrap (may contain ANSI codes and newlines)\n * @param width - Maximum visible width per line\n * @returns Array of wrapped lines (NOT padded to width)\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\treturn nativeWrapTextWithAnsi(text, width);\n}\n\n/**\n * Map an ellipsis string to the native EllipsisKind enum value.\n */\nfunction ellipsisStringToKind(ellipsis: string): number {\n\tif (ellipsis === \"\\u2026\") return EllipsisKind.Unicode;\n\tif (ellipsis === \"...\" || ellipsis === undefined) return EllipsisKind.Ascii;\n\tif (ellipsis === \"\") return EllipsisKind.None;\n\t// Default: \"...\" maps to Ascii\n\treturn EllipsisKind.Ascii;\n}\n\n/**\n * Truncate text to fit within a maximum visible width, adding ellipsis if needed.\n * Optionally pad with spaces to reach exactly maxWidth.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to truncate (may contain ANSI codes)\n * @param maxWidth - Maximum visible width\n * @param ellipsis - Ellipsis string to append when truncating (default: \"...\")\n * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)\n * @returns Truncated text, optionally padded to exactly maxWidth\n */\nexport function truncateToWidth(\n\ttext: string,\n\tmaxWidth: number,\n\tellipsis: string = \"...\",\n\tpad: boolean = false,\n): string {\n\treturn nativeTruncateToWidth(text, maxWidth, ellipsisStringToKind(ellipsis), pad);\n}\n\n/**\n * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.\n * @param strict - If true, exclude wide chars at boundary that would extend past the range\n */\nexport function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {\n\treturn sliceWithWidth(line, startCol, length, strict).text;\n}\n\n/** Like sliceByColumn but also returns the actual visible width of the result. */\nexport function sliceWithWidth(\n\tline: string,\n\tstartCol: number,\n\tlength: number,\n\tstrict = false,\n): { text: string; width: number } {\n\treturn nativeSliceWithWidth(line, startCol, length, strict);\n}\n\n/**\n * Extract \"before\" and \"after\" segments from a line in a single pass.\n * Delegates to the native Rust implementation.\n */\nexport function extractSegments(\n\tline: string,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterLen: number,\n\tstrictAfter = false,\n): { before: string; beforeWidth: number; after: string; afterWidth: number } {\n\treturn nativeExtractSegments(line, beforeEnd, afterStart, afterLen, strictAfter);\n}\n\n/**\n * Apply background color to a line, padding to full width.\n *\n * @param line - Line of text (may contain ANSI codes)\n * @param width - Total width to pad to\n * @param bgFn - Background color function\n * @returns Line with background applied and padded to width\n */\nexport function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {\n\tconst visibleLen = visibleWidth(line);\n\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\tconst padding = \" \".repeat(paddingNeeded);\n\n\tconst withPadding = line + padding;\n\treturn bgFn(withPadding);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,YAAY,IAAI,kBAAkB,EAClC,gBAAgB,IAAI,sBAAsB,EAC1C,eAAe,IAAI,qBAAqB,EACxC,cAAc,IAAI,oBAAoB,EACtC,eAAe,IAAI,qBAAqB,EACxC,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B,uCAAuC;AACvC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC;AAE7E;;GAEG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,iBAAiB,GAAG,sCAAsC,CAAC;AAEjE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC7C,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrC,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M,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAY,EACZ,SAAiB,EACjB,UAAkB,EAClB,QAAgB,EAChB,WAAW,GAAG,KAAK;IAEnB,OAAO,qBAAqB,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAClF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,KAAa,EAAE,IAA8B;IAChG,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAE1C,MAAM,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC;IACnC,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import {\n\tvisibleWidth as nativeVisibleWidth,\n\twrapTextWithAnsi as nativeWrapTextWithAnsi,\n\ttruncateToWidth as nativeTruncateToWidth,\n\tsliceWithWidth as nativeSliceWithWidth,\n\textractSegments as nativeExtractSegments,\n\tEllipsisKind,\n} from \"@gsd/native/text\";\n\n// Grapheme segmenter (shared instance)\nconst segmenter = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/**\n * Get the shared grapheme segmenter instance.\n */\nexport function getSegmenter(): Intl.Segmenter {\n\treturn segmenter;\n}\n\nconst PUNCTUATION_REGEX = /[(){}[\\]<>.,;:'\"!?+\\-=*/\\\\|&%^$#@~`]/;\n\n/**\n * Check if a character is whitespace.\n */\nexport function isWhitespaceChar(char: string): boolean {\n\treturn /\\s/.test(char);\n}\n\n/**\n * Check if a character is punctuation.\n */\nexport function isPunctuationChar(char: string): boolean {\n\treturn PUNCTUATION_REGEX.test(char);\n}\n\n// ---------------------------------------------------------------------------\n// Native text module wrappers\n// ---------------------------------------------------------------------------\n\n/**\n * Calculate the visible width of a string in terminal columns.\n * Delegates to the native Rust implementation.\n */\nexport function visibleWidth(str: string): number {\n\treturn nativeVisibleWidth(str);\n}\n\n/**\n * Wrap text with ANSI codes preserved.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to wrap (may contain ANSI codes and newlines)\n * @param width - Maximum visible width per line\n * @returns Array of wrapped lines (NOT padded to width)\n */\nexport function wrapTextWithAnsi(text: string, width: number): string[] {\n\treturn nativeWrapTextWithAnsi(text, width);\n}\n\n/**\n * Map an ellipsis string to the native EllipsisKind enum value.\n */\nfunction ellipsisStringToKind(ellipsis: string): number {\n\tif (ellipsis === \"\\u2026\") return EllipsisKind.Unicode;\n\tif (ellipsis === \"...\" || ellipsis === undefined) return EllipsisKind.Ascii;\n\tif (ellipsis === \"\") return EllipsisKind.None;\n\t// Default: \"...\" maps to Ascii\n\treturn EllipsisKind.Ascii;\n}\n\n/**\n * Truncate text to fit within a maximum visible width, adding ellipsis if needed.\n * Optionally pad with spaces to reach exactly maxWidth.\n * Delegates to the native Rust implementation.\n *\n * @param text - Text to truncate (may contain ANSI codes)\n * @param maxWidth - Maximum visible width\n * @param ellipsis - Ellipsis string to append when truncating (default: \"...\")\n * @param pad - If true, pad result with spaces to exactly maxWidth (default: false)\n * @returns Truncated text, optionally padded to exactly maxWidth\n */\nexport function truncateToWidth(\n\ttext: string,\n\tmaxWidth: number,\n\tellipsis: string = \"...\",\n\tpad: boolean = false,\n): string {\n\treturn nativeTruncateToWidth(text, maxWidth, ellipsisStringToKind(ellipsis), pad);\n}\n\n/**\n * Extract a range of visible columns from a line. Handles ANSI codes and wide chars.\n * @param strict - If true, exclude wide chars at boundary that would extend past the range\n */\nexport function sliceByColumn(line: string, startCol: number, length: number, strict = false): string {\n\treturn sliceWithWidth(line, startCol, length, strict).text;\n}\n\n/** Like sliceByColumn but also returns the actual visible width of the result. */\nexport function sliceWithWidth(\n\tline: string,\n\tstartCol: number,\n\tlength: number,\n\tstrict = false,\n): { text: string; width: number } {\n\treturn nativeSliceWithWidth(line, startCol, length, strict);\n}\n\n/**\n * Extract \"before\" and \"after\" segments from a line in a single pass.\n * Delegates to the native Rust implementation.\n */\nexport function extractSegments(\n\tline: string,\n\tbeforeEnd: number,\n\tafterStart: number,\n\tafterLen: number,\n\tstrictAfter = false,\n): { before: string; beforeWidth: number; after: string; afterWidth: number } {\n\treturn nativeExtractSegments(line, beforeEnd, afterStart, afterLen, strictAfter);\n}\n\n/**\n * Apply background color to a line, padding to full width.\n *\n * @param line - Line of text (may contain ANSI codes)\n * @param width - Total width to pad to\n * @param bgFn - Background color function\n * @returns Line with background applied and padded to width\n */\nexport function applyBackgroundToLine(line: string, width: number, bgFn: (text: string) => string): string {\n\tconst visibleLen = visibleWidth(line);\n\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\tconst padding = \" \".repeat(paddingNeeded);\n\n\tconst withPadding = line + padding;\n\treturn bgFn(withPadding);\n}\n"]}
|
|
@@ -28,7 +28,7 @@ export interface TextChunk {
|
|
|
28
28
|
* @param maxWidth - Maximum visible width per chunk
|
|
29
29
|
* @returns Array of chunks with text and position information
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
function wordWrapLine(line: string, maxWidth: number): TextChunk[] {
|
|
32
32
|
if (!line || maxWidth <= 0) {
|
|
33
33
|
return [{ text: "", startIndex: 0, endIndex: 0 }];
|
|
34
34
|
}
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overlay layout resolution, compositing, and rendering utilities.
|
|
3
|
+
*
|
|
4
|
+
* Extracted from tui.ts — these are pure functions that compute overlay
|
|
5
|
+
* positions and composite overlay content onto base terminal lines.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { OverlayAnchor, OverlayOptions, SizeValue } from "./tui.js";
|
|
9
|
+
import { extractSegments, sliceByColumn, sliceWithWidth, truncateToWidth, visibleWidth } from "./utils.js";
|
|
10
|
+
import { isImageLine } from "./terminal-image.js";
|
|
11
|
+
import { CURSOR_MARKER } from "./tui.js";
|
|
12
|
+
|
|
13
|
+
// ─── Size parsing ───────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
/** Parse a SizeValue into absolute value given a reference size */
|
|
16
|
+
export function parseSizeValue(value: SizeValue | undefined, referenceSize: number): number | undefined {
|
|
17
|
+
if (value === undefined) return undefined;
|
|
18
|
+
if (typeof value === "number") return value;
|
|
19
|
+
// Parse percentage string like "50%"
|
|
20
|
+
const match = value.match(/^(\d+(?:\.\d+)?)%$/);
|
|
21
|
+
if (match) {
|
|
22
|
+
return Math.floor((referenceSize * parseFloat(match[1])) / 100);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ─── Anchor resolution ──────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export function resolveAnchorRow(
|
|
30
|
+
anchor: OverlayAnchor,
|
|
31
|
+
height: number,
|
|
32
|
+
availHeight: number,
|
|
33
|
+
marginTop: number,
|
|
34
|
+
): number {
|
|
35
|
+
switch (anchor) {
|
|
36
|
+
case "top-left":
|
|
37
|
+
case "top-center":
|
|
38
|
+
case "top-right":
|
|
39
|
+
return marginTop;
|
|
40
|
+
case "bottom-left":
|
|
41
|
+
case "bottom-center":
|
|
42
|
+
case "bottom-right":
|
|
43
|
+
return marginTop + availHeight - height;
|
|
44
|
+
case "left-center":
|
|
45
|
+
case "center":
|
|
46
|
+
case "right-center":
|
|
47
|
+
return marginTop + Math.floor((availHeight - height) / 2);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function resolveAnchorCol(
|
|
52
|
+
anchor: OverlayAnchor,
|
|
53
|
+
width: number,
|
|
54
|
+
availWidth: number,
|
|
55
|
+
marginLeft: number,
|
|
56
|
+
): number {
|
|
57
|
+
switch (anchor) {
|
|
58
|
+
case "top-left":
|
|
59
|
+
case "left-center":
|
|
60
|
+
case "bottom-left":
|
|
61
|
+
return marginLeft;
|
|
62
|
+
case "top-right":
|
|
63
|
+
case "right-center":
|
|
64
|
+
case "bottom-right":
|
|
65
|
+
return marginLeft + availWidth - width;
|
|
66
|
+
case "top-center":
|
|
67
|
+
case "center":
|
|
68
|
+
case "bottom-center":
|
|
69
|
+
return marginLeft + Math.floor((availWidth - width) / 2);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ─── Overlay layout resolution ──────────────────────────────────────────────
|
|
74
|
+
|
|
75
|
+
export interface OverlayLayout {
|
|
76
|
+
width: number;
|
|
77
|
+
row: number;
|
|
78
|
+
col: number;
|
|
79
|
+
maxHeight: number | undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Resolve overlay layout from options.
|
|
84
|
+
* Returns { width, row, col, maxHeight } for rendering.
|
|
85
|
+
*/
|
|
86
|
+
export function resolveOverlayLayout(
|
|
87
|
+
options: OverlayOptions | undefined,
|
|
88
|
+
overlayHeight: number,
|
|
89
|
+
termWidth: number,
|
|
90
|
+
termHeight: number,
|
|
91
|
+
): OverlayLayout {
|
|
92
|
+
const opt = options ?? {};
|
|
93
|
+
|
|
94
|
+
// Parse margin (clamp to non-negative)
|
|
95
|
+
const margin =
|
|
96
|
+
typeof opt.margin === "number"
|
|
97
|
+
? { top: opt.margin, right: opt.margin, bottom: opt.margin, left: opt.margin }
|
|
98
|
+
: (opt.margin ?? {});
|
|
99
|
+
const marginTop = Math.max(0, margin.top ?? 0);
|
|
100
|
+
const marginRight = Math.max(0, margin.right ?? 0);
|
|
101
|
+
const marginBottom = Math.max(0, margin.bottom ?? 0);
|
|
102
|
+
const marginLeft = Math.max(0, margin.left ?? 0);
|
|
103
|
+
|
|
104
|
+
// Available space after margins
|
|
105
|
+
const availWidth = Math.max(1, termWidth - marginLeft - marginRight);
|
|
106
|
+
const availHeight = Math.max(1, termHeight - marginTop - marginBottom);
|
|
107
|
+
|
|
108
|
+
// === Resolve width ===
|
|
109
|
+
let width = parseSizeValue(opt.width, termWidth) ?? Math.min(80, availWidth);
|
|
110
|
+
// Apply minWidth
|
|
111
|
+
if (opt.minWidth !== undefined) {
|
|
112
|
+
width = Math.max(width, opt.minWidth);
|
|
113
|
+
}
|
|
114
|
+
// Clamp to available space
|
|
115
|
+
width = Math.max(1, Math.min(width, availWidth));
|
|
116
|
+
|
|
117
|
+
// === Resolve maxHeight ===
|
|
118
|
+
let maxHeight = parseSizeValue(opt.maxHeight, termHeight);
|
|
119
|
+
// Clamp to available space
|
|
120
|
+
if (maxHeight !== undefined) {
|
|
121
|
+
maxHeight = Math.max(1, Math.min(maxHeight, availHeight));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Effective overlay height (may be clamped by maxHeight)
|
|
125
|
+
const effectiveHeight = maxHeight !== undefined ? Math.min(overlayHeight, maxHeight) : overlayHeight;
|
|
126
|
+
|
|
127
|
+
// === Resolve position ===
|
|
128
|
+
let row: number;
|
|
129
|
+
let col: number;
|
|
130
|
+
|
|
131
|
+
if (opt.row !== undefined) {
|
|
132
|
+
if (typeof opt.row === "string") {
|
|
133
|
+
// Percentage: 0% = top, 100% = bottom (overlay stays within bounds)
|
|
134
|
+
const match = opt.row.match(/^(\d+(?:\.\d+)?)%$/);
|
|
135
|
+
if (match) {
|
|
136
|
+
const maxRow = Math.max(0, availHeight - effectiveHeight);
|
|
137
|
+
const percent = parseFloat(match[1]) / 100;
|
|
138
|
+
row = marginTop + Math.floor(maxRow * percent);
|
|
139
|
+
} else {
|
|
140
|
+
// Invalid format, fall back to center
|
|
141
|
+
row = resolveAnchorRow("center", effectiveHeight, availHeight, marginTop);
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
// Absolute row position
|
|
145
|
+
row = opt.row;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
// Anchor-based (default: center)
|
|
149
|
+
const anchor = opt.anchor ?? "center";
|
|
150
|
+
row = resolveAnchorRow(anchor, effectiveHeight, availHeight, marginTop);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (opt.col !== undefined) {
|
|
154
|
+
if (typeof opt.col === "string") {
|
|
155
|
+
// Percentage: 0% = left, 100% = right (overlay stays within bounds)
|
|
156
|
+
const match = opt.col.match(/^(\d+(?:\.\d+)?)%$/);
|
|
157
|
+
if (match) {
|
|
158
|
+
const maxCol = Math.max(0, availWidth - width);
|
|
159
|
+
const percent = parseFloat(match[1]) / 100;
|
|
160
|
+
col = marginLeft + Math.floor(maxCol * percent);
|
|
161
|
+
} else {
|
|
162
|
+
// Invalid format, fall back to center
|
|
163
|
+
col = resolveAnchorCol("center", width, availWidth, marginLeft);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
// Absolute column position
|
|
167
|
+
col = opt.col;
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
// Anchor-based (default: center)
|
|
171
|
+
const anchor = opt.anchor ?? "center";
|
|
172
|
+
col = resolveAnchorCol(anchor, width, availWidth, marginLeft);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Apply offsets
|
|
176
|
+
if (opt.offsetY !== undefined) row += opt.offsetY;
|
|
177
|
+
if (opt.offsetX !== undefined) col += opt.offsetX;
|
|
178
|
+
|
|
179
|
+
// Clamp to terminal bounds (respecting margins)
|
|
180
|
+
row = Math.max(marginTop, Math.min(row, termHeight - marginBottom - effectiveHeight));
|
|
181
|
+
col = Math.max(marginLeft, Math.min(col, termWidth - marginRight - width));
|
|
182
|
+
|
|
183
|
+
return { width, row, col, maxHeight };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ─── Line compositing ───────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
const SEGMENT_RESET = "\x1b[0m\x1b]8;;\x07";
|
|
189
|
+
|
|
190
|
+
/** Append reset sequences to each non-image line. */
|
|
191
|
+
export function applyLineResets(lines: string[]): string[] {
|
|
192
|
+
for (let i = 0; i < lines.length; i++) {
|
|
193
|
+
const line = lines[i];
|
|
194
|
+
if (!isImageLine(line)) {
|
|
195
|
+
lines[i] = line + SEGMENT_RESET;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return lines;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Splice overlay content into a base line at a specific column. Single-pass optimized. */
|
|
202
|
+
export function compositeLineAt(
|
|
203
|
+
baseLine: string,
|
|
204
|
+
overlayLine: string,
|
|
205
|
+
startCol: number,
|
|
206
|
+
overlayWidth: number,
|
|
207
|
+
totalWidth: number,
|
|
208
|
+
): string {
|
|
209
|
+
if (isImageLine(baseLine)) return baseLine;
|
|
210
|
+
|
|
211
|
+
// Single pass through baseLine extracts both before and after segments
|
|
212
|
+
const afterStart = startCol + overlayWidth;
|
|
213
|
+
const base = extractSegments(baseLine, startCol, afterStart, totalWidth - afterStart, true);
|
|
214
|
+
|
|
215
|
+
// Extract overlay with width tracking (strict=true to exclude wide chars at boundary)
|
|
216
|
+
const overlay = sliceWithWidth(overlayLine, 0, overlayWidth, true);
|
|
217
|
+
|
|
218
|
+
// Pad segments to target widths
|
|
219
|
+
const beforePad = Math.max(0, startCol - base.beforeWidth);
|
|
220
|
+
const overlayPad = Math.max(0, overlayWidth - overlay.width);
|
|
221
|
+
const actualBeforeWidth = Math.max(startCol, base.beforeWidth);
|
|
222
|
+
const actualOverlayWidth = Math.max(overlayWidth, overlay.width);
|
|
223
|
+
const afterTarget = Math.max(0, totalWidth - actualBeforeWidth - actualOverlayWidth);
|
|
224
|
+
const afterPad = Math.max(0, afterTarget - base.afterWidth);
|
|
225
|
+
|
|
226
|
+
// Compose result
|
|
227
|
+
const r = SEGMENT_RESET;
|
|
228
|
+
const result =
|
|
229
|
+
base.before +
|
|
230
|
+
" ".repeat(beforePad) +
|
|
231
|
+
r +
|
|
232
|
+
overlay.text +
|
|
233
|
+
" ".repeat(overlayPad) +
|
|
234
|
+
r +
|
|
235
|
+
base.after +
|
|
236
|
+
" ".repeat(afterPad);
|
|
237
|
+
|
|
238
|
+
// CRITICAL: Always verify and truncate to terminal width.
|
|
239
|
+
// This is the final safeguard against width overflow which would crash the TUI.
|
|
240
|
+
// Width tracking can drift from actual visible width due to:
|
|
241
|
+
// - Complex ANSI/OSC sequences (hyperlinks, colors)
|
|
242
|
+
// - Wide characters at segment boundaries
|
|
243
|
+
// - Edge cases in segment extraction
|
|
244
|
+
const resultWidth = visibleWidth(result);
|
|
245
|
+
if (resultWidth <= totalWidth) {
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
// Truncate with strict=true to ensure we don't exceed totalWidth
|
|
249
|
+
return sliceByColumn(result, 0, totalWidth, true);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ─── Overlay compositing ────────────────────────────────────────────────────
|
|
253
|
+
|
|
254
|
+
export interface OverlayEntry {
|
|
255
|
+
component: { render(width: number): string[]; invalidate?(): void };
|
|
256
|
+
options?: OverlayOptions;
|
|
257
|
+
hidden: boolean;
|
|
258
|
+
focusOrder: number;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Check if an overlay entry is currently visible */
|
|
262
|
+
export function isOverlayVisible(
|
|
263
|
+
entry: OverlayEntry,
|
|
264
|
+
termWidth: number,
|
|
265
|
+
termHeight: number,
|
|
266
|
+
): boolean {
|
|
267
|
+
if (entry.hidden) return false;
|
|
268
|
+
if (entry.options?.visible) {
|
|
269
|
+
return entry.options.visible(termWidth, termHeight);
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Composite all visible overlays into content lines.
|
|
276
|
+
* Sorted by focusOrder (higher = on top).
|
|
277
|
+
*/
|
|
278
|
+
export function compositeOverlays(
|
|
279
|
+
lines: string[],
|
|
280
|
+
overlayStack: OverlayEntry[],
|
|
281
|
+
termWidth: number,
|
|
282
|
+
termHeight: number,
|
|
283
|
+
maxLinesRendered: number,
|
|
284
|
+
): string[] {
|
|
285
|
+
if (overlayStack.length === 0) return lines;
|
|
286
|
+
const result = [...lines];
|
|
287
|
+
|
|
288
|
+
// Pre-render all visible overlays and calculate positions
|
|
289
|
+
const rendered: { overlayLines: string[]; row: number; col: number; w: number }[] = [];
|
|
290
|
+
let minLinesNeeded = result.length;
|
|
291
|
+
|
|
292
|
+
const visibleEntries = overlayStack.filter((e) => isOverlayVisible(e, termWidth, termHeight));
|
|
293
|
+
visibleEntries.sort((a, b) => a.focusOrder - b.focusOrder);
|
|
294
|
+
for (const entry of visibleEntries) {
|
|
295
|
+
const { component, options } = entry;
|
|
296
|
+
|
|
297
|
+
// Get layout with height=0 first to determine width and maxHeight
|
|
298
|
+
// (width and maxHeight don't depend on overlay height)
|
|
299
|
+
const { width, maxHeight } = resolveOverlayLayout(options, 0, termWidth, termHeight);
|
|
300
|
+
|
|
301
|
+
// Render component at calculated width
|
|
302
|
+
let overlayLines = component.render(width);
|
|
303
|
+
|
|
304
|
+
// Apply maxHeight if specified
|
|
305
|
+
if (maxHeight !== undefined && overlayLines.length > maxHeight) {
|
|
306
|
+
overlayLines = overlayLines.slice(0, maxHeight);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Get final row/col with actual overlay height
|
|
310
|
+
const { row, col } = resolveOverlayLayout(options, overlayLines.length, termWidth, termHeight);
|
|
311
|
+
|
|
312
|
+
rendered.push({ overlayLines, row, col, w: width });
|
|
313
|
+
minLinesNeeded = Math.max(minLinesNeeded, row + overlayLines.length);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Ensure result covers the terminal working area to keep overlay positioning stable across resizes.
|
|
317
|
+
// maxLinesRendered can exceed current content length after a shrink; pad to keep viewportStart consistent.
|
|
318
|
+
const workingHeight = Math.max(maxLinesRendered, minLinesNeeded);
|
|
319
|
+
|
|
320
|
+
// Extend result with empty lines if content is too short for overlay placement or working area
|
|
321
|
+
while (result.length < workingHeight) {
|
|
322
|
+
result.push("");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const viewportStart = Math.max(0, workingHeight - termHeight);
|
|
326
|
+
|
|
327
|
+
// Composite each overlay
|
|
328
|
+
for (const { overlayLines, row, col, w } of rendered) {
|
|
329
|
+
for (let i = 0; i < overlayLines.length; i++) {
|
|
330
|
+
const idx = viewportStart + row + i;
|
|
331
|
+
if (idx >= 0 && idx < result.length) {
|
|
332
|
+
// Defensive: truncate overlay line to declared width before compositing
|
|
333
|
+
// (components should already respect width, but this ensures it)
|
|
334
|
+
const truncatedOverlayLine =
|
|
335
|
+
visibleWidth(overlayLines[i]) > w ? sliceByColumn(overlayLines[i], 0, w, true) : overlayLines[i];
|
|
336
|
+
result[idx] = compositeLineAt(result[idx], truncatedOverlayLine, col, w, termWidth);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return result;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// ─── Cursor extraction ──────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Find and extract cursor position from rendered lines.
|
|
348
|
+
* Searches for CURSOR_MARKER, calculates its position, and strips it from the output.
|
|
349
|
+
* Only scans the bottom terminal height lines (visible viewport).
|
|
350
|
+
* @param lines - Rendered lines to search (mutated to strip marker)
|
|
351
|
+
* @param height - Terminal height (visible viewport size)
|
|
352
|
+
* @returns Cursor position { row, col } or null if no marker found
|
|
353
|
+
*/
|
|
354
|
+
export function extractCursorPosition(lines: string[], height: number): { row: number; col: number } | null {
|
|
355
|
+
// Only scan the bottom `height` lines (visible viewport)
|
|
356
|
+
const viewportTop = Math.max(0, lines.length - height);
|
|
357
|
+
for (let row = lines.length - 1; row >= viewportTop; row--) {
|
|
358
|
+
const line = lines[row];
|
|
359
|
+
const markerIndex = line.indexOf(CURSOR_MARKER);
|
|
360
|
+
if (markerIndex !== -1) {
|
|
361
|
+
// Calculate visual column (width of text before marker)
|
|
362
|
+
const beforeMarker = line.slice(0, markerIndex);
|
|
363
|
+
const col = visibleWidth(beforeMarker);
|
|
364
|
+
|
|
365
|
+
// Strip marker from the line
|
|
366
|
+
lines[row] = line.slice(0, markerIndex) + line.slice(markerIndex + CURSOR_MARKER.length);
|
|
367
|
+
|
|
368
|
+
return { row, col };
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|