From 96cf3716e32366471372d7c84d6aba48a7c34a0c Mon Sep 17 00:00:00 2001 From: kumavale Date: Tue, 31 Dec 2024 16:22:36 +0900 Subject: [PATCH 1/3] build(deps)!: update nix --- Cargo.toml | 2 +- src/lib.rs | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51e7d74..7e89e79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ features = [ libc = "0.2" [target.'cfg(unix)'.dependencies] -nix = "0.26" +nix = { version = "0.29", features = ["term"] } diff --git a/src/lib.rs b/src/lib.rs index 8a685b6..1662c6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,9 +118,11 @@ impl Getch { #[cfg(not(windows))] #[allow(clippy::new_without_default)] pub fn new() -> Self { + let stdin = std::io::stdin(); + // Quering original as a separate, since `Termios` does not implement copy - let orig_term = termios::tcgetattr(0).unwrap(); - let mut raw_termios = termios::tcgetattr(0).unwrap(); + let orig_term = termios::tcgetattr(&stdin).unwrap(); + let mut raw_termios = termios::tcgetattr(&stdin).unwrap(); // Unset canonical mode, so we get characters immediately raw_termios.local_flags.remove(termios::LocalFlags::ICANON); @@ -129,7 +131,7 @@ impl Getch { // Disable local echo raw_termios.local_flags.remove(termios::LocalFlags::ECHO); - termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); + termios::tcsetattr(&stdin, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); Self { orig_term, @@ -189,9 +191,10 @@ pub fn enable_echo_input() { #[cfg(not(windows))] { - let mut raw_termios = termios::tcgetattr(0).unwrap(); + let stdin = std::io::stdin(); + let mut raw_termios = termios::tcgetattr(&stdin).unwrap(); raw_termios.local_flags.insert(termios::LocalFlags::ECHO); - termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); + termios::tcsetattr(&stdin, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); } } @@ -213,9 +216,10 @@ pub fn disable_echo_input() { #[cfg(not(windows))] { - let mut raw_termios = termios::tcgetattr(0).unwrap(); + let stdin = std::io::stdin(); + let mut raw_termios = termios::tcgetattr(&stdin).unwrap(); raw_termios.local_flags.remove(termios::LocalFlags::ECHO); - termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); + termios::tcsetattr(&stdin, termios::SetArg::TCSADRAIN, &raw_termios).unwrap(); } } @@ -373,6 +377,7 @@ impl Drop for Getch { #[cfg(not(windows))] fn drop(&mut self) { - termios::tcsetattr(0, termios::SetArg::TCSADRAIN, &self.orig_term).unwrap(); + let stdin = std::io::stdin(); + termios::tcsetattr(&stdin, termios::SetArg::TCSADRAIN, &self.orig_term).unwrap(); } } From 746ef54868a3c9b7bf0466823750e5ebfed7996e Mon Sep 17 00:00:00 2001 From: kumavale Date: Tue, 31 Dec 2024 16:24:08 +0900 Subject: [PATCH 2/3] chore: clippy --- src/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1662c6f..e4c2133 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,17 +7,15 @@ //! ```no_run //! use getch_rs::{Getch, Key}; //! -//! fn main() { -//! let g = Getch::new(); +//! let g = Getch::new(); //! -//! println!("press `q` to exit"); +//! println!("press `q` to exit"); //! -//! loop { -//! match g.getch() { -//! Ok(Key::Char('q')) => break, -//! Ok(key) => println!("{:?}", key), -//! Err(e) => println!("{}", e), -//! } +//! loop { +//! match g.getch() { +//! Ok(Key::Char('q')) => break, +//! Ok(key) => println!("{:?}", key), +//! Err(e) => println!("{}", e), //! } //! } //! ``` From 21f497cb330a731fd4ca626f8f3205e8784a0ab5 Mon Sep 17 00:00:00 2001 From: kumavale Date: Tue, 31 Dec 2024 16:24:58 +0900 Subject: [PATCH 3/3] chore: update nix --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7e89e79..e51c46d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,4 +24,4 @@ features = [ libc = "0.2" [target.'cfg(unix)'.dependencies] -nix = { version = "0.29", features = ["term"] } +nix = { version = "0.29.0", features = ["term"] }