Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/drain-terminal-input-exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Prevent modified keyboard release sequences from appearing after exiting the CLI.
1 change: 1 addition & 0 deletions apps/kimi-code/src/tui/kimi-tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ export class KimiTUI {
await this.harness.close();
this.sessionEventHandler.stopAllMcpServerStatusSpinners();
this.uninstallRainbowDance();
await this.state.terminal.drainInput();
this.state.ui.stop();
if (this.onExit) {
await this.onExit(exitCode);
Expand Down
24 changes: 23 additions & 1 deletion apps/kimi-code/test/tui/signal-handlers.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { KimiTUI, type KimiTUIStartupInput } from '#/tui/kimi-tui';
import { KimiTUI, type KimiTUIStartupInput, type TUIState } from '#/tui/kimi-tui';

interface SignalDriver {
state: TUIState;
registerSignalHandlers(): void;
unregisterSignalHandlers(): void;
emergencyTerminalExit(): never;
Expand Down Expand Up @@ -298,6 +299,27 @@ describe('KimiTUI signal handlers', () => {
expect(process.listenerCount('SIGTERM')).toBe(beforeSigterm);
});

it('stop() drains terminal input before stopping the UI and exiting', async () => {
const { driver, tui } = makeDriver();
const events: string[] = [];
const drainInput = vi.spyOn(driver.state.terminal, 'drainInput').mockImplementation(async () => {
events.push('drain');
});
const uiStop = vi.spyOn(driver.state.ui, 'stop').mockImplementation(() => {
events.push('ui.stop');
});
tui.onExit = vi.fn(async () => {
events.push('exit');
});

await tui.stop();

expect(drainInput).toHaveBeenCalledOnce();
expect(uiStop).toHaveBeenCalledOnce();
expect(tui.onExit).toHaveBeenCalledOnce();
expect(events).toEqual(['drain', 'ui.stop', 'exit']);
});

it('start() unregisters signal handlers when initialization throws', async () => {
const { tui } = makeDriver();
// Force the very first awaited call inside start() to reject. We don't
Expand Down
Loading