@bismawy/pi-arnative 0.18.1 → 0.18.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.
Files changed (2) hide show
  1. package/lib/box.ts +27 -4
  2. package/package.json +1 -1
package/lib/box.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * never loads it as an extension.
5
5
  */
6
6
  import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
7
- import { stripAnsi, thinkingColorOf } from "./ansi.ts";
7
+ import { softSecondaryOf, stripAnsi, thinkingColorOf } from "./ansi.ts";
8
8
 
9
9
  /** A clickable span inside rendered lines: 0-based cell columns, inclusive. */
10
10
  export interface TextSpan {
@@ -125,9 +125,32 @@ export function screenTitle(setting: string, extension = `Arnative${BRAND}`): st
125
125
  return `${setting} - ${extension}`;
126
126
  }
127
127
 
128
+ const KEYCAP = /\[([^\]]+)\]/g;
129
+
130
+ /** Keybind legend paint, one style on every screen (skill arnative-pi §6): the brackets
131
+ * are `dim`, the key glyph inside takes the accent-soft tier, labels and separators stay
132
+ * `dim`. Each segment paints itself, because a `dim` wrap around the whole line would be
133
+ * erased by the reset at the end of the first painted keycap. */
134
+ export function paintKeycapLegend(
135
+ legend: string,
136
+ theme: BoxTheme | null,
137
+ soft: (s: string) => string,
138
+ ): string {
139
+ const dim = (s: string) => (theme ? theme.fg("dim", s) : s);
140
+ if (!theme) return legend;
141
+ let out = "";
142
+ let at = 0;
143
+ for (const match of legend.matchAll(KEYCAP)) {
144
+ out += dim(legend.slice(at, match.index)) + dim("[") + soft(match[1]!) + dim("]");
145
+ at = match.index + match[0].length;
146
+ }
147
+ return out + dim(legend.slice(at));
148
+ }
149
+
128
150
  /** The chrome every arnative screen shares: frame, title in `accent`+bold, description in
129
- * `muted`, blank, the screen's `body`, blank, legend in `dim`. One function so the screens
130
- * cannot drift apart; `body` rows arrive already painted and truncated. */
151
+ * `muted`, blank, the screen's `body`, blank, legend with accent-soft keycaps on `dim`.
152
+ * One function so the screens cannot drift apart; `body` rows arrive already painted and
153
+ * truncated. */
131
154
  export function renderScreen(
132
155
  theme: BoxTheme | null,
133
156
  width: number,
@@ -147,7 +170,7 @@ export function renderScreen(
147
170
  row(""),
148
171
  ...body.map(row),
149
172
  row(""),
150
- row(text.legend.includes("\u001b[") ? text.legend : fg("dim", text.legend)),
173
+ row(text.legend.includes("\u001b[") ? text.legend : paintKeycapLegend(text.legend, theme, softSecondaryOf(theme))),
151
174
  boxEdge("╰", "╯", width, border),
152
175
  ].map((l) => truncateToWidth(l, width, ""));
153
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bismawy/pi-arnative",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
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",