@ashx-j/lunr-tui 0.2.0 → 0.2.2
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/components/box.d.ts +5 -1
- package/dist/components/box.d.ts.map +1 -1
- package/dist/components/box.js +20 -4
- package/dist/components/box.js.map +1 -1
- package/dist/components/text.d.ts +5 -1
- package/dist/components/text.d.ts.map +1 -1
- package/dist/components/text.js +28 -10
- package/dist/components/text.js.map +1 -1
- package/dist/tui.d.ts +8 -0
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +69 -14
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
package/dist/components/box.d.ts
CHANGED
|
@@ -5,10 +5,14 @@ import type { Component } from "../tui.ts";
|
|
|
5
5
|
export declare class Box implements Component {
|
|
6
6
|
children: Component[];
|
|
7
7
|
private paddingX;
|
|
8
|
-
private
|
|
8
|
+
private paddingTop;
|
|
9
|
+
private paddingBottom;
|
|
9
10
|
private bgFn?;
|
|
10
11
|
private cache?;
|
|
11
12
|
constructor(paddingX?: number, paddingY?: number, bgFn?: (text: string) => string);
|
|
13
|
+
setPadding(paddingX: number, paddingY: number): void;
|
|
14
|
+
setPaddingTop(paddingTop: number): void;
|
|
15
|
+
setPaddingBottom(paddingBottom: number): void;
|
|
12
16
|
addChild(component: Component): void;
|
|
13
17
|
removeChild(component: Component): void;
|
|
14
18
|
clear(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAU3C;;GAEG;AACH,qBAAa,GAAI,YAAW,SAAS;IACpC,QAAQ,EAAE,SAAS,EAAE,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"box.d.ts","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAU3C;;GAEG;AACH,qBAAa,GAAI,YAAW,SAAS;IACpC,QAAQ,EAAE,SAAS,EAAE,CAAM;IAC3B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,IAAI,CAAC,CAA2B;IAGxC,OAAO,CAAC,KAAK,CAAC,CAAc;IAE5B,YAAY,QAAQ,SAAI,EAAE,QAAQ,SAAI,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAKtE;IAED,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAKnD;IAED,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAG5C;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,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAmD9B;IAED,OAAO,CAAC,OAAO;CAUf","sourcesContent":["import type { Component } 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 paddingTop: number;\n\tprivate paddingBottom: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cache?: RenderCache;\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\tsetPadding(paddingX: number, paddingY: number): void {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.invalidateCache();\n\t}\n\n\tsetPaddingTop(paddingTop: number): void {\n\t\tthis.paddingTop = paddingTop;\n\t\tthis.invalidateCache();\n\t}\n\n\tsetPaddingBottom(paddingBottom: number): void {\n\t\tthis.paddingBottom = paddingBottom;\n\t\tthis.invalidateCache();\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\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\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\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.paddingTop; 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.paddingBottom; 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
|
@@ -5,15 +5,31 @@ import { applyBackgroundToLine, visibleWidth } from "../utils.js";
|
|
|
5
5
|
export class Box {
|
|
6
6
|
children = [];
|
|
7
7
|
paddingX;
|
|
8
|
-
|
|
8
|
+
paddingTop;
|
|
9
|
+
paddingBottom;
|
|
9
10
|
bgFn;
|
|
10
11
|
// Cache for rendered output
|
|
11
12
|
cache;
|
|
12
13
|
constructor(paddingX = 1, paddingY = 1, bgFn) {
|
|
13
14
|
this.paddingX = paddingX;
|
|
14
|
-
this.
|
|
15
|
+
this.paddingTop = paddingY;
|
|
16
|
+
this.paddingBottom = paddingY;
|
|
15
17
|
this.bgFn = bgFn;
|
|
16
18
|
}
|
|
19
|
+
setPadding(paddingX, paddingY) {
|
|
20
|
+
this.paddingX = paddingX;
|
|
21
|
+
this.paddingTop = paddingY;
|
|
22
|
+
this.paddingBottom = paddingY;
|
|
23
|
+
this.invalidateCache();
|
|
24
|
+
}
|
|
25
|
+
setPaddingTop(paddingTop) {
|
|
26
|
+
this.paddingTop = paddingTop;
|
|
27
|
+
this.invalidateCache();
|
|
28
|
+
}
|
|
29
|
+
setPaddingBottom(paddingBottom) {
|
|
30
|
+
this.paddingBottom = paddingBottom;
|
|
31
|
+
this.invalidateCache();
|
|
32
|
+
}
|
|
17
33
|
addChild(component) {
|
|
18
34
|
this.children.push(component);
|
|
19
35
|
this.invalidateCache();
|
|
@@ -76,7 +92,7 @@ export class Box {
|
|
|
76
92
|
// Apply background and padding
|
|
77
93
|
const result = [];
|
|
78
94
|
// Top padding
|
|
79
|
-
for (let i = 0; i < this.
|
|
95
|
+
for (let i = 0; i < this.paddingTop; i++) {
|
|
80
96
|
result.push(this.applyBg("", width));
|
|
81
97
|
}
|
|
82
98
|
// Content
|
|
@@ -84,7 +100,7 @@ export class Box {
|
|
|
84
100
|
result.push(this.applyBg(line, width));
|
|
85
101
|
}
|
|
86
102
|
// Bottom padding
|
|
87
|
-
for (let i = 0; i < this.
|
|
103
|
+
for (let i = 0; i < this.paddingBottom; i++) {
|
|
88
104
|
result.push(this.applyBg("", width));
|
|
89
105
|
}
|
|
90
106
|
// Update cache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"box.js","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AASlE;;GAEG;AACH,MAAM,OAAO,GAAG;IACf,QAAQ,GAAgB,EAAE,CAAC;IACnB,QAAQ,CAAS;IACjB,
|
|
1
|
+
{"version":3,"file":"box.js","sourceRoot":"","sources":["../../src/components/box.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AASlE;;GAEG;AACH,MAAM,OAAO,GAAG;IACf,QAAQ,GAAgB,EAAE,CAAC;IACnB,QAAQ,CAAS;IACjB,UAAU,CAAS;IACnB,aAAa,CAAS;IACtB,IAAI,CAA4B;IAExC,4BAA4B;IACpB,KAAK,CAAe;IAE5B,YAAY,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,CAAC,EAAE,IAA+B,EAAE;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED,UAAU,CAAC,QAAgB,EAAE,QAAgB,EAAQ;QACpD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC;QAC9B,IAAI,CAAC,eAAe,EAAE,CAAC;IAAA,CACvB;IAED,aAAa,CAAC,UAAkB,EAAQ;QACvC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,EAAE,CAAC;IAAA,CACvB;IAED,gBAAgB,CAAC,aAAqB,EAAQ;QAC7C,IAAI,CAAC,aAAa,GAAG,aA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roundToLine, 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 paddingTop: number;\n\tprivate paddingBottom: number;\n\tprivate bgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cache?: RenderCache;\n\n\tconstructor(paddingX = 1, paddingY = 1, bgFn?: (text: string) => string) {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.bgFn = bgFn;\n\t}\n\n\tsetPadding(paddingX: number, paddingY: number): void {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.invalidateCache();\n\t}\n\n\tsetPaddingTop(paddingTop: number): void {\n\t\tthis.paddingTop = paddingTop;\n\t\tthis.invalidateCache();\n\t}\n\n\tsetPaddingBottom(paddingBottom: number): void {\n\t\tthis.paddingBottom = paddingBottom;\n\t\tthis.invalidateCache();\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\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\tfor (const child of this.children) {\n\t\t\tconst lines = child.render(contentWidth);\n\t\t\tfor (const line of lines) {\n\t\t\t\tchildLines.push(leftPad + line);\n\t\t\t}\n\t\t}\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.paddingTop; 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.paddingBottom; 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"]}
|
|
@@ -5,12 +5,16 @@ import type { Component } from "../tui.ts";
|
|
|
5
5
|
export declare class Text implements Component {
|
|
6
6
|
private text;
|
|
7
7
|
private paddingX;
|
|
8
|
-
private
|
|
8
|
+
private paddingTop;
|
|
9
|
+
private paddingBottom;
|
|
9
10
|
private customBgFn?;
|
|
10
11
|
private cachedText?;
|
|
11
12
|
private cachedWidth?;
|
|
12
13
|
private cachedLines?;
|
|
13
14
|
constructor(text?: string, paddingX?: number, paddingY?: number, customBgFn?: (text: string) => string);
|
|
15
|
+
setPadding(paddingX: number, paddingY: number): void;
|
|
16
|
+
setPaddingTop(paddingTop: number): void;
|
|
17
|
+
setPaddingBottom(paddingBottom: number): void;
|
|
14
18
|
setText(text: string): void;
|
|
15
19
|
setCustomBgFn(customBgFn?: (text: string) => string): void;
|
|
16
20
|
invalidate(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,IAAK,YAAW,SAAS;IACrC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAG3C;;GAEG;AACH,qBAAa,IAAK,YAAW,SAAS;IACrC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,UAAU,CAAC,CAA2B;IAG9C,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAC,CAAW;IAE/B,YAAY,IAAI,GAAE,MAAW,EAAE,QAAQ,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAM/G;IAED,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAKnD;IAED,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAGtC;IAED,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAG5C;IAED,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAG1B;IAED,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAKzD;IAED,UAAU,IAAI,IAAI,CAIjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAgE9B;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from \"../utils.ts\";\n\n/**\n * Text component - displays multi-line text with word wrapping\n */\nexport class Text implements Component {\n\tprivate text: string;\n\tprivate paddingX: number; // Left/right padding\n\tprivate paddingTop: number;\n\tprivate paddingBottom: number;\n\tprivate customBgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedText?: string;\n\tprivate cachedWidth?: number;\n\tprivate cachedLines?: string[];\n\n\tconstructor(text: string = \"\", paddingX: number = 1, paddingY: number = 1, customBgFn?: (text: string) => string) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.customBgFn = customBgFn;\n\t}\n\n\tsetPadding(paddingX: number, paddingY: number): void {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.invalidate();\n\t}\n\n\tsetPaddingTop(paddingTop: number): void {\n\t\tthis.paddingTop = paddingTop;\n\t\tthis.invalidate();\n\t}\n\n\tsetPaddingBottom(paddingBottom: number): void {\n\t\tthis.paddingBottom = paddingBottom;\n\t\tthis.invalidate();\n\t}\n\n\tsetText(text: string): void {\n\t\tthis.text = text;\n\t\tthis.invalidate();\n\t}\n\n\tsetCustomBgFn(customBgFn?: (text: string) => string): void {\n\t\tthis.customBgFn = customBgFn;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\t// Check cache\n\t\tif (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Don't render anything if there's no actual text\n\t\tif (!this.text || this.text.trim() === \"\") {\n\t\t\tconst result: string[] = [];\n\t\t\tthis.cachedText = this.text;\n\t\t\tthis.cachedWidth = width;\n\t\t\tthis.cachedLines = result;\n\t\t\treturn result;\n\t\t}\n\n\t\t// Replace tabs with 3 spaces\n\t\tconst normalizedText = this.text.replace(/\\t/g, \" \");\n\n\t\t// Calculate content width (subtract left/right margins)\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Wrap text (this preserves ANSI codes but does NOT pad)\n\t\tconst wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);\n\n\t\t// Add margins and background to each line\n\t\tconst leftMargin = \" \".repeat(this.paddingX);\n\t\tconst rightMargin = \" \".repeat(this.paddingX);\n\t\tconst contentLines: string[] = [];\n\n\t\tfor (const line of wrappedLines) {\n\t\t\t// Add margins\n\t\t\tconst lineWithMargins = leftMargin + line + rightMargin;\n\n\t\t\t// Apply background if specified (this also pads to full width)\n\t\t\tif (this.customBgFn) {\n\t\t\t\tcontentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));\n\t\t\t} else {\n\t\t\t\t// No background - just pad to width with spaces\n\t\t\t\tconst visibleLen = visibleWidth(lineWithMargins);\n\t\t\t\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\t\t\t\tcontentLines.push(lineWithMargins + \" \".repeat(paddingNeeded));\n\t\t\t}\n\t\t}\n\n\t\t// Add top/bottom padding (empty lines)\n\t\tconst emptyLine = \" \".repeat(width);\n\t\tconst paddedEmpty = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;\n\t\tconst topPad: string[] = [];\n\t\tfor (let i = 0; i < this.paddingTop; i++) {\n\t\t\ttopPad.push(paddedEmpty);\n\t\t}\n\t\tconst bottomPad: string[] = [];\n\t\tfor (let i = 0; i < this.paddingBottom; i++) {\n\t\t\tbottomPad.push(paddedEmpty);\n\t\t}\n\n\t\tconst result = [...topPad, ...contentLines, ...bottomPad];\n\n\t\t// Update cache\n\t\tthis.cachedText = this.text;\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedLines = result;\n\n\t\treturn result.length > 0 ? result : [\"\"];\n\t}\n}\n"]}
|
package/dist/components/text.js
CHANGED
|
@@ -5,7 +5,8 @@ import { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from "../utils.
|
|
|
5
5
|
export class Text {
|
|
6
6
|
text;
|
|
7
7
|
paddingX; // Left/right padding
|
|
8
|
-
|
|
8
|
+
paddingTop;
|
|
9
|
+
paddingBottom;
|
|
9
10
|
customBgFn;
|
|
10
11
|
// Cache for rendered output
|
|
11
12
|
cachedText;
|
|
@@ -14,14 +15,27 @@ export class Text {
|
|
|
14
15
|
constructor(text = "", paddingX = 1, paddingY = 1, customBgFn) {
|
|
15
16
|
this.text = text;
|
|
16
17
|
this.paddingX = paddingX;
|
|
17
|
-
this.
|
|
18
|
+
this.paddingTop = paddingY;
|
|
19
|
+
this.paddingBottom = paddingY;
|
|
18
20
|
this.customBgFn = customBgFn;
|
|
19
21
|
}
|
|
22
|
+
setPadding(paddingX, paddingY) {
|
|
23
|
+
this.paddingX = paddingX;
|
|
24
|
+
this.paddingTop = paddingY;
|
|
25
|
+
this.paddingBottom = paddingY;
|
|
26
|
+
this.invalidate();
|
|
27
|
+
}
|
|
28
|
+
setPaddingTop(paddingTop) {
|
|
29
|
+
this.paddingTop = paddingTop;
|
|
30
|
+
this.invalidate();
|
|
31
|
+
}
|
|
32
|
+
setPaddingBottom(paddingBottom) {
|
|
33
|
+
this.paddingBottom = paddingBottom;
|
|
34
|
+
this.invalidate();
|
|
35
|
+
}
|
|
20
36
|
setText(text) {
|
|
21
37
|
this.text = text;
|
|
22
|
-
this.
|
|
23
|
-
this.cachedWidth = undefined;
|
|
24
|
-
this.cachedLines = undefined;
|
|
38
|
+
this.invalidate();
|
|
25
39
|
}
|
|
26
40
|
setCustomBgFn(customBgFn) {
|
|
27
41
|
this.customBgFn = customBgFn;
|
|
@@ -73,12 +87,16 @@ export class Text {
|
|
|
73
87
|
}
|
|
74
88
|
// Add top/bottom padding (empty lines)
|
|
75
89
|
const emptyLine = " ".repeat(width);
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
const paddedEmpty = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;
|
|
91
|
+
const topPad = [];
|
|
92
|
+
for (let i = 0; i < this.paddingTop; i++) {
|
|
93
|
+
topPad.push(paddedEmpty);
|
|
94
|
+
}
|
|
95
|
+
const bottomPad = [];
|
|
96
|
+
for (let i = 0; i < this.paddingBottom; i++) {
|
|
97
|
+
bottomPad.push(paddedEmpty);
|
|
80
98
|
}
|
|
81
|
-
const result = [...
|
|
99
|
+
const result = [...topPad, ...contentLines, ...bottomPad];
|
|
82
100
|
// Update cache
|
|
83
101
|
this.cachedText = this.text;
|
|
84
102
|
this.cachedWidth = width;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpF;;GAEG;AACH,MAAM,OAAO,IAAI;IACR,IAAI,CAAS;IACb,QAAQ,CAAS,CAAC,qBAAqB;IACvC,
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/components/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpF;;GAEG;AACH,MAAM,OAAO,IAAI;IACR,IAAI,CAAS;IACb,QAAQ,CAAS,CAAC,qBAAqB;IACvC,UAAU,CAAS;IACnB,aAAa,CAAS;IACtB,UAAU,CAA4B;IAE9C,4BAA4B;IACpB,UAAU,CAAU;IACpB,WAAW,CAAU;IACrB,WAAW,CAAY;IAE/B,YAAY,IAAI,GAAW,EAAE,EAAE,QAAQ,GAAW,CAAC,EAAE,QAAQ,GAAW,CAAC,EAAE,UAAqC,EAAE;QACjH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAAA,CAC7B;IAED,UAAU,CAAC,QAAgB,EAAE,QAAgB,EAAQ;QACpD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC;QAC9B,IAAI,CAAC,UAAU,EAAE,CAAC;IAAA,CAClB;IAED,aAAa,CAAC,UAAkB,EAAQ;QACvC,IAAI,CAAC,UAAU,GAAG,UA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U,CAAC,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3G,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC;QACD,MAAM,SAAS,GAAa,EAAE,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC7B,CAAC;QAED,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,YAAY,EAAE,GAAG,SAAS,CAAC,CAAC;QAE1D,eAAe;QACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;QAE1B,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAAA,CACzC;CACD","sourcesContent":["import type { Component } from \"../tui.ts\";\nimport { applyBackgroundToLine, visibleWidth, wrapTextWithAnsi } from \"../utils.ts\";\n\n/**\n * Text component - displays multi-line text with word wrapping\n */\nexport class Text implements Component {\n\tprivate text: string;\n\tprivate paddingX: number; // Left/right padding\n\tprivate paddingTop: number;\n\tprivate paddingBottom: number;\n\tprivate customBgFn?: (text: string) => string;\n\n\t// Cache for rendered output\n\tprivate cachedText?: string;\n\tprivate cachedWidth?: number;\n\tprivate cachedLines?: string[];\n\n\tconstructor(text: string = \"\", paddingX: number = 1, paddingY: number = 1, customBgFn?: (text: string) => string) {\n\t\tthis.text = text;\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.customBgFn = customBgFn;\n\t}\n\n\tsetPadding(paddingX: number, paddingY: number): void {\n\t\tthis.paddingX = paddingX;\n\t\tthis.paddingTop = paddingY;\n\t\tthis.paddingBottom = paddingY;\n\t\tthis.invalidate();\n\t}\n\n\tsetPaddingTop(paddingTop: number): void {\n\t\tthis.paddingTop = paddingTop;\n\t\tthis.invalidate();\n\t}\n\n\tsetPaddingBottom(paddingBottom: number): void {\n\t\tthis.paddingBottom = paddingBottom;\n\t\tthis.invalidate();\n\t}\n\n\tsetText(text: string): void {\n\t\tthis.text = text;\n\t\tthis.invalidate();\n\t}\n\n\tsetCustomBgFn(customBgFn?: (text: string) => string): void {\n\t\tthis.customBgFn = customBgFn;\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\tinvalidate(): void {\n\t\tthis.cachedText = undefined;\n\t\tthis.cachedWidth = undefined;\n\t\tthis.cachedLines = undefined;\n\t}\n\n\trender(width: number): string[] {\n\t\t// Check cache\n\t\tif (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {\n\t\t\treturn this.cachedLines;\n\t\t}\n\n\t\t// Don't render anything if there's no actual text\n\t\tif (!this.text || this.text.trim() === \"\") {\n\t\t\tconst result: string[] = [];\n\t\t\tthis.cachedText = this.text;\n\t\t\tthis.cachedWidth = width;\n\t\t\tthis.cachedLines = result;\n\t\t\treturn result;\n\t\t}\n\n\t\t// Replace tabs with 3 spaces\n\t\tconst normalizedText = this.text.replace(/\\t/g, \" \");\n\n\t\t// Calculate content width (subtract left/right margins)\n\t\tconst contentWidth = Math.max(1, width - this.paddingX * 2);\n\n\t\t// Wrap text (this preserves ANSI codes but does NOT pad)\n\t\tconst wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);\n\n\t\t// Add margins and background to each line\n\t\tconst leftMargin = \" \".repeat(this.paddingX);\n\t\tconst rightMargin = \" \".repeat(this.paddingX);\n\t\tconst contentLines: string[] = [];\n\n\t\tfor (const line of wrappedLines) {\n\t\t\t// Add margins\n\t\t\tconst lineWithMargins = leftMargin + line + rightMargin;\n\n\t\t\t// Apply background if specified (this also pads to full width)\n\t\t\tif (this.customBgFn) {\n\t\t\t\tcontentLines.push(applyBackgroundToLine(lineWithMargins, width, this.customBgFn));\n\t\t\t} else {\n\t\t\t\t// No background - just pad to width with spaces\n\t\t\t\tconst visibleLen = visibleWidth(lineWithMargins);\n\t\t\t\tconst paddingNeeded = Math.max(0, width - visibleLen);\n\t\t\t\tcontentLines.push(lineWithMargins + \" \".repeat(paddingNeeded));\n\t\t\t}\n\t\t}\n\n\t\t// Add top/bottom padding (empty lines)\n\t\tconst emptyLine = \" \".repeat(width);\n\t\tconst paddedEmpty = this.customBgFn ? applyBackgroundToLine(emptyLine, width, this.customBgFn) : emptyLine;\n\t\tconst topPad: string[] = [];\n\t\tfor (let i = 0; i < this.paddingTop; i++) {\n\t\t\ttopPad.push(paddedEmpty);\n\t\t}\n\t\tconst bottomPad: string[] = [];\n\t\tfor (let i = 0; i < this.paddingBottom; i++) {\n\t\t\tbottomPad.push(paddedEmpty);\n\t\t}\n\n\t\tconst result = [...topPad, ...contentLines, ...bottomPad];\n\n\t\t// Update cache\n\t\tthis.cachedText = this.text;\n\t\tthis.cachedWidth = width;\n\t\tthis.cachedLines = result;\n\n\t\treturn result.length > 0 ? result : [\"\"];\n\t}\n}\n"]}
|
package/dist/tui.d.ts
CHANGED
|
@@ -178,6 +178,11 @@ export declare class TUI extends Container {
|
|
|
178
178
|
private chatScrollOffset;
|
|
179
179
|
private lastChatViewportHeight;
|
|
180
180
|
private lastChatScrollMax;
|
|
181
|
+
private chatLaidOut;
|
|
182
|
+
private chatUsesGutter;
|
|
183
|
+
/** Bumped on non-scroll `requestRender` so offset-only paints can reuse chat layout. */
|
|
184
|
+
private contentEpoch;
|
|
185
|
+
private chatLayoutCache;
|
|
181
186
|
private alternateScreen;
|
|
182
187
|
private alternateScreenActive;
|
|
183
188
|
private mouseTrackingActive;
|
|
@@ -230,6 +235,7 @@ export declare class TUI extends Container {
|
|
|
230
235
|
private appendRenderedChild;
|
|
231
236
|
private snapStartToKittyImageHeader;
|
|
232
237
|
render(width: number): string[];
|
|
238
|
+
private copyHitRegions;
|
|
233
239
|
private shiftHitRegions;
|
|
234
240
|
/**
|
|
235
241
|
* Show an overlay component with configurable positioning and sizing.
|
|
@@ -253,6 +259,8 @@ export declare class TUI extends Container {
|
|
|
253
259
|
private queryCellSize;
|
|
254
260
|
stop(): void;
|
|
255
261
|
requestRender(force?: boolean): void;
|
|
262
|
+
private requestRenderFromScroll;
|
|
263
|
+
private queueRender;
|
|
256
264
|
private scheduleRender;
|
|
257
265
|
private syncMouseTracking;
|
|
258
266
|
private enableMouseTracking;
|