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.
This commit is contained in:
IGI-111 2016-10-27 22:03:29 +02:00 committed by ticki
parent 09d31132e2
commit 0e0b5be856
1 changed files with 4 additions and 1 deletions

View File

@ -54,6 +54,8 @@ pub struct RawTerminal<W: Write> {
#[cfg(not(target_os = "redox"))]
impl<W: Write> Drop for RawTerminal<W> {
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<W: Write> IntoRawMode for W {
#[cfg(not(target_os = "redox"))]
fn into_raw_mode(self) -> io::Result<RawTerminal<W>> {
fn into_raw_mode(mut self) -> io::Result<RawTerminal<W>> {
use termios::{cfmakeraw, get_terminal_attr, set_terminal_attr};
let (mut ios, exit) = get_terminal_attr();
@ -116,6 +118,7 @@ impl<W: Write> 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,