@adeildo/pi-look 5.1.0 → 5.3.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/README.md +46 -36
- package/assets/preview.png +0 -0
- package/package.json +2 -2
- package/src/data/snapshot.ts +5 -0
- package/src/index.ts +8 -48
- package/src/render/format.ts +1 -0
- package/src/render/segments.ts +43 -4
- package/src/render/tools.ts +105 -0
- package/src/settings.ts +10 -42
- package/src/ui/footer.ts +1 -1
- package/src/ui/screen.ts +8 -1
- package/src/ui/tool-frame.ts +474 -0
- package/src/desktop/palette.ts +0 -193
- package/src/desktop/sync.ts +0 -79
package/src/desktop/sync.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { type FSWatcher, watch } from "node:fs";
|
|
2
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
3
|
-
import { homedir } from "node:os";
|
|
4
|
-
import { basename, dirname, join } from "node:path";
|
|
5
|
-
|
|
6
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
|
|
8
|
-
import { DESKTOP_THEME, desktopTheme, missingColors, parseDesktopColors } from "./palette.ts";
|
|
9
|
-
|
|
10
|
-
const SETTLE_MS = 250;
|
|
11
|
-
|
|
12
|
-
export type SyncResult =
|
|
13
|
-
| { kind: "written"; path: string }
|
|
14
|
-
| { kind: "unchanged"; path: string }
|
|
15
|
-
| { kind: "missing" }
|
|
16
|
-
| { kind: "invalid"; reason: string };
|
|
17
|
-
|
|
18
|
-
export function themePath(): string {
|
|
19
|
-
return join(getAgentDir(), "themes", `${DESKTOP_THEME}.json`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function expandHome(path: string): string {
|
|
23
|
-
return path === "~" || path.startsWith("~/") ? join(homedir(), path.slice(1)) : path;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function syncDesktopTheme(source: string): Promise<SyncResult> {
|
|
27
|
-
let raw: string;
|
|
28
|
-
try {
|
|
29
|
-
raw = await readFile(expandHome(source), "utf8");
|
|
30
|
-
} catch {
|
|
31
|
-
return { kind: "missing" };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let json: unknown;
|
|
35
|
-
try {
|
|
36
|
-
json = JSON.parse(raw);
|
|
37
|
-
} catch {
|
|
38
|
-
return { kind: "invalid", reason: "the palette file is not JSON" };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const colors = parseDesktopColors(json);
|
|
42
|
-
if (colors === undefined) return { kind: "invalid", reason: "not a DankMaterialShell palette" };
|
|
43
|
-
const missing = missingColors(colors);
|
|
44
|
-
if (missing.length > 0) return { kind: "invalid", reason: `missing ${missing.join(", ")}` };
|
|
45
|
-
|
|
46
|
-
const path = themePath();
|
|
47
|
-
const next = `${JSON.stringify(desktopTheme(colors), null, "\t")}\n`;
|
|
48
|
-
const current = await readFile(path, "utf8").catch(() => undefined);
|
|
49
|
-
if (current === next) return { kind: "unchanged", path };
|
|
50
|
-
|
|
51
|
-
await mkdir(dirname(path), { recursive: true });
|
|
52
|
-
await writeFile(path, next);
|
|
53
|
-
return { kind: "written", path };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Watches the folder: an atomic write replaces the file, and a watch on the old one goes quiet. */
|
|
57
|
-
export function watchDesktopPalette(source: string, changed: () => void): () => void {
|
|
58
|
-
const path = expandHome(source);
|
|
59
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
60
|
-
let watcher: FSWatcher | undefined;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
watcher = watch(dirname(path), (_event, file) => {
|
|
64
|
-
if (file !== null && file !== basename(path)) return;
|
|
65
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
66
|
-
timer = setTimeout(changed, SETTLE_MS);
|
|
67
|
-
timer.unref?.();
|
|
68
|
-
});
|
|
69
|
-
watcher.unref?.();
|
|
70
|
-
watcher.on("error", () => watcher?.close());
|
|
71
|
-
} catch {
|
|
72
|
-
return () => {};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return () => {
|
|
76
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
77
|
-
watcher?.close();
|
|
78
|
-
};
|
|
79
|
-
}
|