diff options
author | Canop <cano.petrole@gmail.com> | 2020-11-25 23:21:23 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-11-25 23:21:23 +0100 |
commit | 9785535f80573a9b00d2ce738f0c5a8df81db392 (patch) | |
tree | 12486770f50cccd14ea38a873bbe191469938c47 /src/display | |
parent | ba9dbf6c0a3827fe6299f3de582db6fc1ce9362a (diff) |
[WIP] high-definition image preview when using kitty
(some cleaning to do but I need to sleep)
Diffstat (limited to 'src/display')
-rw-r--r-- | src/display/mod.rs | 12 | ||||
-rw-r--r-- | src/display/terminal_dimensions.rs | 38 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/display/mod.rs b/src/display/mod.rs index 8ed1fb2..c075b0c 100644 --- a/src/display/mod.rs +++ b/src/display/mod.rs @@ -30,6 +30,7 @@ pub mod flags_display; pub mod status_line; mod matched_string; mod screen; +mod terminal_dimensions; #[cfg(not(any(target_family="windows",target_os="android")))] mod permissions; @@ -43,6 +44,7 @@ pub use { git_status_display::GitStatusDisplay, matched_string::MatchedString, screen::Screen, + terminal_dimensions::*, }; use { crate::{ @@ -74,6 +76,7 @@ lazy_static! { pub const WIDE_STATUS: bool = true; /// the type used by all GUI writing functions +//pub type W = std::io::BufWriter<std::io::Stderr>; pub type W = std::io::BufWriter<std::io::Stderr>; /// return the writer used by the application @@ -81,6 +84,15 @@ pub fn writer() -> W { std::io::BufWriter::new(std::io::stderr()) } +// /// the type used by all GUI writing functions +// //pub type W = std::io::BufWriter<std::io::Stderr>; +// pub type W = std::io::Stdout; +// +// /// return the writer used by the application +// pub fn writer() -> W { +// std::io::stdout() +// } + pub fn fill_bg( w: &mut W, diff --git a/src/display/terminal_dimensions.rs b/src/display/terminal_dimensions.rs new file mode 100644 index 0000000..e90ae89 --- /dev/null +++ b/src/display/terminal_dimensions.rs @@ -0,0 +1,38 @@ +use { + libc::{ + c_ushort, + ioctl, + STDOUT_FILENO, + TIOCGWINSZ, + }, + std::io, +}; + + +#[cfg(unix)] +pub fn cell_size_in_pixels() -> io::Result<(u32, u32)> { + // see http://www.delorie.com/djgpp/doc/libc/libc_495.html + #[repr(C)] + struct winsize { + ws_row: c_ushort, /* rows, in characters */ + ws_col: c_ushort, /* columns, in characters */ + ws_xpixel: c_ushort, /* horizontal size, pixels */ + ws_ypixel: c_ushort /* vertical size, pixels */ + }; + let w = winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0 }; + let r = unsafe { + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) + }; + if r == 0 && w.ws_xpixel > w.ws_col && w.ws_ypixel > w.ws_row { + Ok(( + (w.ws_xpixel / w.ws_col) as u32, + (w.ws_ypixel / w.ws_row) as u32, + )) + } else { + Err(io::Error::new( + io::ErrorKind::Other, + "failed to fetch terminal dimension with ioctl", + )) + } +} + |