mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 05:52:35 +08:00
Merge pull request #6183 from Ashwinhegde19/fix/windows-mouse-tracking-exit
fix: disable mouse tracking on Windows terminal exit
This commit is contained in:
@@ -63,6 +63,7 @@ import { TuiConfigProvider, useTuiConfig } from "./context/tui-config"
|
||||
import { TuiConfig } from "@/config/tui"
|
||||
import { createTuiApi, TuiPluginRuntime, type RouteMap } from "./plugin"
|
||||
import { FormatError, FormatUnknownError } from "@/cli/error"
|
||||
import { resetTerminalState } from "@tui/util/terminal" // kilocode_change
|
||||
|
||||
async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
|
||||
// can't set raw mode if not a TTY
|
||||
@@ -197,6 +198,9 @@ export function tui(input: {
|
||||
await TuiPluginRuntime.dispose()
|
||||
}
|
||||
|
||||
// kilocode_change - safety net: ensure mouse tracking is disabled regardless of exit path
|
||||
process.on("exit", resetTerminalState) // kilocode_change
|
||||
|
||||
const renderer = await createCliRenderer(rendererConfig(input.config))
|
||||
|
||||
await render(() => {
|
||||
@@ -1010,6 +1014,8 @@ function ErrorComponent(props: {
|
||||
renderer?.setTerminalTitle("")
|
||||
renderer?.destroy()
|
||||
win32FlushInputBuffer()
|
||||
// kilocode_change - reset terminal state to disable mouse tracking on exit
|
||||
resetTerminalState()
|
||||
await props.onExit()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useRenderer } from "@opentui/solid"
|
||||
import { createSimpleContext } from "./helper"
|
||||
import { FormatError, FormatUnknownError } from "@/cli/error"
|
||||
import { win32FlushInputBuffer } from "../win32"
|
||||
import { resetTerminalState } from "@tui/util/terminal" // kilocode_change
|
||||
type Exit = ((reason?: unknown) => Promise<void>) & {
|
||||
message: {
|
||||
set: (value?: string) => () => void
|
||||
@@ -38,6 +39,7 @@ export const { use: useExit, provider: ExitProvider } = createSimpleContext({
|
||||
renderer.setTerminalTitle("")
|
||||
renderer.destroy()
|
||||
win32FlushInputBuffer()
|
||||
resetTerminalState() // kilocode_change
|
||||
if (reason) {
|
||||
const formatted = FormatError(reason) ?? FormatUnknownError(reason)
|
||||
if (formatted) {
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
import { RGBA } from "@opentui/core"
|
||||
|
||||
// kilocode_change start
|
||||
/**
|
||||
* Write escape sequences to disable all mouse tracking modes and reset terminal state.
|
||||
* This is a safety net to ensure the terminal is clean after exit, even if the renderer's
|
||||
* cleanup didn't flush properly (e.g. on Windows).
|
||||
*/
|
||||
export function resetTerminalState() {
|
||||
const sequences = [
|
||||
"\x1b[?1000l", // disable normal mouse tracking
|
||||
"\x1b[?1002l", // disable button-event mouse tracking
|
||||
"\x1b[?1003l", // disable any-event mouse tracking (all movement)
|
||||
"\x1b[?1006l", // disable SGR extended mouse mode
|
||||
"\x1b[?1015l", // disable RXVT mouse mode
|
||||
"\x1b[<u", // pop/disable Kitty keyboard protocol
|
||||
"\x1b[0m", // reset text attributes
|
||||
]
|
||||
try {
|
||||
process.stdout.write(sequences.join(""))
|
||||
} catch (err) {
|
||||
console.error("resetTerminalState failed", err)
|
||||
}
|
||||
}
|
||||
// kilocode_change end
|
||||
|
||||
export namespace Terminal {
|
||||
export type Colors = Awaited<ReturnType<typeof colors>>
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user