@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
78 lines • 3.01 kB
JavaScript
import { Text } from "@earendil-works/pi-tui";
import { partialStrikethrough, strikeRevealCount, TODO_STRIKE_FRAME_INTERVAL_MS, TODO_STRIKE_TOTAL_FRAMES, } from "../../../../modes/interactive/components/todo-strike.js";
import { getTodoMarker, sanitizeTodoText } from "./todo-format.js";
function formatTask(task, theme, completionKeys, frame) {
const line = `${getTodoMarker(task.status)} ${sanitizeTodoText(task.content)}`;
switch (task.status) {
case "completed": {
const reveal = completionKeys.has(task.content) ? strikeRevealCount(line, frame) : undefined;
return reveal === undefined
? theme.fg("dim", theme.strikethrough(line))
: theme.fg("dim", partialStrikethrough(line, reveal, (text) => theme.strikethrough(text)));
}
case "in_progress":
return theme.fg("accent", theme.bold(line));
case "abandoned":
return theme.fg("dim", line);
case "pending":
return line;
}
}
function getAnimatedCompletionKeys(model, completedTasks) {
const visibleCompletedTasks = new Set();
for (const row of model.rows) {
if (row.kind === "task" && row.task.status === "completed") {
visibleCompletedTasks.add(row.task.content);
}
}
return new Set(completedTasks
.filter((transition) => transition.phase === model.phaseName && visibleCompletedTasks.has(transition.content))
.map((transition) => transition.content));
}
export class TodoWidgetComponent extends Text {
constructor(tui, theme, model, completedTasks) {
super("", 1, 0);
this.tui = tui;
this.theme = theme;
this.model = model;
this.completionKeys = getAnimatedCompletionKeys(model, completedTasks);
this.frame = this.completionKeys.size > 0 ? 0 : undefined;
this.updateDisplay();
if (this.frame !== undefined)
this.startAnimation();
}
dispose() {
this.stopAnimation();
}
startAnimation() {
const handle = setInterval(() => this.tick(), TODO_STRIKE_FRAME_INTERVAL_MS);
handle.unref();
this.intervalId = handle;
}
stopAnimation() {
if (this.intervalId === undefined)
return;
clearInterval(this.intervalId);
this.intervalId = undefined;
}
tick() {
if (this.frame === undefined)
return;
const nextFrame = this.frame + 1;
if (nextFrame >= TODO_STRIKE_TOTAL_FRAMES) {
this.frame = undefined;
this.stopAnimation();
}
else {
this.frame = nextFrame;
}
this.updateDisplay();
this.tui.requestRender();
}
updateDisplay() {
this.setText(this.model.rows
.map((row) => row.kind === "label" ? row.text : formatTask(row.task, this.theme, this.completionKeys, this.frame))
.join("\n"));
}
}
//# sourceMappingURL=todo-widget-component.js.map