Skip to content

Commit dd0bc89

Browse files
committed
chore: move to rustix
1 parent c7f8075 commit dd0bc89

File tree

5 files changed

+23
-38
lines changed

5 files changed

+23
-38
lines changed

Cargo.lock

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

image/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ image.workspace = true
1515
[target.'cfg(not(windows))'.dependencies]
1616
color_quant = "1.1.0"
1717
base64 = "0.22.1"
18-
nix = { version = "0.30.1", features = ["poll", "term", "ioctl"] }
19-
rustix = { version = "1.1.2", features = ["termios"] }
18+
rustix = { version = "1.1.2", features = ["termios", "event"] }

image/src/kitty.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ use anyhow::{Context as _, Result};
22
use base64::{engine, Engine};
33
use image::{imageops::FilterType, DynamicImage};
44

5-
use nix::poll::{poll, PollFd, PollFlags, PollTimeout};
6-
use nix::sys::termios::{tcgetattr, tcsetattr, LocalFlags, SetArg};
7-
use nix::unistd::read;
8-
use rustix::termios::tcgetwinsize;
5+
use rustix::event::{poll, PollFd, PollFlags, Timespec};
6+
use rustix::io::read;
7+
use rustix::termios::{tcgetattr, tcgetwinsize, tcsetattr, LocalModes, OptionalActions};
98

109
use std::io::{stdout, Write};
1110
use std::os::fd::AsFd as _;
@@ -21,9 +20,9 @@ impl KittyBackend {
2120
let old = tcgetattr(&stdin).context("Failed to recieve terminal attibutes")?;
2221

2322
let mut new = old.clone();
24-
new.local_flags &= !LocalFlags::ICANON;
25-
new.local_flags &= !LocalFlags::ECHO;
26-
tcsetattr(&stdin, SetArg::TCSANOW, &new)
23+
new.local_modes &= !LocalModes::ICANON;
24+
new.local_modes &= !LocalModes::ECHO;
25+
tcsetattr(&stdin, OptionalActions::Now, &new)
2726
.context("Failed to update terminal attributes")?;
2827
old
2928
};
@@ -40,14 +39,15 @@ impl KittyBackend {
4039
stdout().flush()?;
4140

4241
let start_time = Instant::now();
43-
let mut stdin_pollfd = [PollFd::new(stdin.as_fd(), PollFlags::POLLIN)];
42+
let stdin_fd = stdin.as_fd();
43+
let mut stdin_pollfd = [PollFd::new(&stdin_fd, PollFlags::IN)];
4444
let allowed_bytes = [0x1B, b'_', b'G', b'\\'];
4545
let mut buf = Vec::<u8>::new();
4646
loop {
4747
// check for timeout while polling to avoid blocking the main thread
48-
while poll(&mut stdin_pollfd, PollTimeout::ZERO)? < 1 {
48+
while poll(&mut stdin_pollfd, Some(&Timespec::default()))? < 1 {
4949
if start_time.elapsed().as_millis() > 50 {
50-
tcsetattr(&stdin, SetArg::TCSANOW, &old_attributes)
50+
tcsetattr(&stdin, OptionalActions::Now, &old_attributes)
5151
.context("Failed to update terminal attributes")?;
5252
return Ok(false);
5353
}
@@ -58,7 +58,7 @@ impl KittyBackend {
5858
buf.push(byte[0]);
5959
}
6060
if buf.starts_with(&[0x1B, b'_', b'G']) && buf.ends_with(&[0x1B, b'\\']) {
61-
tcsetattr(&stdin, SetArg::TCSANOW, &old_attributes)
61+
tcsetattr(&stdin, OptionalActions::Now, &old_attributes)
6262
.context("Failed to update terminal attributes")?;
6363
return Ok(true);
6464
}

image/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use anyhow::Result;
22
use image::DynamicImage;
33

4-
54
#[derive(clap::ValueEnum, Clone, PartialEq, Eq, Debug)]
65
pub enum ImageProtocol {
76
Kitty,

image/src/sixel.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ use image::{
55
DynamicImage, GenericImageView, ImageBuffer, Pixel, Rgb,
66
};
77

8-
use nix::poll::{poll, PollFd, PollFlags, PollTimeout};
9-
use nix::sys::termios::{tcgetattr, tcsetattr, LocalFlags, SetArg};
10-
use nix::unistd::read;
11-
use rustix::termios::tcgetwinsize;
8+
use rustix::event::{poll, PollFd, PollFlags, Timespec};
9+
use rustix::io::read;
10+
use rustix::termios::{tcgetattr, tcgetwinsize, tcsetattr, LocalModes, OptionalActions};
1211

1312
use std::io::{stdout, Write};
1413
use std::os::fd::AsFd;
@@ -24,9 +23,9 @@ impl SixelBackend {
2423
let old = tcgetattr(&stdin).context("Failed to recieve terminal attibutes")?;
2524

2625
let mut new = old.clone();
27-
new.local_flags &= !LocalFlags::ICANON;
28-
new.local_flags &= !LocalFlags::ECHO;
29-
tcsetattr(&stdin, SetArg::TCSANOW, &new)
26+
new.local_modes &= !LocalModes::ICANON;
27+
new.local_modes &= !LocalModes::ECHO;
28+
tcsetattr(&stdin, OptionalActions::Now, &new)
3029
.context("Failed to update terminal attributes")?;
3130
old
3231
};
@@ -36,13 +35,14 @@ impl SixelBackend {
3635
stdout().flush()?;
3736

3837
let start_time = Instant::now();
39-
let mut stdin_pollfd = [PollFd::new(stdin.as_fd(), PollFlags::POLLIN)];
38+
let stdin_fd = stdin.as_fd();
39+
let mut stdin_pollfd = [PollFd::new(&stdin_fd, PollFlags::IN)];
4040
let mut buf = Vec::<u8>::new();
4141
loop {
4242
// check for timeout while polling to avoid blocking the main thread
43-
while poll(&mut stdin_pollfd, PollTimeout::ZERO)? < 1 {
43+
while poll(&mut stdin_pollfd, Some(&Timespec::default()))? < 1 {
4444
if start_time.elapsed().as_millis() > 50 {
45-
tcsetattr(stdin, SetArg::TCSANOW, &old_attributes)
45+
tcsetattr(stdin, OptionalActions::Now, &old_attributes)
4646
.context("Failed to update terminal attributes")?;
4747
return Ok(false);
4848
}
@@ -53,7 +53,7 @@ impl SixelBackend {
5353
if buf.starts_with(&[0x1B, b'[', b'?']) && buf.ends_with(b"c") {
5454
for attribute in buf[3..(buf.len() - 1)].split(|x| *x == b';') {
5555
if attribute == [b'4'] {
56-
tcsetattr(stdin, SetArg::TCSANOW, &old_attributes)
56+
tcsetattr(stdin, OptionalActions::Now, &old_attributes)
5757
.context("Failed to update terminal attributes")?;
5858
return Ok(true);
5959
}

0 commit comments

Comments
 (0)