mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 13:05:03 +00:00
45 lines
1 KiB
TypeScript
45 lines
1 KiB
TypeScript
/**
|
|
* TUI session selector for --resume flag
|
|
*/
|
|
|
|
import { ProcessTerminal, TUI } from "@mariozechner/pi-tui";
|
|
import type { SessionInfo } from "../core/session-manager.js";
|
|
import { SessionSelectorComponent } from "../modes/interactive/components/session-selector.js";
|
|
|
|
/** Show TUI session selector and return selected session path or null if cancelled */
|
|
export async function selectSession(
|
|
currentSessions: SessionInfo[],
|
|
allSessions: SessionInfo[],
|
|
): Promise<string | null> {
|
|
return new Promise((resolve) => {
|
|
const ui = new TUI(new ProcessTerminal());
|
|
let resolved = false;
|
|
|
|
const selector = new SessionSelectorComponent(
|
|
currentSessions,
|
|
allSessions,
|
|
(path: string) => {
|
|
if (!resolved) {
|
|
resolved = true;
|
|
ui.stop();
|
|
resolve(path);
|
|
}
|
|
},
|
|
() => {
|
|
if (!resolved) {
|
|
resolved = true;
|
|
ui.stop();
|
|
resolve(null);
|
|
}
|
|
},
|
|
() => {
|
|
ui.stop();
|
|
process.exit(0);
|
|
},
|
|
);
|
|
|
|
ui.addChild(selector);
|
|
ui.setFocus(selector.getSessionList());
|
|
ui.start();
|
|
});
|
|
}
|