@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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public `setHeader` adapter for the pure startup header.
|
|
3
|
+
*
|
|
4
|
+
* Ownership is learned when Pi invokes our factory. Pi disposes a custom header
|
|
5
|
+
* before replacing it; that notification lets clear() avoid removing a header
|
|
6
|
+
* another extension installed later. Pi exposes no getter for the current
|
|
7
|
+
* custom header, so disposal is the public ownership signal.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
import { renderHeader } from "./header.ts";
|
|
12
|
+
|
|
13
|
+
export interface HeaderControllerOptions {
|
|
14
|
+
maxWidth?: number;
|
|
15
|
+
minMargin?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type HeaderContext = Pick<ExtensionContext, "cwd" | "ui">;
|
|
19
|
+
|
|
20
|
+
/** Owns installation and safe removal of this extension's custom header. */
|
|
21
|
+
export function createHeaderController(options: HeaderControllerOptions = {}) {
|
|
22
|
+
let ui: HeaderContext["ui"] | undefined;
|
|
23
|
+
let generation = 0;
|
|
24
|
+
let ownedGeneration: number | undefined;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
install(ctx: HeaderContext): void {
|
|
28
|
+
ui = ctx.ui;
|
|
29
|
+
const thisGeneration = ++generation;
|
|
30
|
+
ctx.ui.setHeader((_tui, factoryTheme) => {
|
|
31
|
+
ownedGeneration = thisGeneration;
|
|
32
|
+
return {
|
|
33
|
+
render(width: number): string[] {
|
|
34
|
+
const theme: Theme = ctx.ui.theme ?? factoryTheme;
|
|
35
|
+
return renderHeader({
|
|
36
|
+
width,
|
|
37
|
+
maxWidth: options.maxWidth,
|
|
38
|
+
minMargin: options.minMargin,
|
|
39
|
+
palette: theme.name ?? "system",
|
|
40
|
+
cwd: ctx.cwd,
|
|
41
|
+
fg: (role, text) => theme.fg(role, text),
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
invalidate(): void {},
|
|
45
|
+
dispose(): void {
|
|
46
|
+
if (ownedGeneration === thisGeneration) ownedGeneration = undefined;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
clear(): void {
|
|
53
|
+
if (ownedGeneration === undefined || !ui) return;
|
|
54
|
+
ownedGeneration = undefined;
|
|
55
|
+
ui.setHeader(undefined);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
package/src/header.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure compact startup header for the 1337 theme package.
|
|
3
|
+
*
|
|
4
|
+
* The caller supplies the live palette's foreground colorizer and the current
|
|
5
|
+
* workspace. This module owns no Pi state and uses the same terminal ruler and
|
|
6
|
+
* centered cap geometry as the framed editor.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { sanitizeInlineText, shortCwd } from "./format.ts";
|
|
10
|
+
import { chooseBox, truncateToWidth, visibleWidth } from "./width.ts";
|
|
11
|
+
|
|
12
|
+
export type HeaderColorRole = "accent" | "muted" | "dim";
|
|
13
|
+
|
|
14
|
+
export interface HeaderOptions {
|
|
15
|
+
/** Terminal width in columns. */
|
|
16
|
+
width: number;
|
|
17
|
+
/** Same outer cap used by the framed editor. */
|
|
18
|
+
maxWidth?: number;
|
|
19
|
+
/** Minimum side margin before the editor's narrow-width fallback. */
|
|
20
|
+
minMargin?: number;
|
|
21
|
+
/** Current theme/palette name (for example, `1337-neon`). */
|
|
22
|
+
palette: string;
|
|
23
|
+
/** Current working directory. */
|
|
24
|
+
cwd: string;
|
|
25
|
+
/** Semantic theme foreground colorizer, typically `theme.fg`. */
|
|
26
|
+
fg: (role: HeaderColorRole, text: string) => string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DEFAULT_MAX_WIDTH = 100;
|
|
30
|
+
const DEFAULT_MIN_MARGIN = 2;
|
|
31
|
+
const BRAND = "1337";
|
|
32
|
+
const SEPARATOR = " · ";
|
|
33
|
+
const MIN_LABEL_WIDTH = 3;
|
|
34
|
+
const MIN_PATH_WIDTH = 3;
|
|
35
|
+
|
|
36
|
+
interface HeaderLineParts {
|
|
37
|
+
brand: string;
|
|
38
|
+
palette?: string;
|
|
39
|
+
cwd?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Turn the internal theme id into a short, readable palette label. */
|
|
43
|
+
function shortPaletteLabel(value: string): string {
|
|
44
|
+
const safe = sanitizeInlineText(value);
|
|
45
|
+
if (!safe) return "";
|
|
46
|
+
const name = safe.replace(/^1337(?:[-\s]+)?/i, "").trim();
|
|
47
|
+
if (!name) return "PHOSPHOR";
|
|
48
|
+
const normalized = name.replace(/[-_]+/g, " ").replace(/\s+/g, " ").trim();
|
|
49
|
+
if (/^cyberpunk 2077 edgerunner$/i.test(normalized)) return "EDGERUNNER";
|
|
50
|
+
return truncateToWidth(normalized.toUpperCase(), 24);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Prefer a whole path, then a visible final path segment; never split a filename. */
|
|
54
|
+
function fitPath(path: string, width: number): string {
|
|
55
|
+
if (!path || width <= 0) return "";
|
|
56
|
+
if (visibleWidth(path) <= width) return path;
|
|
57
|
+
const basename = path.split("/").filter(Boolean).at(-1) ?? "";
|
|
58
|
+
if (!basename) return "";
|
|
59
|
+
const tail = `…/${basename}`;
|
|
60
|
+
if (visibleWidth(tail) <= width) return tail;
|
|
61
|
+
return visibleWidth(basename) <= width ? basename : "";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function paletteAndPathLine(width: number, palette: string, cwd: string): HeaderLineParts {
|
|
65
|
+
const base = `${BRAND}${SEPARATOR}`;
|
|
66
|
+
const baseWidth = visibleWidth(base);
|
|
67
|
+
const separatorWidth = visibleWidth(SEPARATOR);
|
|
68
|
+
|
|
69
|
+
if (palette && cwd) {
|
|
70
|
+
// First keep both details whole, abbreviating only the path when needed.
|
|
71
|
+
const fullPalettePrefix = `${base}${palette}${SEPARATOR}`;
|
|
72
|
+
const fullPalettePath = fitPath(cwd, width - visibleWidth(fullPalettePrefix));
|
|
73
|
+
if (fullPalettePath) return { brand: BRAND, palette, cwd: fullPalettePath };
|
|
74
|
+
|
|
75
|
+
// On smaller terminals, let the palette label shorten before dropping the
|
|
76
|
+
// workspace. Retain enough room for a useful path tail.
|
|
77
|
+
const pathBudget = Math.min(8, visibleWidth(cwd));
|
|
78
|
+
const paletteBudget = width - baseWidth - separatorWidth - pathBudget;
|
|
79
|
+
if (paletteBudget >= MIN_LABEL_WIDTH && pathBudget >= MIN_PATH_WIDTH) {
|
|
80
|
+
const compactPalette = truncateToWidth(palette, paletteBudget);
|
|
81
|
+
const compactPath = fitPath(cwd, pathBudget);
|
|
82
|
+
if (visibleWidth(compactPalette) >= MIN_LABEL_WIDTH && compactPath) {
|
|
83
|
+
return { brand: BRAND, palette: compactPalette, cwd: compactPath };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (palette) {
|
|
89
|
+
const paletteBudget = width - baseWidth;
|
|
90
|
+
if (visibleWidth(palette) <= paletteBudget) return { brand: BRAND, palette };
|
|
91
|
+
if (paletteBudget >= MIN_LABEL_WIDTH) {
|
|
92
|
+
return { brand: BRAND, palette: truncateToWidth(palette, paletteBudget) };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (cwd) {
|
|
97
|
+
const compactPath = fitPath(cwd, width - baseWidth);
|
|
98
|
+
if (compactPath) return { brand: BRAND, cwd: compactPath };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (visibleWidth(BRAND) <= width) return { brand: BRAND };
|
|
102
|
+
return { brand: truncateToWidth(BRAND, width) };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function commandHint(width: number): string {
|
|
106
|
+
const both = `/theme-1337${SEPARATOR}/settings`;
|
|
107
|
+
if (visibleWidth(both) <= width) return both;
|
|
108
|
+
if (visibleWidth("/theme-1337") <= width) return "/theme-1337";
|
|
109
|
+
if (visibleWidth("/settings") <= width) return "/settings";
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Render a vibrant, compact 1–2 line startup header. Dynamic palette/path text
|
|
115
|
+
* is sanitized before formatting, and each line is bounded by the editor's
|
|
116
|
+
* centered box geometry so even very narrow terminals cannot overflow.
|
|
117
|
+
*/
|
|
118
|
+
export function renderHeader(options: HeaderOptions): string[] {
|
|
119
|
+
const rawWidth = Number.isFinite(options.width) ? Math.max(0, Math.floor(options.width)) : 0;
|
|
120
|
+
if (rawWidth === 0) return [];
|
|
121
|
+
const maxWidth = options.maxWidth === Number.POSITIVE_INFINITY
|
|
122
|
+
? Number.POSITIVE_INFINITY
|
|
123
|
+
: Number.isFinite(options.maxWidth)
|
|
124
|
+
? Math.max(1, Math.floor(options.maxWidth!))
|
|
125
|
+
: DEFAULT_MAX_WIDTH;
|
|
126
|
+
const minMargin = Number.isFinite(options.minMargin) ? Math.max(0, Math.floor(options.minMargin!)) : DEFAULT_MIN_MARGIN;
|
|
127
|
+
const geometry = chooseBox(rawWidth, maxWidth, minMargin);
|
|
128
|
+
const inset = geometry.boxWidth >= 28 ? 2 : geometry.boxWidth >= 12 ? 1 : 0;
|
|
129
|
+
const contentWidth = Math.max(1, geometry.boxWidth - inset);
|
|
130
|
+
const leftPad = " ".repeat(geometry.leftMargin + inset);
|
|
131
|
+
const palette = shortPaletteLabel(typeof options.palette === "string" ? options.palette : "");
|
|
132
|
+
const cwd = typeof options.cwd === "string" ? shortCwd(options.cwd) : "";
|
|
133
|
+
const brandLine = paletteAndPathLine(contentWidth, palette, cwd);
|
|
134
|
+
const coloredBrandLine = [
|
|
135
|
+
options.fg("accent", brandLine.brand),
|
|
136
|
+
brandLine.palette ? `${options.fg("dim", SEPARATOR)}${options.fg("muted", brandLine.palette)}` : "",
|
|
137
|
+
brandLine.cwd ? `${options.fg("dim", SEPARATOR)}${options.fg("dim", brandLine.cwd)}` : "",
|
|
138
|
+
].join("");
|
|
139
|
+
const lines = [
|
|
140
|
+
`${leftPad}${coloredBrandLine}`,
|
|
141
|
+
];
|
|
142
|
+
const hint = commandHint(contentWidth);
|
|
143
|
+
if (hint) {
|
|
144
|
+
const commands = hint.split(SEPARATOR);
|
|
145
|
+
const coloredHint = commands.length === 2
|
|
146
|
+
? `${options.fg("muted", commands[0])}${options.fg("dim", SEPARATOR)}${options.fg("muted", commands[1])}`
|
|
147
|
+
: options.fg("muted", hint);
|
|
148
|
+
lines.push(`${leftPad}${coloredHint}`);
|
|
149
|
+
}
|
|
150
|
+
return lines;
|
|
151
|
+
}
|