@shanepadgett/tau-tui 0.4.0 → 0.5.0
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/package.json +1 -1
- package/src/tool-panel.ts +22 -8
package/package.json
CHANGED
package/src/tool-panel.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { type Component, truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import { type Component, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
3
3
|
import { renderToolKeyHints, type ToolKeyHint } from "./key-hints.ts";
|
|
4
4
|
|
|
5
5
|
export type ToolPanelFooter =
|
|
@@ -13,6 +13,7 @@ export interface ToolPanelConfig {
|
|
|
13
13
|
header?: Component | readonly string[];
|
|
14
14
|
body: Component;
|
|
15
15
|
footer: ToolPanelFooter;
|
|
16
|
+
border?: "horizontal" | "box";
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export class ToolPanel implements Component {
|
|
@@ -26,22 +27,35 @@ export class ToolPanel implements Component {
|
|
|
26
27
|
|
|
27
28
|
render(width: number): string[] {
|
|
28
29
|
const renderWidth = Math.max(1, width);
|
|
29
|
-
const
|
|
30
|
-
const
|
|
30
|
+
const boxed = this.config.border === "box" && renderWidth >= 5;
|
|
31
|
+
const contentWidth = boxed ? renderWidth - 4 : renderWidth;
|
|
32
|
+
const body = this.config.body.render(contentWidth).map((line) => truncateToWidth(line, contentWidth, ""));
|
|
33
|
+
const footer = this.renderFooter(contentWidth);
|
|
31
34
|
const lines: string[] = [];
|
|
32
35
|
|
|
33
|
-
lines.push(this.theme.fg("border", "─".repeat(renderWidth)));
|
|
34
|
-
lines.push(...this.renderTitle(
|
|
35
|
-
const header = this.renderHeader(
|
|
36
|
+
if (!boxed) lines.push(this.theme.fg("border", "─".repeat(renderWidth)));
|
|
37
|
+
lines.push(...this.renderTitle(contentWidth));
|
|
38
|
+
const header = this.renderHeader(contentWidth);
|
|
36
39
|
if (header.length > 0) lines.push("");
|
|
37
40
|
lines.push(...header);
|
|
38
41
|
if (body.length > 0) lines.push("");
|
|
39
42
|
lines.push(...body);
|
|
40
43
|
if (footer.length > 0) lines.push("");
|
|
41
44
|
lines.push(...footer);
|
|
42
|
-
|
|
45
|
+
if (!boxed) {
|
|
46
|
+
lines.push(this.theme.fg("border", "─".repeat(renderWidth)));
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
const border = (text: string) => this.theme.fg("border", text);
|
|
51
|
+
return [
|
|
52
|
+
border(`╭${"─".repeat(renderWidth - 2)}╮`),
|
|
53
|
+
...lines.map((line) => {
|
|
54
|
+
const content = truncateToWidth(line, contentWidth, "");
|
|
55
|
+
return `${border("│")} ${content}${" ".repeat(Math.max(0, contentWidth - visibleWidth(content)))} ${border("│")}`;
|
|
56
|
+
}),
|
|
57
|
+
border(`╰${"─".repeat(renderWidth - 2)}╯`),
|
|
58
|
+
];
|
|
45
59
|
}
|
|
46
60
|
|
|
47
61
|
invalidate(): void {
|