feat(tui): add input history for submitted messages (WIP)

Record submitted inputs in the editor history so up/down arrow
can recall previous messages.

Adds a small helper to wire submit handling and unit tests for
routing/recording behavior.

No PR yet (per request).
This commit is contained in:
Vignesh Natarajan
2026-01-20 18:21:55 -08:00
committed by Peter Steinberger
parent 416894c642
commit 2700794228
2 changed files with 128 additions and 10 deletions

View File

@@ -36,6 +36,30 @@ import type {
export { resolveFinalAssistantText } from "./tui-formatters.js";
export type { TuiOptions } from "./tui-types.js";
export function createEditorSubmitHandler(params: {
editor: {
setText: (value: string) => void;
addToHistory: (value: string) => void;
};
handleCommand: (value: string) => Promise<void> | void;
sendMessage: (value: string) => Promise<void> | void;
}) {
return (text: string) => {
const value = text.trim();
params.editor.setText("");
if (!value) return;
// Enable built-in editor prompt history navigation (up/down).
params.editor.addToHistory(value);
if (value.startsWith("/")) {
void params.handleCommand(value);
return;
}
void params.sendMessage(value);
};
}
export async function runTui(opts: TuiOptions) {
const config = loadConfig();
const initialSessionInput = (opts.session ?? "").trim();
@@ -473,16 +497,11 @@ export async function runTui(opts: TuiOptions) {
});
updateAutocompleteProvider();
editor.onSubmit = (text) => {
const value = text.trim();
editor.setText("");
if (!value) return;
if (value.startsWith("/")) {
void handleCommand(value);
return;
}
void sendMessage(value);
};
editor.onSubmit = createEditorSubmitHandler({
editor,
handleCommand,
sendMessage,
});
editor.onEscape = () => {
void abortActive();