- /resume and --resume now toggle between Current Folder and All sessions with Tab - SessionManager.list() and listAll() are now async with optional progress callback - Shows loading progress (e.g. Loading 5/42) while scanning sessions - SessionInfo.cwd field shows session working directory in All view - Lazy loading: All sessions only loaded when user presses Tab closes #619 Co-authored-by: Thomas Mustier <mustierthomas@gmail.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
/**
|
|
* TUI session selector for --resume flag
|
|
*/
|
|
|
|
import { ProcessTerminal, TUI } from "@mariozechner/pi-tui";
|
|
import type { SessionInfo, SessionListProgress } from "../core/session-manager.js";
|
|
import { SessionSelectorComponent } from "../modes/interactive/components/session-selector.js";
|
|
|
|
type SessionsLoader = (onProgress?: SessionListProgress) => Promise<SessionInfo[]>;
|
|
|
|
/** Show TUI session selector and return selected session path or null if cancelled */
|
|
export async function selectSession(
|
|
currentSessionsLoader: SessionsLoader,
|
|
allSessionsLoader: SessionsLoader,
|
|
): Promise<string | null> {
|
|
return new Promise((resolve) => {
|
|
const ui = new TUI(new ProcessTerminal());
|
|
let resolved = false;
|
|
|
|
const selector = new SessionSelectorComponent(
|
|
currentSessionsLoader,
|
|
allSessionsLoader,
|
|
(path: string) => {
|
|
if (!resolved) {
|
|
resolved = true;
|
|
ui.stop();
|
|
resolve(path);
|
|
}
|
|
},
|
|
() => {
|
|
if (!resolved) {
|
|
resolved = true;
|
|
ui.stop();
|
|
resolve(null);
|
|
}
|
|
},
|
|
() => {
|
|
ui.stop();
|
|
process.exit(0);
|
|
},
|
|
() => ui.requestRender(),
|
|
);
|
|
|
|
ui.addChild(selector);
|
|
ui.setFocus(selector.getSessionList());
|
|
ui.start();
|
|
});
|
|
}
|