killeros 3.0.7 → 3.0.8

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.
@@ -1,25 +1,25 @@
1
- import { Text, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
2
-
3
- export class BoundedText implements Component {
4
- private readonly text: string;
5
- private readonly maxRows?: number;
6
-
7
- constructor(text: string, maxRows?: number) {
8
- this.text = text;
9
- this.maxRows = maxRows;
10
- }
11
-
12
- render(width: number): string[] {
13
- if (width <= 0) return [];
14
- const lines = new Text(this.text, 0, 0).render(width).map((line) => truncateToWidth(line, width, ""));
15
- if (this.maxRows === undefined || lines.length <= this.maxRows) return lines;
16
- const rowLimit = Math.max(1, this.maxRows);
17
- const visible = lines.slice(0, rowLimit);
18
- const suffix = " …";
19
- const last = visible.at(-1) ?? "";
20
- visible[rowLimit - 1] = `${truncateToWidth(last, Math.max(0, width - visibleWidth(suffix)), "")}${suffix}`;
21
- return visible.map((line) => truncateToWidth(line, width, ""));
22
- }
23
-
24
- invalidate(): void {}
25
- }
1
+ import { Text, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
2
+
3
+ export class BoundedText implements Component {
4
+ private readonly text: string;
5
+ private readonly maxRows?: number;
6
+
7
+ constructor(text: string, maxRows?: number) {
8
+ this.text = text;
9
+ this.maxRows = maxRows;
10
+ }
11
+
12
+ render(width: number): string[] {
13
+ if (width <= 0) return [];
14
+ const lines = new Text(this.text, 0, 0).render(width).map((line) => truncateToWidth(line, width, ""));
15
+ if (this.maxRows === undefined || lines.length <= this.maxRows) return lines;
16
+ const rowLimit = Math.max(1, this.maxRows);
17
+ const visible = lines.slice(0, rowLimit);
18
+ const suffix = " …";
19
+ const last = visible.at(-1) ?? "";
20
+ visible[rowLimit - 1] = `${truncateToWidth(last, Math.max(0, width - visibleWidth(suffix)), "")}${suffix}`;
21
+ return visible.map((line) => truncateToWidth(line, width, ""));
22
+ }
23
+
24
+ invalidate(): void {}
25
+ }