Add terminal_size_pixels() to expose terminal's pixel size
This commit is contained in:
parent
7853c0251d
commit
574f863676
|
@ -22,6 +22,8 @@ mod sys;
|
||||||
mod sys;
|
mod sys;
|
||||||
|
|
||||||
pub use sys::size::terminal_size;
|
pub use sys::size::terminal_size;
|
||||||
|
#[cfg(all(unix, not(target_os = "redox")))]
|
||||||
|
pub use sys::size::terminal_size_pixels;
|
||||||
pub use sys::tty::{is_tty, get_tty};
|
pub use sys::tty::{is_tty, get_tty};
|
||||||
|
|
||||||
mod async;
|
mod async;
|
||||||
|
|
|
@ -7,8 +7,8 @@ use super::libc::{c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ};
|
||||||
struct TermSize {
|
struct TermSize {
|
||||||
row: c_ushort,
|
row: c_ushort,
|
||||||
col: c_ushort,
|
col: c_ushort,
|
||||||
_x: c_ushort,
|
x: c_ushort,
|
||||||
_y: c_ushort,
|
y: c_ushort,
|
||||||
}
|
}
|
||||||
/// Get the size of the terminal.
|
/// Get the size of the terminal.
|
||||||
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
|
@ -18,3 +18,12 @@ pub fn terminal_size() -> io::Result<(u16, u16)> {
|
||||||
Ok((size.col as u16, size.row as u16))
|
Ok((size.col as u16, size.row as u16))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the size of the terminal, in pixels
|
||||||
|
pub fn terminal_size_pixels() -> io::Result<(u16, u16)> {
|
||||||
|
unsafe {
|
||||||
|
let mut size: TermSize = mem::zeroed();
|
||||||
|
cvt(ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut size as *mut _))?;
|
||||||
|
Ok((size.x as u16, size.y as u16))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue