@narumitw/pi-statusline 0.13.0 → 0.13.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.
- package/README.md +3 -2
- package/package.json +1 -1
- package/src/extension-status.ts +300 -0
- package/src/git-status.ts +117 -0
- package/src/render.ts +257 -0
- package/src/settings.ts +66 -0
- package/src/statusline.ts +43 -721
package/src/settings.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import type { SegmentName, StatuslineConfig, StatuslinePresetName } from "../presets/types.js";
|
|
6
|
+
|
|
7
|
+
const SETTINGS_FILE = "pi-statusline-settings.json";
|
|
8
|
+
const DEFAULT_PRESET: StatuslinePresetName = "tokyo-night";
|
|
9
|
+
const DEFAULT_SEGMENTS: SegmentName[] = [
|
|
10
|
+
"brand",
|
|
11
|
+
"model",
|
|
12
|
+
"thinking",
|
|
13
|
+
"cwd",
|
|
14
|
+
"branch",
|
|
15
|
+
"tools",
|
|
16
|
+
"context",
|
|
17
|
+
"tokens",
|
|
18
|
+
"cost",
|
|
19
|
+
"time",
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
export interface StatuslineSettings {
|
|
23
|
+
extensionStatusIcons: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createDefaultConfig(): StatuslineConfig {
|
|
27
|
+
return {
|
|
28
|
+
preset: readStatuslinePreset(),
|
|
29
|
+
palette: "candy",
|
|
30
|
+
density: "compact",
|
|
31
|
+
separator: "dot",
|
|
32
|
+
showLabels: false,
|
|
33
|
+
segments: [...DEFAULT_SEGMENTS],
|
|
34
|
+
extensionStatusIcons: readStatuslineSettings().extensionStatusIcons,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function readStatuslineSettings(
|
|
39
|
+
settingsPath = join(getAgentDir(), SETTINGS_FILE),
|
|
40
|
+
): StatuslineSettings {
|
|
41
|
+
try {
|
|
42
|
+
return normalizeStatuslineSettings(JSON.parse(readFileSync(settingsPath, "utf8")));
|
|
43
|
+
} catch {
|
|
44
|
+
return { extensionStatusIcons: {} };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function normalizeStatuslineSettings(value: unknown): StatuslineSettings {
|
|
49
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return { extensionStatusIcons: {} };
|
|
50
|
+
const icons = (value as { extensionStatusIcons?: unknown }).extensionStatusIcons;
|
|
51
|
+
if (!icons || typeof icons !== "object" || Array.isArray(icons)) {
|
|
52
|
+
return { extensionStatusIcons: {} };
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
extensionStatusIcons: Object.fromEntries(
|
|
56
|
+
Object.entries(icons).filter(
|
|
57
|
+
(entry): entry is [string, string] => typeof entry[1] === "string",
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function readStatuslinePreset(): StatuslinePresetName {
|
|
64
|
+
const value = process.env.PI_STATUSLINE_PRESET?.trim().toLowerCase();
|
|
65
|
+
return value === "classic" || value === "tokyo-night" ? value : DEFAULT_PRESET;
|
|
66
|
+
}
|