@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
37 lines • 1.54 kB
JavaScript
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { getAgentDir } from "../../../config.js";
function hintPath(agentDir = getAgentDir()) {
return join(agentDir, "cache", "terminal-theme.json");
}
/**
* The terminal's background is only knowable by asking it, and the answer arrives one OSC round
* trip after the first frame is already on screen. Remembering the last answer lets the next launch
* paint the right theme immediately; `COLORFGBG` is the only environment signal and most terminals
* do not set it, so without this an `auto` user is repainted on every start.
*/
export function readTerminalThemeHint(agentDir) {
try {
const parsed = JSON.parse(readFileSync(hintPath(agentDir), "utf8"));
if (typeof parsed !== "object" || parsed === null)
return undefined;
const value = parsed.terminalTheme;
return value === "light" || value === "dark" ? value : undefined;
}
catch {
return undefined;
}
}
export function writeTerminalThemeHint(terminalTheme, agentDir) {
try {
const path = hintPath(agentDir);
mkdirSync(dirname(path), { recursive: true });
const temporary = `${path}.${process.pid}.tmp`;
writeFileSync(temporary, `${JSON.stringify({ terminalTheme })}\n`);
renameSync(temporary, path);
}
catch {
// A cache that cannot be written must never break a launch.
}
}
//# sourceMappingURL=terminal-theme-cache.js.map