summaryrefslogtreecommitdiffstats
path: root/src/display
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-11-27 20:47:34 +0100
committerCanop <cano.petrole@gmail.com>2020-11-27 20:47:34 +0100
commit273ccc6355c588460804482872ea61b488406c4f (patch)
tree7003101ddb83f8d41447980c2a730479d21945ff /src/display
parentf1a05da9e1f7abcf00c90c54a75eca354351c7e8 (diff)
parent3f04afa264751f30fc5da7bda1bcac7252b6589d (diff)
version 1.0.7
Diffstat (limited to 'src/display')
-rw-r--r--src/display/cell_size.rs42
-rw-r--r--src/display/mod.rs4
2 files changed, 45 insertions, 1 deletions
diff --git a/src/display/cell_size.rs b/src/display/cell_size.rs
new file mode 100644
index 0000000..01f1fc3
--- /dev/null
+++ b/src/display/cell_size.rs
@@ -0,0 +1,42 @@
+
+/// find and return the size of a cell (a char location) in pixels
+/// as (width, height).
+/// Many terminals don't fill this information correctly, so an
+/// error is expected (it works on kitty, where I use the data
+/// to compute the rendering dimensions of images)
+#[cfg(unix)]
+pub fn cell_size_in_pixels() -> std::io::Result<(u32, u32)> {
+ use {
+ libc::{
+ c_ushort,
+ ioctl,
+ STDOUT_FILENO,
+ TIOCGWINSZ,
+ },
+ std::io,
+ };
+ // 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",
+ ))
+ }
+}
+
diff --git a/src/display/mod.rs b/src/display/mod.rs
index 8ed1fb2..5db1f1e 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 cell_size;
#[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,
+ cell_size::*,
};
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,7 +84,6 @@ pub fn writer() -> W {
std::io::BufWriter::new(std::io::stderr())
}
-
pub fn fill_bg(
w: &mut W,
len: usize,