diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-16 12:50:53 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-16 12:50:53 -0400 |
commit | 78933dcd8c55f9f14386342b3e6f63285bd59fec (patch) | |
tree | 20dd75fe68c36590331450e3b276089eb54db2b2 /src/cmd/stream.rs | |
parent | 85e5c74a8bce3956163d80f8fbee3cf4ad516bac (diff) | |
download | teleterm-78933dcd8c55f9f14386342b3e6f63285bd59fec.tar.gz teleterm-78933dcd8c55f9f14386342b3e6f63285bd59fec.zip |
ensure that all bytes coming from the terminal actually get written
it's not actually safe to just skip over bytes when we see a reset
escape sequence, because there might be other escape sequences changing
the terminal state that don't get cleared by a reset. for instance,
starting vim sends "switch to alternate screen" followed by "reset", and
if those two come in the same packet, we were previously dropping the
"switch to alternate screen" escape sequence, causing incorrect display.
Diffstat (limited to 'src/cmd/stream.rs')
-rw-r--r-- | src/cmd/stream.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs index c1e1efa..c1d62c6 100644 --- a/src/cmd/stream.rs +++ b/src/cmd/stream.rs @@ -178,15 +178,14 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> } fn record_bytes(&mut self, buf: &[u8]) { - let truncated = self.buffer.append(buf); - if truncated > self.sent_local { - self.sent_local = 0; - } else { - self.sent_local -= truncated; - } - if truncated > self.sent_remote { - self.sent_remote = 0; + let written = if self.connected { + self.sent_local.min(self.sent_remote) } else { + self.sent_local + }; + let truncated = self.buffer.append(buf, written); + self.sent_local -= truncated; + if self.connected { self.sent_remote -= truncated; } } |