@earendil-works/pi-tui 0.84.4 → 0.85.1
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/README.md +53 -4
- package/dist/alt-screen-search.d.ts +21 -1
- package/dist/alt-screen-search.d.ts.map +1 -1
- package/dist/alt-screen-search.js +202 -42
- package/dist/alt-screen-search.js.map +1 -1
- package/dist/components/box.d.ts +3 -1
- package/dist/components/box.d.ts.map +1 -1
- package/dist/components/box.js +29 -0
- package/dist/components/box.js.map +1 -1
- package/dist/components/editor.d.ts +6 -1
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +98 -18
- package/dist/components/editor.js.map +1 -1
- package/dist/components/input.d.ts +12 -1
- package/dist/components/input.d.ts.map +1 -1
- package/dist/components/input.js +44 -5
- package/dist/components/input.js.map +1 -1
- package/dist/components/loader.d.ts +2 -0
- package/dist/components/loader.d.ts.map +1 -1
- package/dist/components/loader.js +10 -3
- package/dist/components/loader.js.map +1 -1
- package/dist/components/mouse-region.d.ts +12 -0
- package/dist/components/mouse-region.d.ts.map +1 -0
- package/dist/components/mouse-region.js +21 -0
- package/dist/components/mouse-region.js.map +1 -0
- package/dist/components/scroll-view.d.ts +6 -3
- package/dist/components/scroll-view.d.ts.map +1 -1
- package/dist/components/scroll-view.js +8 -2
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/select-list.d.ts +4 -1
- package/dist/components/select-list.d.ts.map +1 -1
- package/dist/components/select-list.js +49 -2
- package/dist/components/select-list.js.map +1 -1
- package/dist/components/settings-list.d.ts +5 -1
- package/dist/components/settings-list.d.ts.map +1 -1
- package/dist/components/settings-list.js +55 -5
- package/dist/components/settings-list.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/latex.d.ts.map +1 -1
- package/dist/latex.js +14 -0
- package/dist/latex.js.map +1 -1
- package/dist/layout.d.ts +3 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +32 -9
- package/dist/layout.js.map +1 -1
- package/dist/terminal-image.d.ts.map +1 -1
- package/dist/terminal-image.js +1 -4
- package/dist/terminal-image.js.map +1 -1
- package/dist/terminal.d.ts +6 -0
- package/dist/terminal.d.ts.map +1 -1
- package/dist/terminal.js +17 -4
- package/dist/terminal.js.map +1 -1
- package/dist/tui-alt-screen.d.ts +31 -1
- package/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/tui-alt-screen.js +342 -41
- package/dist/tui-alt-screen.js.map +1 -1
- package/dist/tui-main-screen.d.ts.map +1 -1
- package/dist/tui-main-screen.js +6 -5
- package/dist/tui-main-screen.js.map +1 -1
- package/dist/tui.d.ts +84 -6
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +123 -9
- package/dist/tui.js.map +1 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -0
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/components/box.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Component, type TuiMouseDispatchResult, type TuiMouseEvent } from "../tui.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Box component - a container that applies padding and background to all children
|
|
4
4
|
*/
|
|
@@ -8,6 +8,7 @@ export declare class Box implements Component {
|
|
|
8
8
|
private paddingY;
|
|
9
9
|
private bgFn?;
|
|
10
10
|
private cache?;
|
|
11
|
+
private mouseLayout?;
|
|
11
12
|
constructor(paddingX?: number, paddingY?: number, bgFn?: (text: string) => string);
|
|
12
13
|
addChild(component: Component): void;
|
|
13
14
|
removeChild(component: Component): void;
|
|
@@ -16,6 +17,7 @@ export declare class Box implements Component {
|
|
|
16
17
|
private invalidateCache;
|
|
17
18
|
private matchCache;
|
|
18
19
|
invalidate(): void;
|
|
20
|
+
handleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | undefined;
|
|
19
21
|
render(width: number): string[];
|
|
20
22
|
private applyBg;
|
|
21
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAsB,KAAK,sBAAsB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAUhH;;GAEG;AACH,qBAAa,GAAI,YAAW,SAAS;IACpC,QAAQ,EAAE,SAAS,EAAE,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAC,CAA2B;IAGxC,OAAO,CAAC,KAAK,CAAC,CAAc;IAC5B,OAAO,CAAC,WAAW,CAAC,CAA+E;IAEnG,YAAY,QAAQ,SAAI,EAAE,QAAQ,SAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAItE;IAED,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAGnC;IAED,WAAW,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAMtC;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAG7C;IAED,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,UAAU;IAWlB,UAAU,IAAI,IAAI,CAKjB;IAED,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,sBAAsB,GAAG,SAAS,CAwBpE;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAsD9B;IAED,OAAO,CAAC,OAAO;CAUf","sourcesContent":["import { type Component, dispatchMouseEvent, type TuiMouseDispatchResult, type TuiMouseEvent } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth } from \"../utils.ts\";\n\ntype RenderCache = {\n\tchildLines: string[];\n\twidth: number;\n\tbgSample: string | undefined;\n\tlines: string[];\n};\n\n/**\n * Box component - a container that applies padding and background to all children\n */\nexport class Box implements Component {\n\tchildren: Component[] = [];\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cache?: RenderCache;\n\tprivate mouseLayout?: { width: number; children: Array<{ component: Component; height: number }> };\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\taddChild(component: Component): void {\n\t\tthis.children.push(component);\n\t\tthis.invalidateCache();\n\t}\n\n\tremoveChild(component: Component): void {\n\t\tconst index = this.children.indexOf(component);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tthis.invalidateCache();\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.children = [];\n\t\tthis.invalidateCache();\n\t}\n\n\tsetBgFn(bgFn?: (text: string) => string): void {\n\t\tthis.bgFn = bgFn;\n\t\t// Don't invalidate here - we'll detect bgFn changes by sampling output\n\t}\n\n\tprivate invalidateCache(): void {\n\t\tthis.cache = undefined;\n\t}\n\n\tprivate matchCache(width: number, childLines: string[], bgSample: string | undefined): boolean {\n\t\tconst cache = this.cache;\n\t\treturn (\n\t\t\t!!cache &&\n\t\t\tcache.width === width &&\n\t\t\tcache.bgSample === bgSample &&\n\t\t\tcache.childLines.length === childLines.length &&\n\t\t\tcache.childLines.every((line, i) => line === childLines[i])\n\t\t);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.invalidateCache();\n\t\tfor (const child of this.children) {\n\t\t\tchild.invalidate?.();\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | undefined {\n\t\tconst contentWidth = Math.max(1, event.width - this.paddingX * 2);\n\t\tconst contentY = event.y - this.paddingY;\n\t\tconst contentX = event.x - this.paddingX;\n\t\tif (contentY < 0 || contentX < 0 || contentX >= contentWidth) return undefined;\n\n\t\tconst mouseChildren =\n\t\t\tthis.mouseLayout?.width === contentWidth\n\t\t\t\t? this.mouseLayout.children\n\t\t\t\t: this.children.map((component) => ({ component, height: component.render(contentWidth).length }));\n\t\tlet childY = 0;\n\t\tfor (const { component: child, height: childHeight } of mouseChildren) {\n\t\t\tif (contentY >= childY && contentY < childY + childHeight) {\n\t\t\t\treturn dispatchMouseEvent(child, {\n\t\t\t\t\t...event,\n\t\t\t\t\tx: contentX,\n\t\t\t\t\ty: contentY - childY,\n\t\t\t\t\twidth: contentWidth,\n\t\t\t\t\theight: childHeight,\n\t\t\t\t});\n\t\t\t}\n\t\t\tchildY += childHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.children.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\t\tconst leftPad = \" \".repeat(this.paddingX);\n\n\t\t// Render all children\n\t\tconst childLines: string[] = [];\n\t\tconst mouseChildren: Array<{ component: Component; height: number }> = [];\n\t\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tmouseChildren.push({ component: child, height: lines.length });\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\n\t\tthis.mouseLayout = { width: contentWidth, children: mouseChildren };\n\n\t\tif (childLines.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Check if bgFn output changed by sampling\n\t\tconst bgSample = this.bgFn ? this.bgFn(\"test\") : undefined;\n\n\t\t// Check cache validity\n\t\tif (this.matchCache(width, childLines, bgSample)) {\n\t\t\treturn this.cache!.lines;\n\t\t}\n\n\t\t// Apply background and padding\n\t\tconst result: string[] = [];\n\n\t\t// Top padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Content\n\t\tfor (const line of childLines) {\n\t\t\tresult.push(this.applyBg(line, width));\n\t\t}\n\n\t\t// Bottom padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Update cache\n\t\tthis.cache = { childLines, width, bgSample, lines: result };\n\n\t\treturn result;\n\t}\n\n\tprivate applyBg(line: string, width: number): string {\n\t\tconst visLen = visibleWidth(line);\n\t\tconst padNeeded = Math.max(0, width - visLen);\n\t\tconst padded = line + \" \".repeat(padNeeded);\n\n\t\tif (this.bgFn) {\n\t\t\treturn applyBackgroundToLine(padded, width, this.bgFn);\n\t\t}\n\t\treturn padded;\n\t}\n}\n"]}
|
package/dist/components/box.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dispatchMouseEvent } from "../tui.js";
|
|
1
2
|
import { applyBackgroundToLine, visibleWidth } from "../utils.js";
|
|
2
3
|
/**
|
|
3
4
|
* Box component - a container that applies padding and background to all children
|
|
@@ -9,6 +10,7 @@ export class Box {
|
|
|
9
10
|
bgFn;
|
|
10
11
|
// Cache for rendered output
|
|
11
12
|
cache;
|
|
13
|
+
mouseLayout;
|
|
12
14
|
constructor(paddingX = 1, paddingY = 1, bgFn) {
|
|
13
15
|
this.paddingX = paddingX;
|
|
14
16
|
this.paddingY = paddingY;
|
|
@@ -50,6 +52,30 @@ export class Box {
|
|
|
50
52
|
child.invalidate?.();
|
|
51
53
|
}
|
|
52
54
|
}
|
|
55
|
+
handleMouse(event) {
|
|
56
|
+
const contentWidth = Math.max(1, event.width - this.paddingX * 2);
|
|
57
|
+
const contentY = event.y - this.paddingY;
|
|
58
|
+
const contentX = event.x - this.paddingX;
|
|
59
|
+
if (contentY < 0 || contentX < 0 || contentX >= contentWidth)
|
|
60
|
+
return undefined;
|
|
61
|
+
const mouseChildren = this.mouseLayout?.width === contentWidth
|
|
62
|
+
? this.mouseLayout.children
|
|
63
|
+
: this.children.map((component) => ({ component, height: component.render(contentWidth).length }));
|
|
64
|
+
let childY = 0;
|
|
65
|
+
for (const { component: child, height: childHeight } of mouseChildren) {
|
|
66
|
+
if (contentY >= childY && contentY < childY + childHeight) {
|
|
67
|
+
return dispatchMouseEvent(child, {
|
|
68
|
+
...event,
|
|
69
|
+
x: contentX,
|
|
70
|
+
y: contentY - childY,
|
|
71
|
+
width: contentWidth,
|
|
72
|
+
height: childHeight,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
childY += childHeight;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
53
79
|
render(width) {
|
|
54
80
|
if (this.children.length === 0) {
|
|
55
81
|
return [];
|
|
@@ -58,12 +84,15 @@ export class Box {
|
|
|
58
84
|
const leftPad = " ".repeat(this.paddingX);
|
|
59
85
|
// Render all children
|
|
60
86
|
const childLines = [];
|
|
87
|
+
const mouseChildren = [];
|
|
61
88
|
for (const child of this.children) {
|
|
62
89
|
const lines = child.render(contentWidth);
|
|
90
|
+
mouseChildren.push({ component: child, height: lines.length });
|
|
63
91
|
for (const line of lines) {
|
|
64
92
|
childLines.push(leftPad + line);
|
|
65
93
|
}
|
|
66
94
|
}
|
|
95
|
+
this.mouseLayout = { width: contentWidth, children: mouseChildren };
|
|
67
96
|
if (childLines.length === 0) {
|
|
68
97
|
return [];
|
|
69
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.js","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"box.js","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,kBAAkB,EAAmD,MAAM,WAAW,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AASlE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QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAE5D,OAAO,MAAM,CAAC;IAAA,CACd;IAEO,OAAO,CAAC,IAAY,EAAE,KAAa,EAAU;QACpD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE5C,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,OAAO,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,MAAM,CAAC;IAAA,CACd;CACD","sourcesContent":["import { type Component, dispatchMouseEvent, type TuiMouseDispatchResult, type TuiMouseEvent } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth } from \"../utils.ts\";\n\ntype RenderCache = {\n\tchildLines: string[];\n\twidth: number;\n\tbgSample: string | undefined;\n\tlines: string[];\n};\n\n/**\n * Box component - a container that applies padding and background to all children\n */\nexport class Box implements Component {\n\tchildren: Component[] = [];\n\tprivate paddingX: number;\n\tprivate paddingY: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cache?: RenderCache;\n\tprivate mouseLayout?: { width: number; children: Array<{ component: Component; height: number }> };\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingY = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\taddChild(component: Component): void {\n\t\tthis.children.push(component);\n\t\tthis.invalidateCache();\n\t}\n\n\tremoveChild(component: Component): void {\n\t\tconst index = this.children.indexOf(component);\n\t\tif (index !== -1) {\n\t\t\tthis.children.splice(index, 1);\n\t\t\tthis.invalidateCache();\n\t\t}\n\t}\n\n\tclear(): void {\n\t\tthis.children = [];\n\t\tthis.invalidateCache();\n\t}\n\n\tsetBgFn(bgFn?: (text: string) => string): void {\n\t\tthis.bgFn = bgFn;\n\t\t// Don't invalidate here - we'll detect bgFn changes by sampling output\n\t}\n\n\tprivate invalidateCache(): void {\n\t\tthis.cache = undefined;\n\t}\n\n\tprivate matchCache(width: number, childLines: string[], bgSample: string | undefined): boolean {\n\t\tconst cache = this.cache;\n\t\treturn (\n\t\t\t!!cache &&\n\t\t\tcache.width === width &&\n\t\t\tcache.bgSample === bgSample &&\n\t\t\tcache.childLines.length === childLines.length &&\n\t\t\tcache.childLines.every((line, i) => line === childLines[i])\n\t\t);\n\t}\n\n\tinvalidate(): void {\n\t\tthis.invalidateCache();\n\t\tfor (const child of this.children) {\n\t\t\tchild.invalidate?.();\n\t\t}\n\t}\n\n\thandleMouse(event: TuiMouseEvent): TuiMouseDispatchResult | undefined {\n\t\tconst contentWidth = Math.max(1, event.width - this.paddingX * 2);\n\t\tconst contentY = event.y - this.paddingY;\n\t\tconst contentX = event.x - this.paddingX;\n\t\tif (contentY < 0 || contentX < 0 || contentX >= contentWidth) return undefined;\n\n\t\tconst mouseChildren =\n\t\t\tthis.mouseLayout?.width === contentWidth\n\t\t\t\t? this.mouseLayout.children\n\t\t\t\t: this.children.map((component) => ({ component, height: component.render(contentWidth).length }));\n\t\tlet childY = 0;\n\t\tfor (const { component: child, height: childHeight } of mouseChildren) {\n\t\t\tif (contentY >= childY && contentY < childY + childHeight) {\n\t\t\t\treturn dispatchMouseEvent(child, {\n\t\t\t\t\t...event,\n\t\t\t\t\tx: contentX,\n\t\t\t\t\ty: contentY - childY,\n\t\t\t\t\twidth: contentWidth,\n\t\t\t\t\theight: childHeight,\n\t\t\t\t});\n\t\t\t}\n\t\t\tchildY += childHeight;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\tif (this.children.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\t\tconst leftPad = \" \".repeat(this.paddingX);\n\n\t\t// Render all children\n\t\tconst childLines: string[] = [];\n\t\tconst mouseChildren: Array<{ component: Component; height: number }> = [];\n\t\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tmouseChildren.push({ component: child, height: lines.length });\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\n\t\tthis.mouseLayout = { width: contentWidth, children: mouseChildren };\n\n\t\tif (childLines.length === 0) {\n\t\t\treturn [];\n\t\t}\n\n\t\t// Check if bgFn output changed by sampling\n\t\tconst bgSample = this.bgFn ? this.bgFn(\"test\") : undefined;\n\n\t\t// Check cache validity\n\t\tif (this.matchCache(width, childLines, bgSample)) {\n\t\t\treturn this.cache!.lines;\n\t\t}\n\n\t\t// Apply background and padding\n\t\tconst result: string[] = [];\n\n\t\t// Top padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Content\n\t\tfor (const line of childLines) {\n\t\t\tresult.push(this.applyBg(line, width));\n\t\t}\n\n\t\t// Bottom padding\n\t\tfor (let i = 0; i < this.paddingY; i++) {\n\t\t\tresult.push(this.applyBg(\"\", width));\n\t\t}\n\n\t\t// Update cache\n\t\tthis.cache = { childLines, width, bgSample, lines: result };\n\n\t\treturn result;\n\t}\n\n\tprivate applyBg(line: string, width: number): string {\n\t\tconst visLen = visibleWidth(line);\n\t\tconst padNeeded = Math.max(0, width - visLen);\n\t\tconst padded = line + \" \".repeat(padNeeded);\n\n\t\tif (this.bgFn) {\n\t\t\treturn applyBackgroundToLine(padded, width, this.bgFn);\n\t\t}\n\t\treturn padded;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AutocompleteProvider } from "../autocomplete.ts";
|
|
2
|
-
import { type Component, type Focusable, type TUI } from "../tui.ts";
|
|
2
|
+
import { type Component, type Focusable, type TUI, type TuiMouseEvent, type TuiMouseEventResult } from "../tui.ts";
|
|
3
3
|
import { type SelectListTheme } from "./select-list.ts";
|
|
4
4
|
/**
|
|
5
5
|
* Represents a chunk of text for word-wrap layout.
|
|
@@ -38,6 +38,8 @@ export declare class Editor implements Component, Focusable {
|
|
|
38
38
|
private theme;
|
|
39
39
|
private paddingX;
|
|
40
40
|
private lastWidth;
|
|
41
|
+
private renderedVisibleLineCount;
|
|
42
|
+
private renderedAutocompleteHeight;
|
|
41
43
|
private scrollOffset;
|
|
42
44
|
borderColor: (str: string) => string;
|
|
43
45
|
private autocompleteProvider?;
|
|
@@ -92,7 +94,10 @@ export declare class Editor implements Component, Focusable {
|
|
|
92
94
|
/** Internal setText that doesn't reset history state - used by navigateHistory */
|
|
93
95
|
private setTextInternal;
|
|
94
96
|
invalidate(): void;
|
|
97
|
+
protected renderTopBorder(width: number, hiddenLineCount: number): string;
|
|
98
|
+
protected renderBottomBorder(width: number, hiddenLineCount: number): string;
|
|
95
99
|
render(width: number): string[];
|
|
100
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined;
|
|
96
101
|
handleInput(data: string): void;
|
|
97
102
|
private layoutText;
|
|
98
103
|
getText(): string;
|