@bismawy/pi-arnative 0.8.0-rc.1 → 0.8.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.
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Rows pinned above the chat column (pi's `aboveEditor` widget slot). One shape for every
3
+ * status line: the arnative mark, one space, then the text in the theme's `dim` token.
4
+ *
5
+ * pi renders a plain string array as unstyled `Text`, so `setWidget(key, ["…"])` ignores the
6
+ * theme and the line lands in the default foreground. The patch in
7
+ * `extensions/ui-render-tweaks.ts` turns every such array into a component factory, which
8
+ * receives the live theme; this module holds the formatting that patch renders.
9
+ *
10
+ * A row that already carries ANSI (another extension painted it) keeps its own colour: only
11
+ * the unstyled rows are painted `dim`, so an error row stays red instead of being re-tinted.
12
+ *
13
+ * Lives outside `extensions/*.ts` so pi never loads it as an extension.
14
+ */
15
+ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
16
+ import { assert, isMain } from "./check.ts";
17
+
18
+ /** The mark that leads a block of rows above the chat column. */
19
+ export const STATUS_ICON = "\ueb1b";
20
+
21
+ /** pi's own cap on a string-array widget (`InteractiveMode.MAX_WIDGET_LINES`). */
22
+ export const MAX_STATUS_ROWS = 10;
23
+
24
+ type FgTheme = { fg?(color: string, text: string): string } | null;
25
+
26
+ /** `dim(text)`, or the plain text when the theme is absent or rejects the token. */
27
+ function dim(th: FgTheme, text: string): string {
28
+ try {
29
+ return th?.fg ? th.fg("dim", text) : text;
30
+ } catch {
31
+ return text;
32
+ }
33
+ }
34
+
35
+ /** Aligned under the mark; a long block is capped exactly like pi's own array widget, and
36
+ * every row is cut to `width` (a component owns its width, pi does not wrap it for us). */
37
+ export function statusRows(th: FgTheme, rows: string[], width = Number.POSITIVE_INFINITY): string[] {
38
+ const lines = rows
39
+ .slice(0, MAX_STATUS_ROWS)
40
+ .map((row, i) => {
41
+ const prefix = i === 0 ? ` ${STATUS_ICON} ` : " ";
42
+ return row.includes("\x1b") ? dim(th, prefix) + row : dim(th, prefix + row);
43
+ });
44
+ if (rows.length > MAX_STATUS_ROWS) lines.push(dim(th, " ... (widget truncated)"));
45
+ return Number.isFinite(width) ? lines.map((line) => truncateToWidth(line, width, "")) : lines;
46
+ }
47
+
48
+ if (isMain(import.meta.url)) {
49
+ const tag = (color: string, text: string) => `<${color}>${text}</${color}>`;
50
+ assert(
51
+ JSON.stringify(statusRows({ fg: tag }, ["model-heal: healed"])) === JSON.stringify(["<dim> \ueb1b model-heal: healed</dim>"]),
52
+ "one space before the mark, one after, one dim span for the whole row",
53
+ );
54
+ assert(JSON.stringify(statusRows(null, ["plain"])) === JSON.stringify([" \ueb1b plain"]), "no theme renders the plain line");
55
+ assert(
56
+ JSON.stringify(statusRows({ fg: () => { throw new Error("unknown token"); } }, ["safe"])) === JSON.stringify([" \ueb1b safe"]),
57
+ "a theme that rejects the token does not crash the render",
58
+ );
59
+ assert(
60
+ JSON.stringify(statusRows({ fg: tag }, ["one", "\x1b[31mtwo\x1b[39m"])) ===
61
+ JSON.stringify(["<dim> \ueb1b one</dim>", "<dim> </dim>\x1b[31mtwo\x1b[39m"]),
62
+ "an already-painted row keeps its own colour, continuation rows align under the text",
63
+ );
64
+ const long = statusRows({ fg: tag }, new Array(20).fill("x"));
65
+ assert(long.length === MAX_STATUS_ROWS + 1 && long.at(-1)!.includes("widget truncated"), "a long block is capped like pi's own");
66
+ assert(statusRows(null, []).length === 0, "an empty block renders nothing");
67
+ // A component owns its width: a line wider than the terminal must be cut, not wrapped.
68
+ const wide = statusRows({ fg: tag }, ["x".repeat(200)], 20);
69
+ assert(wide.length === 1 && visibleWidth(wide[0]!) === 20, "rows are cut to the render width");
70
+ console.log("status-widget.ts self-check OK");
71
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bismawy/pi-arnative",
3
- "version": "0.8.0-rc.1",
3
+ "version": "0.8.1",
4
4
  "description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -40,8 +40,8 @@
40
40
  "@earendil-works/pi-tui": "*"
41
41
  },
42
42
  "scripts": {
43
- "dev": "pi --extension ./extensions/tools.ts --extension ./extensions/section-headers.ts --extension ./extensions/footer.ts --extension ./extensions/timestamps.ts --extension ./extensions/ui-render-tweaks.ts --extension ./extensions/usage.ts --extension ./extensions/animations.ts --extension ./extensions/autocompact.ts --extension ./extensions/arnative.ts",
44
- "test": "node lib/box.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/preset-store.ts && node lib/spinner.ts && node themes/gen-themes.mjs --check && node extensions/tools.ts && node lib/list-picker.ts && node lib/compat.ts && node lib/provider.ts && node extensions/footer.ts && node extensions/timestamps.ts && node extensions/ui-render-tweaks.ts && node extensions/usage.ts && node extensions/animations.ts && node extensions/autocompact.ts && node extensions/arnative.ts && node --test",
43
+ "dev": "pi --extension ./extensions/tools.ts --extension ./extensions/section-headers.ts --extension ./extensions/footer.ts --extension ./extensions/timestamps.ts --extension ./extensions/ui-render-tweaks.ts --extension ./extensions/usage.ts --extension ./extensions/animations.ts --extension ./extensions/autocompact.ts --extension ./extensions/model-heal.ts --extension ./extensions/arnative.ts",
44
+ "test": "node lib/box.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/status-widget.ts && node lib/preset-store.ts && node lib/spinner.ts && node themes/gen-themes.mjs --check && node extensions/tools.ts && node lib/list-picker.ts && node lib/compat.ts && node lib/provider.ts && node lib/model-heal.ts && node extensions/footer.ts && node extensions/timestamps.ts && node extensions/ui-render-tweaks.ts && node extensions/usage.ts && node extensions/animations.ts && node extensions/autocompact.ts && node extensions/model-heal.ts && node extensions/arnative.ts && node --test",
45
45
  "preview": "node scripts/preview.mjs",
46
46
  "themes": "node themes/gen-themes.mjs",
47
47
  "release:check": "node scripts/release-check.mjs pre-tag",