From bd5fcb00e0c4b6479f323e9192fba99bef4206da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Nov 2023 21:22:41 +0530 Subject: [PATCH] Fix regression that broke quick exit from ssh kitten --- kittens/ssh/main.go | 13 ++++++++----- kitty/window.py | 1 + shell-integration/ssh/bootstrap.sh | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/kittens/ssh/main.go b/kittens/ssh/main.go index 4792b355e..7b2b6358d 100644 --- a/kittens/ssh/main.go +++ b/kittens/ssh/main.go @@ -524,16 +524,20 @@ func get_remote_command(cd *connection_data) error { return nil } +var debugprintln = tty.DebugPrintln +var _ = debugprintln + func drain_potential_tty_garbage(term *tty.Term) { - err := term.ApplyOperations(tty.TCSANOW, tty.SetNoEcho) + err := term.ApplyOperations(tty.TCSANOW, tty.SetRaw) if err != nil { return } - canary, err := secrets.TokenBase64() + canary, err := secrets.TokenHex() if err != nil { return } - dcs, err := tui.DCSToKitty("echo", canary+"\n\r") + dcs, err := tui.DCSToKitty("echo", canary) + q := utils.UnsafeStringToBytes(canary) if err != nil { return } @@ -541,7 +545,6 @@ func drain_potential_tty_garbage(term *tty.Term) { if err != nil { return } - q := utils.UnsafeStringToBytes(canary) data := make([]byte, 0) give_up_at := time.Now().Add(2 * time.Second) buf := make([]byte, 0, 8192) @@ -553,7 +556,7 @@ func drain_potential_tty_garbage(term *tty.Term) { } n, err := term.ReadWithTimeout(buf, timeout) if err != nil { - return + break } data = append(data, buf[:n]...) } diff --git a/kitty/window.py b/kitty/window.py index ca560a658..c562a9de4 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -1194,6 +1194,7 @@ class Window: def handle_remote_echo(self, msg: str) -> None: from base64 import standard_b64decode data = standard_b64decode(msg) + data = re.sub(rb'[^a-zA-Z0-9]', b'', data) self.write_to_child(data) def handle_remote_ssh(self, msg: str) -> None: diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 74e20bd52..1a272020a 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -74,7 +74,6 @@ fi dcs_to_kitty() { printf "\033P@kitty-$1|%s\033\134" "$(printf "%s" "$2" | base64_encode)" > /dev/tty; } debug() { dcs_to_kitty "print" "debug: $1"; } -echo_via_kitty() { dcs_to_kitty "echo" "$1"; } # If $HOME is configured set it here EXPORT_HOME_CMD