From 09d31132e2d6236ae3a4d0c93f9f853a9bd1a3fe Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 27 Oct 2016 13:02:29 -0700 Subject: [PATCH 1/3] Protects AsyncReader::read against empty buffer. (#65) Move the check to the beginning of the loop to protect against empty buffer. --- src/async.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/async.rs b/src/async.rs index a7ec891..1db9429 100644 --- a/src/async.rs +++ b/src/async.rs @@ -51,14 +51,14 @@ impl Read for AsyncReader { let mut total = 0; loop { + if total >= buf.len() { + break; + } + match self.recv.try_recv() { Ok(Ok(b)) => { buf[total] = b; total += 1; - - if total == buf.len() { - break; - } }, Ok(Err(e)) => return Err(e), Err(_) => break, From 0e0b5be856fff602513f940d00fe954faecdd905 Mon Sep 17 00:00:00 2001 From: IGI-111 Date: Thu, 27 Oct 2016 22:03:29 +0200 Subject: [PATCH 2/3] Added true terminal restoration (#66) Using the "alternate screen" capability, the RawTerminal trait restores the terminal in its previous state by sending the proper escape codes. --- src/raw.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/raw.rs b/src/raw.rs index 20a07f9..39a0391 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -54,6 +54,8 @@ pub struct RawTerminal { #[cfg(not(target_os = "redox"))] impl Drop for RawTerminal { fn drop(&mut self) { + write!(self, csi!("r")).unwrap(); + write!(self, csi!("?1049l")).unwrap(); use termios::set_terminal_attr; set_terminal_attr(&mut self.prev_ios as *mut _); } @@ -100,7 +102,7 @@ pub trait IntoRawMode: Write + Sized { impl IntoRawMode for W { #[cfg(not(target_os = "redox"))] - fn into_raw_mode(self) -> io::Result> { + fn into_raw_mode(mut self) -> io::Result> { use termios::{cfmakeraw, get_terminal_attr, set_terminal_attr}; let (mut ios, exit) = get_terminal_attr(); @@ -116,6 +118,7 @@ impl IntoRawMode for W { if set_terminal_attr(&mut ios as *mut _) != 0 { Err(io::Error::new(io::ErrorKind::Other, "Unable to set Termios attribute.")) } else { + write!(self, csi!("?1049h")).unwrap(); let res = RawTerminal { prev_ios: prev_ios, output: self, From bb8d1704cd9c1292244d1b00c948e285e02c57d6 Mon Sep 17 00:00:00 2001 From: ticki Date: Thu, 27 Oct 2016 22:09:41 +0200 Subject: [PATCH 3/3] Revert "True terminal restoration" (#67) --- src/raw.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/raw.rs b/src/raw.rs index 39a0391..20a07f9 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -54,8 +54,6 @@ pub struct RawTerminal { #[cfg(not(target_os = "redox"))] impl Drop for RawTerminal { fn drop(&mut self) { - write!(self, csi!("r")).unwrap(); - write!(self, csi!("?1049l")).unwrap(); use termios::set_terminal_attr; set_terminal_attr(&mut self.prev_ios as *mut _); } @@ -102,7 +100,7 @@ pub trait IntoRawMode: Write + Sized { impl IntoRawMode for W { #[cfg(not(target_os = "redox"))] - fn into_raw_mode(mut self) -> io::Result> { + fn into_raw_mode(self) -> io::Result> { use termios::{cfmakeraw, get_terminal_attr, set_terminal_attr}; let (mut ios, exit) = get_terminal_attr(); @@ -118,7 +116,6 @@ impl IntoRawMode for W { if set_terminal_attr(&mut ios as *mut _) != 0 { Err(io::Error::new(io::ErrorKind::Other, "Unable to set Termios attribute.")) } else { - write!(self, csi!("?1049h")).unwrap(); let res = RawTerminal { prev_ios: prev_ios, output: self,