Skip to content
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

Upgrade nix to v0.28.0 #21

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ thiserror = "1.0.38"
which = "4.3.0"

[target.'cfg(unix)'.dependencies.nix]
version = "0.26.1"
version = "0.28.0"
default-features = false
features = ["fs", "term"]

Expand Down
13 changes: 6 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,15 +708,14 @@ mod unix {
use super::Error;

use nix::{
libc::STDIN_FILENO,
sys::termios::{
tcgetattr, tcsetattr, ControlFlags, InputFlags, LocalFlags, OutputFlags,
SetArg::TCSANOW, Termios,
},
unistd::isatty,
};

use std::{fs::OpenOptions, os::unix::prelude::AsRawFd};
use std::{fs::OpenOptions, io::stdin, os::fd::AsFd, os::unix::prelude::AsRawFd};

pub(crate) fn vt_cooked() -> Result<(), Error> {
write_termios(|t| {
Expand Down Expand Up @@ -759,14 +758,14 @@ mod unix {
}

fn write_termios(f: impl Fn(&mut Termios)) -> Result<(), Error> {
if isatty(STDIN_FILENO)? {
let mut t = tcgetattr(STDIN_FILENO)?;
if isatty(stdin().as_raw_fd())? {
let mut t = tcgetattr(stdin().as_fd())?;
reset_termios(&mut t);
f(&mut t);
tcsetattr(STDIN_FILENO, TCSANOW, &t)?;
tcsetattr(stdin().as_fd(), TCSANOW, &t)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain if this is the correct way to do this, but it was the easiest way I could find that didn't involve unsafe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(These methods changed to requiring AsFd rather than AsRawFd.)

} else {
let tty = OpenOptions::new().read(true).write(true).open("/dev/tty")?;
let fd = tty.as_raw_fd();
let fd = tty.as_fd();

let mut t = tcgetattr(fd)?;
reset_termios(&mut t);
Expand Down Expand Up @@ -1167,7 +1166,7 @@ impl<'a> Capability<'a> for ResetScrollback<'a> {

#[inline]
fn from(value: Option<&'a Value>) -> Option<Self> {
if let Some(&Value::String(ref value)) = value {
if let Some(Value::String(value)) = value {
Some(Self(Cow::Borrowed(value)))
} else {
None
Expand Down