feat(tui): let Esc cancel active minimal-mode response generation
This commit is contained in:
@@ -29,6 +29,7 @@ function asAgent(value: unknown): NativeAgent {
|
||||
function minimalTuiPrivates(value: MinimalTui): {
|
||||
handleBackendCommand: (provider: string) => Promise<void>;
|
||||
handleModelCommand: (tier: string, providerModel?: string) => void;
|
||||
handleEscapeAction: () => boolean;
|
||||
prompt: (text: string) => Promise<string>;
|
||||
rl: {
|
||||
once: (event: string, cb: () => void) => void;
|
||||
@@ -37,10 +38,12 @@ function minimalTuiPrivates(value: MinimalTui): {
|
||||
write: (data: string | null, key?: { ctrl?: boolean; name?: string }) => void;
|
||||
};
|
||||
activePromptCancel: (() => void) | null;
|
||||
activeOperationCancel: (() => void) | null;
|
||||
} {
|
||||
return value as unknown as {
|
||||
handleBackendCommand: (provider: string) => Promise<void>;
|
||||
handleModelCommand: (tier: string, providerModel?: string) => void;
|
||||
handleEscapeAction: () => boolean;
|
||||
prompt: (text: string) => Promise<string>;
|
||||
rl: {
|
||||
once: (event: string, cb: () => void) => void;
|
||||
@@ -49,6 +52,7 @@ function minimalTuiPrivates(value: MinimalTui): {
|
||||
write: (data: string | null, key?: { ctrl?: boolean; name?: string }) => void;
|
||||
};
|
||||
activePromptCancel: (() => void) | null;
|
||||
activeOperationCancel: (() => void) | null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -329,4 +333,26 @@ describe('MinimalTui prompt cancellation', () => {
|
||||
expect(write).toHaveBeenCalledWith(null, { name: 'return' });
|
||||
expect(minimalTuiPrivates(tui).activePromptCancel).toBeNull();
|
||||
});
|
||||
|
||||
it('uses Esc to cancel active running operation', () => {
|
||||
const mockSession = {
|
||||
id: 'test',
|
||||
getHistory: () => [],
|
||||
addMessage: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
replaceHistory: vi.fn(),
|
||||
};
|
||||
|
||||
const tui = new MinimalTui({
|
||||
session: asSession(mockSession),
|
||||
modelClient: asRouter({}),
|
||||
systemPrompt: 'test',
|
||||
});
|
||||
|
||||
const cancelRunningOperation = vi.fn();
|
||||
minimalTuiPrivates(tui).activeOperationCancel = cancelRunningOperation;
|
||||
|
||||
expect(minimalTuiPrivates(tui).handleEscapeAction()).toBe(true);
|
||||
expect(cancelRunningOperation).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user