Reverse model switching and binding for dialog

This commit is contained in:
Armin Ronacher 2025-12-25 18:02:38 +01:00
parent 58c02ce02b
commit b576a527c7
5 changed files with 57 additions and 12 deletions

View file

@ -3,11 +3,13 @@ import {
isCtrlC,
isCtrlD,
isCtrlG,
isCtrlL,
isCtrlO,
isCtrlP,
isCtrlT,
isCtrlZ,
isEscape,
isShiftCtrlP,
isShiftTab,
} from "@mariozechner/pi-tui";
@ -20,6 +22,8 @@ export class CustomEditor extends Editor {
public onCtrlD?: () => void;
public onShiftTab?: () => void;
public onCtrlP?: () => void;
public onShiftCtrlP?: () => void;
public onCtrlL?: () => void;
public onCtrlO?: () => void;
public onCtrlT?: () => void;
public onCtrlG?: () => void;
@ -44,12 +48,24 @@ export class CustomEditor extends Editor {
return;
}
// Intercept Ctrl+L for model selector
if (isCtrlL(data) && this.onCtrlL) {
this.onCtrlL();
return;
}
// Intercept Ctrl+O for tool output expansion
if (isCtrlO(data) && this.onCtrlO) {
this.onCtrlO();
return;
}
// Intercept Shift+Ctrl+P for backward model cycling (check before Ctrl+P)
if (isShiftCtrlP(data) && this.onShiftCtrlP) {
this.onShiftCtrlP();
return;
}
// Intercept Ctrl+P for model cycling
if (isCtrlP(data) && this.onCtrlP) {
this.onCtrlP();

View file

@ -225,9 +225,12 @@ export class InteractiveMode {
theme.fg("dim", "shift+tab") +
theme.fg("muted", " to cycle thinking") +
"\n" +
theme.fg("dim", "ctrl+p") +
theme.fg("dim", "ctrl+p/shift+ctrl+p") +
theme.fg("muted", " to cycle models") +
"\n" +
theme.fg("dim", "ctrl+l") +
theme.fg("muted", " to select model") +
"\n" +
theme.fg("dim", "ctrl+o") +
theme.fg("muted", " to expand tools") +
"\n" +
@ -592,7 +595,9 @@ export class InteractiveMode {
this.editor.onCtrlD = () => this.handleCtrlD();
this.editor.onCtrlZ = () => this.handleCtrlZ();
this.editor.onShiftTab = () => this.cycleThinkingLevel();
this.editor.onCtrlP = () => this.cycleModel();
this.editor.onCtrlP = () => this.cycleModel("forward");
this.editor.onShiftCtrlP = () => this.cycleModel("backward");
this.editor.onCtrlL = () => this.showModelSelector();
this.editor.onCtrlO = () => this.toggleToolOutputExpansion();
this.editor.onCtrlT = () => this.toggleThinkingBlockVisibility();
this.editor.onCtrlG = () => this.openExternalEditor();
@ -1232,9 +1237,9 @@ export class InteractiveMode {
}
}
private async cycleModel(): Promise<void> {
private async cycleModel(direction: "forward" | "backward"): Promise<void> {
try {
const result = await this.session.cycleModel();
const result = await this.session.cycleModel(direction);
if (result === null) {
const msg = this.session.scopedModels.length > 0 ? "Only one model in scope" : "Only one model available";
this.showStatus(msg);