From 40fc4ac2af1bf83c56be9bdfd8b660c75fce46f8 Mon Sep 17 00:00:00 2001 From: gwenn <gtreguier@gmail.com> Date: Sun, 4 Feb 2018 16:18:22 +0100 Subject: [PATCH] Upgrade to nix 0.10 --- Cargo.toml | 2 +- src/lib.rs | 8 ++++---- src/tty/unix.rs | 25 +++++++++++++------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbc80411..643422d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ unicode-width = "0.1" unicode-segmentation = "1.0" [target.'cfg(unix)'.dependencies] -nix = "0.9" +nix = "0.10" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["consoleapi", "handleapi", "minwindef", "processenv", "winbase", "wincon", "winuser"] } diff --git a/src/lib.rs b/src/lib.rs index b7106a4e..59e335be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,8 @@ //! let mut rl = rustyline::Editor::<()>::new(); //! let readline = rl.readline(">> "); //! match readline { -//! Ok(line) => println!("Line: {:?}",line), -//! Err(_) => println!("No input"), +//! Ok(line) => println!("Line: {:?}", line), +//! Err(_) => println!("No input"), //! } //! ``` #![feature(io)] @@ -1263,10 +1263,10 @@ impl<H: Helper> Editor<H> { /// match readline { /// Ok(line) => { /// println!("Line: {}", line); - /// }, + /// } /// Err(err) => { /// println!("Error: {:?}", err); - /// break + /// break; /// } /// } /// } diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 72655c7f..bd24e930 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -6,7 +6,7 @@ use std::sync::atomic; use libc; use nix; -use nix::poll; +use nix::poll::{self, EventFlags}; use nix::sys::signal; use nix::sys::termios; use nix::sys::termios::SetArg; @@ -262,7 +262,7 @@ impl RawReader for PosixRawReader { let mut key = consts::char_to_key_press(c); if key == KeyPress::Esc { - let mut fds = [poll::PollFd::new(STDIN_FILENO, poll::POLLIN)]; + let mut fds = [poll::PollFd::new(STDIN_FILENO, EventFlags::POLLIN)]; match poll::poll(&mut fds, self.timeout_ms) { Ok(n) if n == 0 => { // single escape @@ -361,8 +361,8 @@ impl Renderer for PosixRenderer { // calculate the desired position of the cursor let cursor = self.calculate_position(&line[..line.pos()], prompt_size); - // self.old_rows < self.cursor.row if the prompt spans multiple lines and if this is the - // default State. + // self.old_rows < self.cursor.row if the prompt spans multiple lines and if + // this is the default State. let cursor_row_movement = old_rows.checked_sub(current_row).unwrap_or(0); // move the cursor down as required if cursor_row_movement > 0 { @@ -567,9 +567,7 @@ impl Term for PosixTerminal { fn enable_raw_mode(&self) -> Result<Mode> { use nix::errno::Errno::ENOTTY; - use nix::sys::termios::{CS8, BRKINT, ECHO, ICANON, ICRNL, IEXTEN, INPCK, ISIG, ISTRIP, - IXON /* OPOST, */}; - use nix::sys::termios::SpecialCharacterIndices; + use nix::sys::termios::{ControlFlags, InputFlags, LocalFlags, SpecialCharacterIndices}; if !self.stdin_isatty { try!(Err(nix::Error::from_errno(ENOTTY))); } @@ -577,12 +575,15 @@ impl Term for PosixTerminal { let mut raw = original_mode.clone(); // disable BREAK interrupt, CR to NL conversion on input, // input parity check, strip high bit (bit 8), output flow control - raw.input_flags &= !(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + raw.input_flags &= !(InputFlags::BRKINT | InputFlags::ICRNL | InputFlags::INPCK + | InputFlags::ISTRIP | InputFlags::IXON); // we don't want raw output, it turns newlines into straight linefeeds - // raw.c_oflag = raw.c_oflag & !(OPOST); // disable all output processing - raw.control_flags |= CS8; // character-size mark (8 bits) - // disable echoing, canonical mode, extended input processing and signals - raw.local_flags &= !(ECHO | ICANON | IEXTEN | ISIG); + // raw.c_oflag = raw.c_oflag & !(OutputFlags::OPOST); // disable all output + // processing + raw.control_flags |= ControlFlags::CS8; // character-size mark (8 bits) + // disable echoing, canonical mode, extended input processing and signals + raw.local_flags &= + !(LocalFlags::ECHO | LocalFlags::ICANON | LocalFlags::IEXTEN | LocalFlags::ISIG); raw.control_chars[SpecialCharacterIndices::VMIN as usize] = 1; // One character-at-a-time input raw.control_chars[SpecialCharacterIndices::VTIME as usize] = 0; // with blocking read try!(termios::tcsetattr(STDIN_FILENO, SetArg::TCSADRAIN, &raw)); -- GitLab