mirror of
https://github.com/earendil-works/pi.git
synced 2026-06-18 15:54:04 +08:00
- Add message queuing with configurable modes (one-at-a-time/all) (#15) - Add /queue command to select queue mode - Add TruncatedText component for proper viewport-aware text truncation - Queue mode setting persists in ~/.pi/agent/settings.json - Visual feedback for queued messages with proper ANSI handling - Press Escape to abort and restore queued messages to editor
65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import { type Component, Container, type SelectItem, SelectList } from "@mariozechner/pi-tui";
|
|
import chalk from "chalk";
|
|
|
|
/**
|
|
* Dynamic border component that adjusts to viewport width
|
|
*/
|
|
class DynamicBorder implements Component {
|
|
render(width: number): string[] {
|
|
return [chalk.blue("─".repeat(Math.max(1, width)))];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Component that renders a queue mode selector with borders
|
|
*/
|
|
export class QueueModeSelectorComponent extends Container {
|
|
private selectList: SelectList;
|
|
|
|
constructor(
|
|
currentMode: "all" | "one-at-a-time",
|
|
onSelect: (mode: "all" | "one-at-a-time") => void,
|
|
onCancel: () => void,
|
|
) {
|
|
super();
|
|
|
|
const queueModes: SelectItem[] = [
|
|
{
|
|
value: "one-at-a-time",
|
|
label: "one-at-a-time",
|
|
description: "Process queued messages one by one (recommended)",
|
|
},
|
|
{ value: "all", label: "all", description: "Process all queued messages at once" },
|
|
];
|
|
|
|
// Add top border
|
|
this.addChild(new DynamicBorder());
|
|
|
|
// Create selector
|
|
this.selectList = new SelectList(queueModes, 2);
|
|
|
|
// Preselect current mode
|
|
const currentIndex = queueModes.findIndex((item) => item.value === currentMode);
|
|
if (currentIndex !== -1) {
|
|
this.selectList.setSelectedIndex(currentIndex);
|
|
}
|
|
|
|
this.selectList.onSelect = (item) => {
|
|
onSelect(item.value as "all" | "one-at-a-time");
|
|
};
|
|
|
|
this.selectList.onCancel = () => {
|
|
onCancel();
|
|
};
|
|
|
|
this.addChild(this.selectList);
|
|
|
|
// Add bottom border
|
|
this.addChild(new DynamicBorder());
|
|
}
|
|
|
|
getSelectList(): SelectList {
|
|
return this.selectList;
|
|
}
|
|
}
|