mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 11:02:17 +00:00
Fix session selector: handle Ctrl+C and viewport width
- Add SIGINT handler to allow Ctrl+C to exit during session selection - Remove hardcoded 60-char truncation, let SelectList handle dynamic truncation - Simplify date format (5m, 2h, 3d instead of "5m ago") - Make metadata more compact (5msg instead of "5 msgs")
This commit is contained in:
parent
458702b3a7
commit
6b48e73607
2 changed files with 37 additions and 17 deletions
|
|
@ -124,17 +124,37 @@ async function selectSession(sessionManager: SessionManager): Promise<string | n
|
|||
return new Promise((resolve) => {
|
||||
const ui = new TUI(new ProcessTerminal());
|
||||
let selectedPath: string | null = null;
|
||||
let resolved = false;
|
||||
|
||||
// Handle Ctrl+C
|
||||
const handleSigint = () => {
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
ui.stop();
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
|
||||
process.on("SIGINT", handleSigint);
|
||||
|
||||
const selector = new SessionSelectorComponent(
|
||||
sessionManager,
|
||||
(path: string) => {
|
||||
selectedPath = path;
|
||||
ui.stop();
|
||||
resolve(path);
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
selectedPath = path;
|
||||
process.removeListener("SIGINT", handleSigint);
|
||||
ui.stop();
|
||||
resolve(path);
|
||||
}
|
||||
},
|
||||
() => {
|
||||
ui.stop();
|
||||
resolve(null);
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
process.removeListener("SIGINT", handleSigint);
|
||||
ui.stop();
|
||||
resolve(null);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -54,29 +54,29 @@ export class SessionSelectorComponent extends Container {
|
|||
const diffHours = Math.floor(diffMs / 3600000);
|
||||
const diffDays = Math.floor(diffMs / 86400000);
|
||||
|
||||
if (diffMins < 1) return "just now";
|
||||
if (diffMins < 60) return `${diffMins}m ago`;
|
||||
if (diffHours < 24) return `${diffHours}h ago`;
|
||||
if (diffDays === 1) return "yesterday";
|
||||
if (diffDays < 7) return `${diffDays}d ago`;
|
||||
if (diffMins < 1) return "now";
|
||||
if (diffMins < 60) return `${diffMins}m`;
|
||||
if (diffHours < 24) return `${diffHours}h`;
|
||||
if (diffDays === 1) return "1d";
|
||||
if (diffDays < 7) return `${diffDays}d`;
|
||||
|
||||
// Fallback to date string
|
||||
return date.toLocaleDateString();
|
||||
};
|
||||
|
||||
// Truncate first message to single line
|
||||
const truncatedMessage = session.firstMessage.replace(/\n/g, " ").trim();
|
||||
// Normalize first message to single line
|
||||
const normalizedMessage = session.firstMessage.replace(/\n/g, " ").trim();
|
||||
|
||||
// Build description with metadata
|
||||
const created = formatDate(session.created);
|
||||
// Build description with metadata (single line, compact format)
|
||||
const modified = formatDate(session.modified);
|
||||
const msgCount = `${session.messageCount} msg${session.messageCount !== 1 ? "s" : ""}`;
|
||||
const msgCount = `${session.messageCount}msg`;
|
||||
|
||||
const description = `${truncatedMessage}\n${chalk.dim(`Created: ${created} • Modified: ${modified} • ${msgCount}`)}`;
|
||||
// Keep description compact: "modified • count"
|
||||
const description = `${modified} • ${msgCount}`;
|
||||
|
||||
return {
|
||||
value: session.path,
|
||||
label: truncatedMessage.substring(0, 80),
|
||||
label: normalizedMessage, // Let SelectList handle truncation based on actual width
|
||||
description,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue