-
Notifications
You must be signed in to change notification settings - Fork 850
fix(shell): disable kitty keys in VS Code #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| import sys | ||
| import time | ||
|
|
||
| from kimi_cli.utils.envvar import get_env_bool | ||
|
|
||
|
|
||
| def ensure_new_line() -> None: | ||
| """Ensure the next prompt starts at column 0 regardless of prior command output.""" | ||
|
|
@@ -50,6 +52,33 @@ def ensure_tty_sane() -> None: | |
| termios.tcsetattr(fd, termios.TCSADRAIN, attrs) | ||
|
|
||
|
|
||
| def maybe_disable_kitty_keyboard_protocol() -> None: | ||
| """Disable kitty keyboard protocol in terminals that send CSI-u sequences. | ||
|
|
||
| This is primarily a workaround for VS Code's integrated terminal, which can | ||
| emit CSI-u key sequences that prompt_toolkit doesn't parse. | ||
| """ | ||
| if sys.platform == "win32": | ||
| return | ||
| if not sys.stdout.isatty() or not sys.stdin.isatty(): | ||
| return | ||
| if not _should_disable_kitty_keyboard_protocol(): | ||
| return | ||
|
|
||
| _write_escape("\x1b[<u") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| def _should_disable_kitty_keyboard_protocol() -> bool: | ||
| env_value = os.getenv("KIMI_CLI_DISABLE_KITTY_KEYS") | ||
| if env_value is not None: | ||
| return get_env_bool("KIMI_CLI_DISABLE_KITTY_KEYS", default=False) | ||
| return _is_vscode_terminal() | ||
|
|
||
|
|
||
| def _is_vscode_terminal() -> bool: | ||
| return os.getenv("TERM_PROGRAM") == "vscode" or "VSCODE_IPC_HOOK_CLI" in os.environ | ||
|
|
||
|
|
||
| def _cursor_position_unix() -> tuple[int, int] | None: | ||
| """Get cursor position (row, column) on Unix. Both are 1-indexed.""" | ||
| assert sys.platform != "win32" | ||
|
|
@@ -149,6 +178,11 @@ def _write_newline() -> None: | |
| sys.stdout.flush() | ||
|
|
||
|
|
||
| def _write_escape(value: str) -> None: | ||
| sys.stdout.write(value) | ||
| sys.stdout.flush() | ||
|
|
||
|
|
||
| def get_cursor_row() -> int | None: | ||
| """Get the current cursor row (1-indexed).""" | ||
| if not sys.stdout.isatty() or not sys.stdin.isatty(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 NameError:
_mcp_status_block,_mcp_status_loading, and_bg_task_countare used but no longer definedThe PR deleted the local function/class definitions for
_mcp_status_block,_mcp_status_loading,_BgCountCache, and_bg_task_count(previously at old lines 200-230) but left the references to them at lines 204-206 when constructing theCustomPromptSession. This means entering the interactive shell (Shell.run()without a command) will immediately crash with aNameError. This breaks the primary interactive mode of the CLI.(Refers to lines 204-206)
Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.