summaryrefslogtreecommitdiff
path: root/src/vtcol.rs
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2021-11-15 20:55:30 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2021-11-15 20:14:17 +0100
commitc43c6aa562c5222477f66d50179e368ca0f25a9b (patch)
tree7630730b7214fbe933413705c9820245cb4ddb2a /src/vtcol.rs
parent1a8e9bba39ed97634ae61ad146653071da666143 (diff)
downloadvtcol-c43c6aa562c5222477f66d50179e368ca0f25a9b.tar.gz
turn Fd into proper wrapper
Diffstat (limited to 'src/vtcol.rs')
-rw-r--r--src/vtcol.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/vtcol.rs b/src/vtcol.rs
index 2c41d7b..0cc713c 100644
--- a/src/vtcol.rs
+++ b/src/vtcol.rs
@@ -1,9 +1,10 @@
pub mod lib;
-use vtcol::{Palette, Scheme};
+use vtcol::{Fd, Palette, Scheme};
use anyhow::{anyhow, Result};
use std::{io::{self, BufWriter, Error},
+ os::unix::io::AsRawFd,
sync::atomic::{AtomicBool, Ordering}};
static VERBOSITY: AtomicBool = AtomicBool::new(false);
@@ -225,9 +226,9 @@ impl<'a> Job
let fd = get_console_fd()?;
vrb!("console fd: {}", fd);
- vtcol::ioctl_pio_cmap(fd, &pal)?;
+ vtcol::ioctl_pio_cmap(&fd, &pal)?;
- clear_term(fd)?;
+ clear_term(&fd)?;
vrb!("successfully enabled scheme {:?}", scheme);
/* It’s fine to leak the fd, the kernel will clean up anyways. */
Ok(())
@@ -238,7 +239,7 @@ impl<'a> Job
let fd = get_console_fd()?;
vrb!("console fd: {}", fd);
- let pal = vtcol::ioctl_gio_cmap(fd)?;
+ let pal = vtcol::ioctl_gio_cmap(&fd)?;
let scm = Scheme::from(pal);
vrb!("active scheme:");
@@ -255,7 +256,7 @@ impl<'a> Job
let fd = get_console_fd()?;
vrb!("console fd: {}", fd);
- let pal = vtcol::ioctl_gio_cmap(fd)?;
+ let pal = vtcol::ioctl_gio_cmap(&fd)?;
if pal == Palette::from(&one) {
Self::set_scheme(two)
@@ -289,11 +290,7 @@ fn fd_of_path(path: &std::path::Path) -> Option<vtcol::Fd>
let mut tty_type: libc::c_char = 0;
let res = unsafe {
- libc::ioctl(
- fd,
- vtcol::KDGKBTYPE,
- &mut tty_type as *mut _
- )
+ libc::ioctl(fd, vtcol::KDGKBTYPE, &mut tty_type as *mut _)
};
if res < 0 {
vrb!(" *> ioctl failed");
@@ -304,12 +301,12 @@ fn fd_of_path(path: &std::path::Path) -> Option<vtcol::Fd>
return None;
}
- Some(fd)
+ Some(Fd::from(fd))
},
}
}
-fn get_console_fd() -> Result<vtcol::Fd>
+fn get_console_fd() -> Result<Fd>
{
for path in CONSOLE_PATHS.iter() {
vrb!("trying path: {:?}", path);
@@ -322,12 +319,13 @@ fn get_console_fd() -> Result<vtcol::Fd>
Err(anyhow!("could not retrieve fd for any of the search paths"))
}
-fn write_to_term(fd: vtcol::Fd, buf: &str) -> Result<()>
+fn write_to_term(fd: &Fd, buf: &str) -> Result<()>
{
let len = buf.len() as libc::size_t;
- if unsafe { libc::write(fd, buf.as_ptr() as *const libc::c_void, len) }
- != len as isize
+ if unsafe {
+ libc::write(fd.as_raw_fd(), buf.as_ptr() as *const libc::c_void, len)
+ } != len as isize
{
Err(anyhow!(
"failed to write {} B to fd {}: {}",
@@ -340,7 +338,7 @@ fn write_to_term(fd: vtcol::Fd, buf: &str) -> Result<()>
}
}
-fn clear_term(fd: vtcol::Fd) -> Result<()>
+fn clear_term(fd: &Fd) -> Result<()>
{
let clear = "\x1b[2J";
let cursor = "\x1b[1;1H";