-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use termios from termios crate #717
Conversation
I agree reducing dependencies in general is a desirable goal. For the three linked issues above, the reduction of dependencies could be done without any negative effects. As for this PR however, I'd say the possible choice of keeping quantity of dependencies low, conflicts with the hopefully existing goal of increasing the quality of the crate. To my understanding, it is highly unlikely that the Lets start with one sentence from each crate description: nix
termios
The key point here of course being that While nix::sys::termios does talk about these abstractions in terms of safety, the implementation (by truncating the flags) fails to honor that documented requirements of the C API to avoid undefined behavior triumphs type safety. As noted in nix-rust/nix#2071, the undefined behavior always gets triggered on illumos, without any possibility in the API to avoid it. As the termios implementation merely passes the wrapped C struct unmodified, there are less moving parts and thus less risk. There's a point to be made that termios::tcsetattr() technically should probably be an unsafe function. With it too being able to trigger undefined behavior with invalid input. Considering the low-level expectation, and since termios::Termios documents every reasonable way to interface the API, I'm tempted to say that detail is best ignored. Another, more opinionated, factor to consider is whether For comparison I realize Alternatively, I could rewrite this PR to make the Yet another theoretically possible way forward would of course be for |
Ok, let's try and see. |
The termios interface from the nix crate is lacking a thought through design. Severely broken on at least one platform. Please see [#2071][] for details. The termios crate stays closer to the C API and thus both works with illumos and reduces the risk of bugs on other platforms. [#2071]: nix-rust/nix#2071
a2c20a8
to
c3a2d08
Compare
Thanks! A new branch have been pushed, fixing the rustfmt issue. Some thinking also went into platform compability, and one should probably consider the risk of previously working platforms breaking. As you pointed out, e.g. ios would break since termios v0.3.3 lacks knowledge about it. Hence I've posted dcuddeback/termios-rs#36 which, if merged, could make v0.3.4 of termios support pretty much any posix like system out there. 🤞 |
@@ -106,7 +106,8 @@ pub type Mode = PosixMode; | |||
impl RawMode for PosixMode { | |||
/// Disable RAW mode for the terminal. | |||
fn disable_raw_mode(&self) -> Result<()> { | |||
termios::tcsetattr(self.tty_in, SetArg::TCSADRAIN, &self.termios)?; | |||
let mut termios = self.termios; | |||
tcgetattr(self.tty_in, &mut termios)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this. Raw mode leaks. Resolved in #724.
tcgetattr(self.tty_in, &mut termios)?; | |
tcsetattr(self.tty_in, termios::TCSADRAIN, &mut termios)?; |
The termios interface from the nix crate is lacking a thought through design. Severely broken on at least one platform. Please see #2071 for details.
The termios crate stays closer to the C API and thus both works with illumos and reduces the risk of bugs on other platforms.