@aeondave/pi-theme-1337 0.0.0-stage → 0.6.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/CHANGELOG.md +263 -0
- package/LICENSE +21 -0
- package/README.md +166 -2
- package/assets/banner.png +0 -0
- package/assets/palettes.gif +0 -0
- package/docs/architecture.md +172 -0
- package/docs/configuration.md +103 -0
- package/docs/palette-design.md +51 -0
- package/docs/theme-motion.md +88 -0
- package/package.json +68 -4
- package/src/avatar.ts +174 -0
- package/src/background.ts +82 -0
- package/src/config.ts +400 -0
- package/src/diff-spans.ts +77 -0
- package/src/draft.ts +10 -0
- package/src/editor.ts +545 -0
- package/src/format.ts +464 -0
- package/src/frame.ts +380 -0
- package/src/git-status-cache.ts +198 -0
- package/src/git-status-reader.ts +28 -0
- package/src/git-status.ts +72 -0
- package/src/header-controller.ts +58 -0
- package/src/header.ts +151 -0
- package/src/index.ts +1264 -0
- package/src/quota.ts +581 -0
- package/src/redraw-guard.ts +79 -0
- package/src/run-summary.ts +623 -0
- package/src/spinner.ts +72 -0
- package/src/status-style.ts +26 -0
- package/src/terminal-title.ts +67 -0
- package/src/tool-activity.ts +216 -0
- package/src/tool-adapter.ts +491 -0
- package/src/tool-groups.ts +192 -0
- package/src/tool-lexicon.ts +200 -0
- package/src/tool-view.ts +788 -0
- package/src/width.ts +246 -0
- package/themes/1337-amber.json +94 -0
- package/themes/1337-amber.pi1337 +3 -0
- package/themes/1337-cosmos.json +94 -0
- package/themes/1337-cosmos.pi1337 +3 -0
- package/themes/1337-cyber.json +94 -0
- package/themes/1337-cyber.pi1337 +3 -0
- package/themes/1337-cyberpunk-2077-edgerunner.json +94 -0
- package/themes/1337-cyberpunk-2077-edgerunner.pi1337 +7 -0
- package/themes/1337-cyberpunk-2077.json +94 -0
- package/themes/1337-cyberpunk-2077.pi1337 +7 -0
- package/themes/1337-fallout.json +94 -0
- package/themes/1337-fallout.pi1337 +4 -0
- package/themes/1337-ice.json +94 -0
- package/themes/1337-ice.pi1337 +3 -0
- package/themes/1337-magma.json +94 -0
- package/themes/1337-magma.pi1337 +1 -0
- package/themes/1337-neon.json +94 -0
- package/themes/1337-neon.pi1337 +3 -0
- package/themes/1337-poison.json +94 -0
- package/themes/1337-poison.pi1337 +3 -0
- package/themes/1337-skynet-dark.json +94 -0
- package/themes/1337-skynet-dark.pi1337 +4 -0
- package/themes/1337-skynet.json +94 -0
- package/themes/1337-skynet.pi1337 +4 -0
- package/themes/1337.json +95 -0
- package/themes/1337.pi1337 +3 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
pi-1337 reads extension settings from environment variables and an optional JSON file. A per-theme `.pi1337` sidecar holds spinner, background, and avatar settings that do not belong in Pi's theme schema.
|
|
4
|
+
|
|
5
|
+
## Extension settings
|
|
6
|
+
|
|
7
|
+
The default file is `~/.pi/agent/1337-theme/config.json`. Pi's `PI_CODING_AGENT_DIR` changes the base directory; `PI_1337_STATE_DIR` can set the config directory directly.
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"theme": "cyber",
|
|
12
|
+
"copyKey": "alt+c",
|
|
13
|
+
"polish": true,
|
|
14
|
+
"background": "off"
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Missing or invalid files fall back to defaults. Unknown keys and values with the wrong type are ignored. Environment values take precedence over their matching file settings.
|
|
19
|
+
|
|
20
|
+
| Environment variable | File key | Default | Behavior |
|
|
21
|
+
| --- | --- | --- | --- |
|
|
22
|
+
| `PI_1337_DISABLE` | `disable` | off | Any non-empty value disables the extension. |
|
|
23
|
+
| `PI_1337_POLISH` | `polish` | on | Set `off` to keep Pi's standard tool renderers; `on` enables compact tool rows and previews. |
|
|
24
|
+
| `PI_1337_ACTIVITY` | `activity` | on | Set `off` to stop naming long-running tools in the status row and to hide the run clock (`Working… 45s`). Read when the extension loads. |
|
|
25
|
+
| `PI_1337_GROUPS` | `groups` | on | Set `off` to keep one transcript row per tool call; `on` folds runs of three or more settled read/search/list rows into one tally row. Needs `PI_1337_POLISH`; read when the extension loads. |
|
|
26
|
+
| `PI_1337_THEME` | `theme` | on | Select a palette, use `off` to keep the current Pi theme, or leave unset to respect Pi's bundled `/settings` choice. All bundled palettes are dark: on a light Pi theme the package keeps that theme unless a palette is set here or `PI_1337_THEME` is `on`. |
|
|
27
|
+
| `PI_1337_COPY_KEY` | `copyKey` | `alt+c` | Set the key chord used to copy the editor's logical buffer. An empty value disables it. |
|
|
28
|
+
| `PI_1337_MAX_WIDTH` | `maxWidth` | 100 | Widest framed editor box in columns; `0` or `full` removes the cap. Values below 40 are raised to 40 and invalid values are ignored. Read when the extension loads. |
|
|
29
|
+
| `PI_1337_SUMMARY` | `summary` | on | Appends one summary row when a run that used tools, was interrupted or failed settles; `off` writes none and hides existing ones. The row is a custom session entry: it never reaches the model and stays in the session file. Read when the extension loads. |
|
|
30
|
+
| `PI_1337_TITLE` | `title` | on | Shows the run state in the terminal title (`● Running npm test… — repo`) and restores Pi's own title at rest; `off` never touches the title. Read when the extension loads. |
|
|
31
|
+
| `PI_1337_QUOTA` | `quota` | on | Shows the subscription quota the current provider reports in the status row: `5h 43% · wk 12%`, `wk 85%`, or `limit`. `off` registers no response or stream handler and leaves the row as it is. Read when the extension loads. |
|
|
32
|
+
| `PI_1337_STATUS_STYLE` | `statusStyle` | segmented | Palette-colored text and thin chevrons. Choose `classic` for the dotted row. |
|
|
33
|
+
| `PI_1337_HEADER` | `header` | on | Compact startup header with palette, workspace and command hints. `off` leaves the header alone. |
|
|
34
|
+
| `PI_1337_GIT_STATUS` | `gitStatus` | on | Cached Git change counters beside the branch. `off` starts no Git process. |
|
|
35
|
+
| `PI_1337_DRAFT_TOKENS` | `draftTokens` | off | Approximate size of long text drafts, using Pi's estimator and expanded pasted text; shown only when idle. |
|
|
36
|
+
| `PI_1337_THINKING_LABEL` | `thinkingLabel` | `∴ thinking` | Set the collapsed thinking label. |
|
|
37
|
+
| `PI_1337_BG` | `background` | theme | Set `on`/`auto` to use the palette background, `off` to leave the terminal unchanged, or a hex color such as `#101820`. |
|
|
38
|
+
| `PI_1337_STATE_DIR` | — | `<agent-dir>/1337-theme` | Set the directory containing `config.json`. |
|
|
39
|
+
|
|
40
|
+
### Theme selection
|
|
41
|
+
|
|
42
|
+
All thirteen palettes are available in `/settings`, and Pi persists that selection. With `PI_1337_THEME` unset, pi-1337 respects Pi's current bundled palette; a `theme` value in `config.json` seeds startup only when no bundled palette is already selected. An explicit `PI_1337_THEME` palette alias or full name pins that palette. `on` uses the current bundled choice or the default green palette; `off` leaves the current Pi theme in place while the editor redesign remains active.
|
|
43
|
+
|
|
44
|
+
Aliases include `green`, `amber`, `ice`, `cyber`/`blue`, `cyberpunk-2077`, `cyberpunk-2077-edgerunner`, `neon`, `cosmos`, `poison`, `magma`, `fallout`, `skynet`, and `skynet-dark`. Full names such as `1337-cyberpunk-2077` also work.
|
|
45
|
+
|
|
46
|
+
## Status presentation
|
|
47
|
+
|
|
48
|
+
The segmented style draws the path in the palette's accent color and the branch in its success color. Thin Unicode chevrons separate the labels on the terminal background. Both styles retain the same two groups and width priorities. The model stays in the top border, and the context percentage remains the last session metric to yield.
|
|
49
|
+
|
|
50
|
+
Git badges count staged (`+2`), modified (`~1`), untracked (`?1`) and conflicted (`!1`) entries. Clean repositories show no badge; unavailable, failed or incomplete probes show no claim about cleanliness. Untracked directories count as one entry, as in `git status --untracked-files=normal`. The read-only probe runs through Pi's public executor with optional Git locks disabled, a 1.5-second timeout and a 1 MiB output cap. Results are cached for one second during tool activity; activation, branch changes and run settlement force refreshes. Edits made externally while Pi is idle appear at the next such event; there is no polling timer. Counters yield before branch and session details on narrow screens.
|
|
51
|
+
|
|
52
|
+
With `draftTokens: true`, a draft of at least 256 estimated tokens shows a whole approximate label such as `~1.2k tok` in the idle left slot when it fits. This is Pi's conservative character-based estimate, not the model's tokenizer. Paste placeholders are expanded before estimating. It never changes the session context figure and disappears while Pi is working or waiting for a prompt response.
|
|
53
|
+
|
|
54
|
+
The header follows live palette changes and uses the editor's width cap and margins. Toggling the redesign off restores Pi's header if ours still owns the slot; a header installed later by another extension is left alone. Pi exposes no getter for a previously installed custom header, so an earlier extension's header cannot be restored automatically. Disable our header when another extension should own it.
|
|
55
|
+
|
|
56
|
+
These settings are read when the extension loads; use `/reload` after changing them.
|
|
57
|
+
|
|
58
|
+
## Activity label and tool grouping
|
|
59
|
+
|
|
60
|
+
While Pi works, a tool call that has been running for half a second is named in the status row, in the workspace segment's place: `Running npm test…`, `Reading stats.py…`, after three seconds with the elapsed time (`Running npm test… 14s`), and with ` +2` when other calls run beside it. The right group (usage, cost, persona) never moves for it, fast calls never flash, and the workspace returns when the call ends. The label comes only from Pi's tool events and adds no timer. When no tool is named and the run has lasted three seconds, the same place shows the run clock, `Working… 45s`; it counts from the run's start, and is hidden during prompts and compaction and for a run that began while the redesign was toggled off. `PI_1337_ACTIVITY=off` (config `activity: false`) hides both.
|
|
61
|
+
|
|
62
|
+
Three or more consecutive `read`, `grep`, `find`, or `ls` rows fold into one tally row — `● Read 3 files, searched 2 patterns (ctrl+o to expand)` — as soon as the third one settles. The tally stays in place and counts up while the run goes on; a call still running keeps its own row. Anything that paints a row ends a run: `bash`, `edit`, `write`, custom tools (their rows never fold, including those drawn in the flat frame), a message, or a thinking row. Failed calls and results with image attachments always keep their own rows. The tally names its files when the whole row fits (`Read width.ts, frame.ts · searched 2 patterns`) and counts them otherwise; it counts distinct files and patterns, so paging one file three times reads `Read 1 file`. Left-clicking the tally brings that run back; the host's expand key (Ctrl+O) shows every row; history rebuilt on resume, tree navigation, or compaction stays unfolded. `PI_1337_GROUPS=off` (config `groups: false`) disables folding; it also needs `PI_1337_POLISH`, which owns the tool rows.
|
|
63
|
+
|
|
64
|
+
## Subscription quota
|
|
65
|
+
|
|
66
|
+
When the current provider reports subscription usage, the status row shows it between the cost and the persona as percent used: `5h 43% · wk 12%` (five-hour and weekly windows), `wk 85%` when only one window is known, or `limit` once the provider says the usage limit is reached. Above 70% the percentage takes the warning color and above 90% the error color; a figure not confirmed for thirty minutes turns dim while it is calm.
|
|
67
|
+
|
|
68
|
+
It is read only from what the provider already sends with a response, so it appears after the first response, never before, and the extension makes no request of its own. Seen on live accounts: Anthropic's subscription headers (the weekly window) and OpenAI's usage-limit error on a ChatGPT login. Implemented from the published Codex client format but not yet seen live: the Codex rate-limit headers and stream event, and Anthropic's five-hour window. Providers that report nothing — z.ai, OpenRouter and other pay-per-use routes — show nothing, and a generic rate-limit error is not treated as a subscription limit. The plan, the absolute limit and the time a `limit` lifts are not known.
|
|
69
|
+
|
|
70
|
+
Set `PI_1337_QUOTA=off` (or `"quota": false`) to turn it off; the row is then exactly as it is without the feature.
|
|
71
|
+
|
|
72
|
+
## Theme sidecars
|
|
73
|
+
|
|
74
|
+
For a theme file named `my-theme.json`, place optional extension settings in `my-theme.pi1337` beside it. The sidecar is JSON but uses a non-`.json` extension so Pi does not load it as another palette.
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"spinner": {
|
|
79
|
+
"frames": ["·", "•", "●", "•"],
|
|
80
|
+
"intervalMs": 120
|
|
81
|
+
},
|
|
82
|
+
"background": "on",
|
|
83
|
+
"avatar": {
|
|
84
|
+
"working": ["[ thinking ]"]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Every bundled palette has a spinner profile. Cyberpunk 2077, Edgerunner, Fallout, Skynet, and Skynet Dark also opt into tinting the terminal background. Bundled palettes do not configure avatars.
|
|
90
|
+
|
|
91
|
+
Selecting a different palette in `/settings` loads its sidecar. After editing a sidecar in place, use `/reload`.
|
|
92
|
+
|
|
93
|
+
### Background tint
|
|
94
|
+
|
|
95
|
+
Tint is off unless enabled by a config value or the active theme sidecar. `PI_1337_BG` or the `background` setting overrides the sidecar: `on`/`auto` uses the palette's `void` color, a valid `#rgb` or `#rrggbb` sets an explicit tint, and `off` disables tinting. The extension resets the tint when its redesign is turned off or Pi shuts down.
|
|
96
|
+
|
|
97
|
+
### Optional avatar
|
|
98
|
+
|
|
99
|
+
Avatars are user-configured widgets; none are included in the bundled palettes. Use ASCII lines or an image path in `avatar` frames. For example, the `working` frame above appears while the model is working and falls back to `idle` if configured. Paths are resolved relative to the theme file.
|
|
100
|
+
|
|
101
|
+
Avatar objects accept optional `align` (`left` or `center`) and `placement` (`belowEditor` or `aboveEditor`) settings. The default placement is below the editor. Image display depends on terminal image support; configure ASCII lines as a fallback when needed.
|
|
102
|
+
|
|
103
|
+
See [theme motion profiles](theme-motion.md) for accepted spinner frame shapes, geometry limits, and timing.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Palette design
|
|
2
|
+
|
|
3
|
+
Thirteen palette names are registered, and all thirteen share Pi's strict 51-token contract. Twelve use vivid chromatic colors over deep, family-specific surfaces; the Terminator 2 HUD palette uses warm-white text on red-tinted black. Tool output remains legible body text, semantic status roles stay distinct, and no palette ships images.
|
|
4
|
+
|
|
5
|
+
## Palette anchors
|
|
6
|
+
|
|
7
|
+
| Theme | Void / panel / selection | Body / accent | Success / error / warning / highlight |
|
|
8
|
+
|---|---|---|---|
|
|
9
|
+
| `1337` | `#04140b` / `#0b2614` / `#123a22` | `#78ef74` / `#ffc35c` | `#4bd878` / `#ff9c78` / `#ffe55c` / `#c6ffd5` |
|
|
10
|
+
| `1337-amber` | `#171009` / `#281d11` / `#3b2d19` | `#ffbd68` / `#ffdda0` | `#a6df62` / `#ff765e` / `#ffeb3b` / `#fff0c5` |
|
|
11
|
+
| `1337-ice` | `#0b151d` / `#142630` / `#263b47` | `#9de4ff` / `#aff5ff` | `#71e8c0` / `#ff8c9c` / `#ffe36d` / `#d8f8ff` |
|
|
12
|
+
| `1337-cyber` | `#0b1022` / `#151c34` / `#202b43` | `#8baeff` / `#42e8ff` | `#75e6b6` / `#ff718f` / `#ffe36d` / `#dce4ff` |
|
|
13
|
+
| `1337-cyberpunk-2077` | `#000000` / `#111000` / `#211c00` | `#fcee0a` / `#52c9ff` | `#ffe56b` / `#ff5364` / `#ff8a00` / `#fff09a` |
|
|
14
|
+
| `1337-cyberpunk-2077-edgerunner` | `#100307` / `#1d0710` / `#2c0b18` | `#ff8995` / `#00e6e6` | `#ffd43b` / `#ff5368` / `#ff8c00` / `#ffe65a` |
|
|
15
|
+
| `1337-neon` | `#170f21` / `#291b39` / `#3d2c50` | `#e589ff` / `#ff62da` | `#6bdf9a` / `#ff759b` / `#ffe36d` / `#ffe0ff` |
|
|
16
|
+
| `1337-cosmos` | `#11111b` / `#1a1a30` / `#292a3e` | `#ccaaff` / `#f9e2af` | `#a6e3a1` / `#f38ba8` / `#fab387` / `#e4e9fc` |
|
|
17
|
+
| `1337-poison` | `#091610` / `#14271d` / `#302439` | `#69f29a` / `#e17bff` | `#59d98a` / `#ff718f` / `#ffe36d` / `#d5ffe2` |
|
|
18
|
+
| `1337-magma` | `#160d0b` / `#271711` / `#3a2319` | `#ff9876` / `#46e5df` | `#69df97` / `#ff677e` / `#ffd166` / `#ffe0c9` |
|
|
19
|
+
| `1337-fallout` | `#111608` / `#202a12` / `#303d1d` | `#c8f96c` / `#e7ff72` | `#90d83e` / `#ff9a4d` / `#ffdc35` / `#f2ffd0` |
|
|
20
|
+
| `1337-skynet` | `#0c0304` / `#25070a` / `#451016` | `#fff1ed` / `#ff5f6b` | `#ffb8b3` / `#ff8a9d` / `#ffe5df` / `#ffd3cf` |
|
|
21
|
+
| `1337-skynet-dark` | `#090103` / `#160406` / `#25080c` | `#ff817d` / `#ff5964` | `#ff9185` / `#ff69a4` / `#ffb5ad` / `#ffaba5` |
|
|
22
|
+
|
|
23
|
+
The default `1337` palette takes its visual direction from the green P39 phosphor and long-persistence monochrome displays of early IBM PCs. Its yellow-green body and deep green surfaces keep that CRT character; amber/gold UI accents are a deliberate design adaptation, not a claim that the original monochrome hardware displayed multiple colors. Poison remains more emerald, with orchid and cyan syntax; the identity test keeps their body and accent hues in separate families.
|
|
24
|
+
|
|
25
|
+
Cyber uses periwinkle text, electric-cyan accents, lavender keywords, and blue-indigo surfaces. The screenshots in the [Cyberpunk 2077 inspired theme post on r/S24Ultra](https://www.reddit.com/r/S24Ultra/comments/1g2krv1/cyberpunk_2077_inspired_theme/) use black fields, dominant bright yellow, and cyan-blue accents. This palette adapts that visual hierarchy with a neon-yellow body, a cyan-blue accent, and contrast-adjusted semantic roles; it is a terminal interpretation, not an exact game or phone theme reproduction.
|
|
26
|
+
|
|
27
|
+
The Edgerunner variant takes visual direction from the Blender theme [Cyberpunk2077 by mamane-kabirou](https://extensions.blender.org/themes/cyberpunk2077/). The reference screenshots combine dark burgundy-red surfaces and muted red interface text with yellow labels and cyan highlights. The terminal palette interprets those color relationships with a muted red body (`#ff8995`), yellow titles (`#ffe65a`), cyan accent (`#00e6e6`), and burgundy-black surfaces; it does not reuse the Blender theme's XML.
|
|
28
|
+
|
|
29
|
+
Neon combines violet and hot pink with cyan syntax; Fallout stays yellow-lime rather than emerald. Magma pairs molten coral-orange with cyan accents on warm charcoal. Skynet follows the Terminator 2 diagnostic view: warm-white HUD text over red-tinted black footage, with crimson accents. Skynet Dark retains a red body on near-black surfaces as a separate palette. These are color interpretations of the references, not exact scene or hardware reproductions.
|
|
30
|
+
|
|
31
|
+
## Contrast and hierarchy
|
|
32
|
+
|
|
33
|
+
`test/theme.test.ts` measures colors against intended dark surfaces. Required floors are 7:1 for body/tool output on void and pending/success/error tool panels and for user/custom message text on its associated background; 4.5:1 for dim/muted on void, panel, selection, and tool panels; 4.5:1 for syntax, diff, and status roles on their defined surfaces. The tests also enforce text/secondary/status contrast against representative untinted terminal `#1e1e1e`, separation of semantic pairs by at least 8 OKLab ΔE × 100, and luminance ordering `border < dim < muted < text` with existing tier gaps.
|
|
34
|
+
|
|
35
|
+
The twelve chromatic palettes keep an RGB channel range of at least 85 and HSL saturation of at least 60%. Skynet's warm-white body has its own HUD color checks; Skynet Dark remains covered by the red-body vividness guard. These are project identity and contrast checks, not an accessibility claim for arbitrary terminal backgrounds.
|
|
36
|
+
|
|
37
|
+
Across the thirteen current palettes, the observed minimums are 7.14:1 for body/tool output (Neon), 7.14:1 for user/custom message text (Neon), 4.58:1 for dim/muted (Cosmos), 5.19:1 for syntax (Cosmos), 5.92:1 for diff roles (Cyberpunk 2077), 4.78:1 for status roles (Neon), and 4.68:1 for secondary text against untinted `#1e1e1e` (Edgerunner). Cyberpunk 2077 measures 15.19:1 for body/tool output, 16.56:1 / 15.38:1 for user/custom message text, 5.26:1 / 9.78:1 for dim/muted, 5.66:1 for syntax, 5.92:1 for diff roles, 5.42:1 for status roles, and 5.14:1 for dim text against untinted `#1e1e1e`. Edgerunner measures 8.24:1 for body/tool output, 5.05:1 / 6.58:1 for dim/muted, 5.25:1 for syntax, 5.73:1 for status roles, and 4.68:1 for dim text against untinted `#1e1e1e`. Every palette exceeds the corresponding test floor.
|
|
38
|
+
|
|
39
|
+
## Inspiration references
|
|
40
|
+
|
|
41
|
+
The palette combinations are original, informed by the references below.
|
|
42
|
+
|
|
43
|
+
- Cosmos takes its swatches from the cover art and pill bar of [pi-starline](https://github.com/Andy8647/pi-starline) (MIT), which are the [Catppuccin](https://github.com/catppuccin/palette) Mocha colors (MIT): crust `#11111b` for the page, surface1 `#45475a` for rules, subtext0 `#a6adc8` for secondary text, text `#cdd6f4` for the user's own messages, and the green, peach, red, yellow, blue, lavender, pink and teal pastels for status, syntax and the thinking ramp. Catppuccin's text color is too neutral for this family's vividness rule, so the body is its mauve pushed to `#ccaaff`; the panel, selection, tool bands and dim steps are derived. The star-gold accent on cool surfaces is what separates it from Cyber and Neon.
|
|
44
|
+
|
|
45
|
+
- [IBM 5150 Technical Reference (August 1981), monochrome display section](https://www.minuszerodegrees.net/manuals/IBM_5150_Technical_Reference_6025005_AUG81.pdf) and the [Centre for Computing History's IBM 5151 display entry](https://www.computinghistory.org.uk/det/39463/IBM-5151-Personal-Computer-Display/) describe the period's persistent green monochrome CRT direction behind the default palette.
|
|
46
|
+
- The [Cyberpunk 2077 inspired theme post on r/S24Ultra](https://www.reddit.com/r/S24Ultra/comments/1g2krv1/cyberpunk_2077_inspired_theme/) is the visual reference for black fields, dominant yellow, and cyan-blue accents. This is a community phone-theme interpretation, not an official Cyberpunk 2077 color specification.
|
|
47
|
+
- The [Cyberpunk2077 theme for Blender by mamane-kabirou](https://extensions.blender.org/themes/cyberpunk2077/) informs the Edgerunner variant's burgundy-red, yellow, and cyan hierarchy; only the visual direction is reused, not its XML theme code.
|
|
48
|
+
- The Skynet HUD interpretation references a [Terminator 2 still and discussion of the T-800 HUD](https://scifi.stackexchange.com/questions/68511/why-does-the-terminator-t-800-have-a-hud) and a [production-effects account of the film's black/white/red image process](https://www.sideshow.com/blog/how-terminator-2-achieved-iconic-special-effects). These guide the warm-white diagnostic text and red-tinted-black surfaces; no specific scene is reproduced exactly.
|
|
49
|
+
- [Color Hunt's neon black/purple palettes](https://colorhunt.co/palettes/neon-black-purple) and [SchemeColor's dark cyan/orange palette](https://www.schemecolor.com/dark-cyan-and-orange.php) informed Neon and Magma color studies.
|
|
50
|
+
- [Color Hunt: charcoal, cyan, and light neutral](https://colorhunt.co/palette/222831393e4600adb5eeeeee) and [Coolors: navy-to-cyan sequence](https://coolors.co/palette/0b132b-1c2541-3a506b-5bc0be-6fffe9) are harmony references for dark structure with crisp cyan counterpoints.
|
|
51
|
+
- [Coolors: muted green sequence](https://coolors.co/palette/cad2c5-84a98c-52796f-354f52-2f3e46) informs layered green surfaces, not foreground saturation; [MyColor.Space](https://mycolor.space/) is a seed-driven complementary/shade exploration tool.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Theme-driven text motion
|
|
2
|
+
|
|
3
|
+
Bundled themes use text spinners, not PNG mascots. Glyphs and timing come from
|
|
4
|
+
the adjacent `.pi1337` sidecar; color defaults to the active palette's `accent`
|
|
5
|
+
token, with an optional validated RGB override. There is only one animation
|
|
6
|
+
timer.
|
|
7
|
+
|
|
8
|
+
| Theme | Motion | Interval | Reserved cells |
|
|
9
|
+
|---|---|---:|---:|
|
|
10
|
+
| `1337` | Braille rotation | 90 ms | 1 |
|
|
11
|
+
| `1337-amber` | ASCII baton | 120 ms | 1 |
|
|
12
|
+
| `1337-ice` | Quarter circles: `◴ ◷ ◶ ◵` | 150 ms | 1 |
|
|
13
|
+
| `1337-cyber` | Pulse: `· • ● •` | 140 ms | 1 |
|
|
14
|
+
| `1337-cyberpunk-2077` | Electric ladder bars: `▁▃▅` → `▃▅▇` → `▅▇▁` → `▇▁▃` → `▅▂▆` → `▃▅▇` | 140 ms | 3 |
|
|
15
|
+
| `1337-cyberpunk-2077-edgerunner` | Electric ladder bars: `▁▃▅` → `▃▅▇` → `▅▇▁` → `▇▁▃` → `▅▂▆` → `▃▅▇` | 140 ms | 3 |
|
|
16
|
+
| `1337-neon` | Diamonds: `◇ ◈ ◆ ◈` | 160 ms | 1 |
|
|
17
|
+
| `1337-cosmos` | Twinkling star: `⋆ ✧ ✦ ✧` | 180 ms | 1 |
|
|
18
|
+
| `1337-poison` | Half circles: `◐ ◓ ◑ ◒` | 140 ms | 1 |
|
|
19
|
+
| `1337-magma` | Heat bars: `▁▃▆` | 120 ms | 3 |
|
|
20
|
+
| `1337-fallout` | Pixel rotation: `▖ ▘ ▝ ▗` | 150 ms | 1 |
|
|
21
|
+
| `1337-skynet` | Pyramid: one triangle above two | 180 ms | 3 |
|
|
22
|
+
| `1337-skynet-dark` | Pyramid: one triangle above two | 180 ms | 3 |
|
|
23
|
+
|
|
24
|
+
Both Skynet profiles activate one triangle at a time:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
▲ △ △
|
|
28
|
+
△ △ ▲ △ △ ▲
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Both Skynet profiles use the crimson `#ff5f6b` pyramid. All other profiles
|
|
32
|
+
use their palette's semantic accent. Cyberpunk 2077 uses a cyan-blue accent
|
|
33
|
+
(`#52c9ff`), and Edgerunner uses a cyan accent (`#00e6e6`). The explicit color
|
|
34
|
+
override belongs only to the Skynet sidecars, not either theme palette.
|
|
35
|
+
|
|
36
|
+
## Configure a profile
|
|
37
|
+
|
|
38
|
+
For `my-theme.json`, put the profile in `my-theme.pi1337`:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"spinner": {
|
|
43
|
+
"frames": [[" ▲ ", "△ △"], [" △ ", "▲ △"], [" △ ", "△ ▲"]],
|
|
44
|
+
"intervalMs": 180,
|
|
45
|
+
"color": "#ff5f6b"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Frames may be legacy single-row strings or explicit arrays of one or two row
|
|
51
|
+
strings, for example `[" ▲ ", "△ △"]`. Every frame must have the same height;
|
|
52
|
+
each row must have the same host-measured width of 1–3 columns. Controls, bidi
|
|
53
|
+
characters, tabs, blank rows/frames, and unequal geometry are rejected. Raw
|
|
54
|
+
newlines are never accepted. Each row is limited to 256 UTF-16 code units, with
|
|
55
|
+
1–32 frames total. `color`, when present, must be exactly `#RRGGBB`; invalid
|
|
56
|
+
profiles fall back to the standard braille spinner. The interval defaults to
|
|
57
|
+
90 ms and must be between 60 and 500 ms.
|
|
58
|
+
|
|
59
|
+
A two-row animation reserves its indicator width plus one cell on the status
|
|
60
|
+
row (four cells for both Skynet profiles), even when idle or waiting. This reduces the status
|
|
61
|
+
layout budget without changing the input
|
|
62
|
+
viewport. When there is one input row and no menu, the lower art occupies the
|
|
63
|
+
right side of the existing status row. With at least two content rows, it uses
|
|
64
|
+
the second content row. Autocomplete never gains a row or changes suggestion
|
|
65
|
+
indices: if only one content row is available while a menu is open, the compact
|
|
66
|
+
fallback displays only the top triangle. Waiting displays `?` on top and clears
|
|
67
|
+
the bottom row. The extra reserved gutter cell can carry a down-scroll marker
|
|
68
|
+
beside the lower triangle.
|
|
69
|
+
|
|
70
|
+
## Layout and lifecycle
|
|
71
|
+
|
|
72
|
+
The editor reserves the profile's indicator width even while idle or waiting.
|
|
73
|
+
Starting or stopping motion therefore does not shift the cursor, rewrap input,
|
|
74
|
+
or change the mouse viewport. At extremely narrow widths, the normal bare-editor
|
|
75
|
+
fallback remains available.
|
|
76
|
+
|
|
77
|
+
A blocking prompt pauses motion and shows a static `?`. Manual compaction uses
|
|
78
|
+
the same timer. Motion stops on settlement, disable and shutdown—not merely on
|
|
79
|
+
`agent_end`, because retries and queued work may follow. A live theme change
|
|
80
|
+
resets the frame and resumes only if work is active and no prompt is blocking.
|
|
81
|
+
|
|
82
|
+
Selecting another theme through `/settings` loads its profile. After editing a
|
|
83
|
+
sidecar in place, use `/reload`. RPC, JSON and print modes do not start the timer.
|
|
84
|
+
|
|
85
|
+
The visual references were [Skynet Hunter](https://github.com/paullaudeman/skynet-hunter)
|
|
86
|
+
and the [CLI/ASCII spinner collection](https://codepen.io/moritzjacobs/pen/WXBPxO).
|
|
87
|
+
These profiles are an original text implementation; no upstream renderer code,
|
|
88
|
+
CSS animation or image assets are bundled.
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeondave/pi-theme-1337",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Thirteen vivid themes for Pi with a framed editor, compact tool views, theme-aware diffs, and configurable text spinners.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"pi-package",
|
|
9
|
+
"pi-extension",
|
|
10
|
+
"pi-theme",
|
|
11
|
+
"pi-themes",
|
|
12
|
+
"pi-coding-agent",
|
|
13
|
+
"theme",
|
|
14
|
+
"dark-theme",
|
|
15
|
+
"terminal-theme",
|
|
16
|
+
"statusline",
|
|
17
|
+
"phosphor",
|
|
18
|
+
"minimal",
|
|
19
|
+
"tui"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "AeonDave"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/AeonDave/pi-theme-1337.git"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"src",
|
|
31
|
+
"themes",
|
|
32
|
+
"docs",
|
|
33
|
+
"assets/banner.png",
|
|
34
|
+
"assets/palettes.gif",
|
|
35
|
+
"README.md",
|
|
36
|
+
"CHANGELOG.md"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"test": "node --import tsx --test \"test/*.test.ts\"",
|
|
41
|
+
"test:parity": "node --import tsx test/parity.ts",
|
|
42
|
+
"preview": "node --import tsx test/preview.ts"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
46
|
+
"@earendil-works/pi-tui": "*"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@earendil-works/pi-coding-agent": "1.7.0",
|
|
50
|
+
"@earendil-works/pi-tui": "1.7.0",
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"tsx": "^4.23.15",
|
|
53
|
+
"typescript": "^7.0.2"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=22.19.0"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"pi": {
|
|
62
|
+
"image": "https://raw.githubusercontent.com/AeonDave/pi-theme-1337/v0.6.0/assets/banner.png",
|
|
63
|
+
"extensions": [
|
|
64
|
+
"./src/index.ts"
|
|
65
|
+
],
|
|
66
|
+
"themes": [
|
|
67
|
+
"./themes"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/avatar.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure parsing/selection for the theme-driven avatar.
|
|
3
|
+
*
|
|
4
|
+
* These palettes are themes *for* pi-1337, so a theme file may carry a
|
|
5
|
+
* `pi1337.avatar` — a small mascot shown in a widget above the editor that
|
|
6
|
+
* reacts to the agent (e.g. a Fallout Vault-Boy: thumbs-up while the model is
|
|
7
|
+
* answering, thumbs-down when idle). A frame is either a PNG (`{ image }`,
|
|
8
|
+
* rendered via the terminal image protocol) or ASCII (`{ lines }`, for terminals
|
|
9
|
+
* with no image support). This module only turns the raw JSON value into frames
|
|
10
|
+
* picks one for the current state, and computes image cells for centering;
|
|
11
|
+
* index.ts owns loading/encoding + the widget + coloring.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { sanitizeArtLine } from "./format.ts";
|
|
15
|
+
import { isImageProtocolLine, truncateToWidth, visibleWidth } from "./width.ts";
|
|
16
|
+
|
|
17
|
+
export interface AvatarLayoutOptions {
|
|
18
|
+
align?: "left" | "center";
|
|
19
|
+
/** Cell width reserved by Pi's image renderer; ignored for textual fallbacks. */
|
|
20
|
+
imageColumns?: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Compose Pi's rendered image or ASCII rows in the widget's available columns.
|
|
25
|
+
* Image.render can return ordinary text even with an active image protocol:
|
|
26
|
+
* only actual image payloads use imageColumns and bypass text clipping.
|
|
27
|
+
*/
|
|
28
|
+
export function layoutAvatarRows(lines: readonly string[], width: number, options: AvatarLayoutOptions = {}): string[] {
|
|
29
|
+
const columns = Math.max(0, Math.floor(width));
|
|
30
|
+
if (columns === 0) return lines.map(() => "");
|
|
31
|
+
// Without known image geometry, omit centering rather than invent spare room.
|
|
32
|
+
const imageSpan = options.imageColumns !== undefined && Number.isFinite(options.imageColumns) && options.imageColumns > 0
|
|
33
|
+
? Math.ceil(options.imageColumns)
|
|
34
|
+
: columns;
|
|
35
|
+
const rows = lines.map((line) => ({ line, image: isImageProtocolLine(line) }));
|
|
36
|
+
const span = rows.reduce((max, row) => Math.max(max, row.image ? imageSpan : visibleWidth(row.line)), 0);
|
|
37
|
+
const pad = options.align === "center" ? Math.max(0, Math.floor((columns - span) / 2)) : 0;
|
|
38
|
+
const room = columns - pad;
|
|
39
|
+
const prefix = " ".repeat(pad);
|
|
40
|
+
return rows.map(({ line, image }) => {
|
|
41
|
+
if (!line) return line; // preserve Pi's empty image-height reservations
|
|
42
|
+
// A stale/oversized image cannot be clipped safely; omit the complete payload.
|
|
43
|
+
if (image) return imageSpan <= columns ? prefix + line : "";
|
|
44
|
+
return prefix + truncateToWidth(line, room, "");
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Image width in cells for centering beside pi-tui's Image component. */
|
|
49
|
+
export function avatarImageColumns(
|
|
50
|
+
dims: { widthPx: number; heightPx: number },
|
|
51
|
+
cell: { widthPx: number; heightPx: number },
|
|
52
|
+
maxWidth: number,
|
|
53
|
+
maxHeight: number,
|
|
54
|
+
protocol: "kitty" | "iterm2" | null | undefined,
|
|
55
|
+
): number {
|
|
56
|
+
const iw = Math.max(1, dims.widthPx);
|
|
57
|
+
const ih = Math.max(1, dims.heightPx);
|
|
58
|
+
const widthCap = Math.max(1, Math.floor(maxWidth));
|
|
59
|
+
const heightCap = Math.max(1, Math.floor(maxHeight));
|
|
60
|
+
const widthScale = (widthCap * cell.widthPx) / iw;
|
|
61
|
+
const heightScale = (heightCap * cell.heightPx) / ih;
|
|
62
|
+
const scale = Math.min(widthScale, heightScale);
|
|
63
|
+
const upper = Math.max(1, Math.min(widthCap, Math.ceil((iw * scale) / cell.widthPx)));
|
|
64
|
+
if (protocol !== "kitty" || widthScale <= heightScale || upper <= 1) return upper;
|
|
65
|
+
// Pi's Kitty renderer chooses the less-distorted of the two neighbouring
|
|
66
|
+
// cell widths when the image is height-constrained; iTerm2 keeps the ceil.
|
|
67
|
+
const rows = Math.min(heightCap, Math.max(1, Math.ceil((ih * scale) / cell.heightPx)));
|
|
68
|
+
const ideal = (rows * cell.heightPx * iw) / (ih * cell.widthPx);
|
|
69
|
+
const lower = upper - 1;
|
|
70
|
+
const distortion = (count: number) => Math.max(count / ideal, ideal / count);
|
|
71
|
+
return distortion(lower) < distortion(upper) ? lower : upper;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One avatar frame: a PNG path OR literal ASCII lines (image preferred when both). */
|
|
75
|
+
export interface AvatarSource {
|
|
76
|
+
/** Path to a PNG (absolute, or relative to the theme file). */
|
|
77
|
+
image?: string;
|
|
78
|
+
/** ASCII fallback lines, used when the terminal has no image protocol. */
|
|
79
|
+
lines?: string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The task-lifecycle states the avatar can reflect. */
|
|
83
|
+
export type AvatarState = "idle" | "working" | "confused" | "error";
|
|
84
|
+
|
|
85
|
+
/** Per-state frames. A missing state falls back down the chain (see `selectAvatar`). */
|
|
86
|
+
export interface AvatarFrames {
|
|
87
|
+
/** Shown at rest / on startup (e.g. a friendly wink). */
|
|
88
|
+
idle?: AvatarSource;
|
|
89
|
+
/** Shown while the model is producing a response. Falls back to `idle`. */
|
|
90
|
+
working?: AvatarSource;
|
|
91
|
+
/** Shown during context compaction ("thinking hard"). Falls back to `working` → `idle`. */
|
|
92
|
+
confused?: AvatarSource;
|
|
93
|
+
/** Shown when the turn hit a tool error. Falls back to `idle`. */
|
|
94
|
+
error?: AvatarSource;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const IMAGE_EXT = /\.(png|jpe?g|gif|webp)$/i;
|
|
98
|
+
|
|
99
|
+
/** Coerce a JSON art value (a string with newlines, or an array of lines) to lines. */
|
|
100
|
+
function toLines(value: unknown): string[] | undefined {
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
|
+
const lines = value.filter((v): v is string => typeof v === "string").map(sanitizeArtLine);
|
|
103
|
+
return lines.length > 0 ? lines : undefined;
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === "string" && value.length > 0) return value.split("\n").map(sanitizeArtLine);
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Parse one frame: a path string → image; a newline string / array → ASCII; an object → explicit. */
|
|
110
|
+
function parseSource(value: unknown): AvatarSource | undefined {
|
|
111
|
+
if (typeof value === "string") {
|
|
112
|
+
const s = value.trim();
|
|
113
|
+
if (!s) return undefined;
|
|
114
|
+
if (IMAGE_EXT.test(s)) return { image: s };
|
|
115
|
+
return { lines: value.split("\n").map(sanitizeArtLine) };
|
|
116
|
+
}
|
|
117
|
+
if (Array.isArray(value)) {
|
|
118
|
+
const lines = toLines(value);
|
|
119
|
+
return lines ? { lines } : undefined;
|
|
120
|
+
}
|
|
121
|
+
if (value && typeof value === "object") {
|
|
122
|
+
const obj = value as Record<string, unknown>;
|
|
123
|
+
const image = typeof obj.image === "string" && obj.image.trim() ? obj.image.trim() : undefined;
|
|
124
|
+
const lines = toLines(obj.lines);
|
|
125
|
+
if (image || lines) return { image, lines };
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Parse a theme's `pi1337.avatar` into frames, or `undefined` when the theme
|
|
132
|
+
* ships none (the common case — the widget then never appears). A bare frame
|
|
133
|
+
* (path string / ASCII / `{ image|lines }`) is treated as an always-on avatar
|
|
134
|
+
* (same idle and working); an object `{ idle?, working? }` gives per-state
|
|
135
|
+
* control — e.g. `{ working }` alone makes it appear only while the model answers.
|
|
136
|
+
*/
|
|
137
|
+
export function parseAvatar(raw: unknown): AvatarFrames | undefined {
|
|
138
|
+
if (raw === undefined || raw === null) return undefined;
|
|
139
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
140
|
+
const obj = raw as Record<string, unknown>;
|
|
141
|
+
if ("idle" in obj || "working" in obj || "confused" in obj || "error" in obj) {
|
|
142
|
+
const frames: AvatarFrames = {
|
|
143
|
+
idle: parseSource(obj.idle),
|
|
144
|
+
working: parseSource(obj.working),
|
|
145
|
+
confused: parseSource(obj.confused),
|
|
146
|
+
error: parseSource(obj.error),
|
|
147
|
+
};
|
|
148
|
+
return frames.idle || frames.working || frames.confused || frames.error ? frames : undefined;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const bare = parseSource(raw); // path / ASCII / {image|lines} → pinned in both states
|
|
152
|
+
return bare ? { idle: bare, working: bare } : undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* The frame to show for `state`, or `undefined` to hide the widget. Each state
|
|
157
|
+
* falls back toward the always-present `idle` frame, so a theme can ship as few
|
|
158
|
+
* as one frame: `working`→`idle`, `confused`→`working`→`idle`, `error`→`idle`.
|
|
159
|
+
* `idle` never borrows another state's frame — a `{ working }`-only avatar stays
|
|
160
|
+
* hidden at rest (the "appears when the AI responds" behavior).
|
|
161
|
+
*/
|
|
162
|
+
export function selectAvatar(frames: AvatarFrames | undefined, state: AvatarState): AvatarSource | undefined {
|
|
163
|
+
if (!frames) return undefined;
|
|
164
|
+
switch (state) {
|
|
165
|
+
case "working":
|
|
166
|
+
return frames.working ?? frames.idle;
|
|
167
|
+
case "confused":
|
|
168
|
+
return frames.confused ?? frames.working ?? frames.idle;
|
|
169
|
+
case "error":
|
|
170
|
+
return frames.error ?? frames.idle;
|
|
171
|
+
default:
|
|
172
|
+
return frames.idle;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the optional terminal-background tint.
|
|
3
|
+
*
|
|
4
|
+
* A Pi *theme* can only color the cells Pi draws (per-widget backgrounds); the
|
|
5
|
+
* window's own background — including the empty margins around the framed editor
|
|
6
|
+
* — belongs to the terminal emulator. As an *extension* we can still tint it with
|
|
7
|
+
* OSC 11 (`ESC ] 11 ; <color> BEL`), the same out-of-band channel pi-tui uses to
|
|
8
|
+
* *query* the background. This is opt-in and must always be undone (OSC 111
|
|
9
|
+
* resets to the terminal default), so the sequences live here, dependency-free
|
|
10
|
+
* and unit-tested, while index.ts owns the write + the reversal.
|
|
11
|
+
*
|
|
12
|
+
* Only a solid color is portable. A background *image* has no app-level escape
|
|
13
|
+
* that sits behind the text across terminals (kitty/iTerm image protocols draw
|
|
14
|
+
* inline content, not a backdrop) — it stays the emulator's own config.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// OSC 11: set the default background color. BEL-terminated to match pi-tui's own
|
|
18
|
+
// OSC emitter (its `\x1b]11;?\x07` query), which every target terminal accepts.
|
|
19
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: escape-sequence literal
|
|
20
|
+
const OSC = "\x1b]";
|
|
21
|
+
const BEL = "\x07";
|
|
22
|
+
|
|
23
|
+
/** OSC 111: reset the background color to the terminal's configured default. */
|
|
24
|
+
export const OSC11_RESET = `${OSC}111${BEL}`;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Normalize a hex color to lowercase `#rrggbb`, expanding the `#rgb` shorthand.
|
|
28
|
+
* Returns `undefined` for anything that isn't a 3- or 6-digit hex color, so a
|
|
29
|
+
* malformed value can never be written to the terminal.
|
|
30
|
+
*/
|
|
31
|
+
export function normalizeHex(input: string | undefined): string | undefined {
|
|
32
|
+
if (!input) return undefined;
|
|
33
|
+
const s = input.trim().toLowerCase();
|
|
34
|
+
const m3 = /^#([0-9a-f]{3})$/.exec(s);
|
|
35
|
+
if (m3) {
|
|
36
|
+
const [r, g, b] = m3[1];
|
|
37
|
+
return `#${r}${r}${g}${g}${b}${b}`;
|
|
38
|
+
}
|
|
39
|
+
return /^#[0-9a-f]{6}$/.test(s) ? s : undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Build the OSC 11 sequence that tints the terminal background to `hex`. */
|
|
43
|
+
export function osc11Set(hex: string): string {
|
|
44
|
+
return `${OSC}11;${hex}${BEL}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Settings that read as "do not tint" from either the env var or the theme. */
|
|
48
|
+
const BG_FALSY = new Set(["", "0", "off", "false", "no"]);
|
|
49
|
+
|
|
50
|
+
export interface BackgroundResolution {
|
|
51
|
+
/** Whether to tint the terminal at all. */
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
/** An explicit color the setting pinned (`#…`); undefined → derive from the theme's `void`. */
|
|
54
|
+
hex?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decide whether/what to tint from the two sources, env winning over the theme.
|
|
59
|
+
* `env` is the raw `PI_1337_BG` (undefined when unset); `theme` is the palette's
|
|
60
|
+
* own `pi1337.background` (these are themes *for* pi-1337, so they may opt in).
|
|
61
|
+
* A defined `env` — even `off`/empty — overrides the theme entirely; otherwise the
|
|
62
|
+
* theme's setting stands. `on`/`auto`/`theme`/`1` enable the derived `void`; a
|
|
63
|
+
* `#rrggbb`/`#rgb` value enables that exact color; falsy values disable.
|
|
64
|
+
*/
|
|
65
|
+
export function resolveBackground(env: string | undefined, theme: string | undefined): BackgroundResolution {
|
|
66
|
+
const raw = env !== undefined ? env : theme;
|
|
67
|
+
if (raw === undefined) return { enabled: false };
|
|
68
|
+
const s = raw.trim().toLowerCase();
|
|
69
|
+
if (BG_FALSY.has(s)) return { enabled: false };
|
|
70
|
+
const hex = normalizeHex(s);
|
|
71
|
+
return hex ? { enabled: true, hex } : { enabled: true };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Resolve the background color to paint: an explicit `override` (e.g. from
|
|
76
|
+
* `PI_1337_BG=#101010`) wins when it's a valid hex; otherwise the active theme's
|
|
77
|
+
* page background (`export.pageBg` — each palette's `void`). Returns `undefined`
|
|
78
|
+
* when neither is a usable color, in which case the terminal is left untouched.
|
|
79
|
+
*/
|
|
80
|
+
export function resolveBackgroundHex(override: string | undefined, pageBg: string | undefined): string | undefined {
|
|
81
|
+
return normalizeHex(override) ?? normalizeHex(pageBg);
|
|
82
|
+
}
|