-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add image positioning using terminal dimensions
- Loading branch information
Showing
10 changed files
with
126 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use libc::{c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ}; | ||
use log::warn; | ||
|
||
/// See http://www.delorie.com/djgpp/doc/libc/libc_495.html | ||
#[repr(C)] | ||
#[derive(Default)] | ||
pub struct Window { | ||
pub ws_row: c_ushort, /* rows, in characters */ | ||
pub ws_col: c_ushort, /* columns, in characters */ | ||
pub ws_xpixel: c_ushort, /* horizontal size, pixels */ | ||
pub ws_ypixel: c_ushort, /* vertical size, pixels */ | ||
} | ||
|
||
impl Window { | ||
/// Get a new `Window` instance with the terminal measurements. | ||
/// | ||
/// This function returns `None` if the ioctl call fails. | ||
pub fn try_new() -> Option<Self> { | ||
let mut win = Self::default(); | ||
#[allow(clippy::useless_conversion)] | ||
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut win) }; | ||
if r == 0 && win.ws_xpixel > win.ws_col && win.ws_ypixel > win.ws_row { | ||
return Some(win); | ||
} | ||
warn!("Could not determine cell dimensions."); | ||
None | ||
} | ||
|
||
pub fn cell_width(&self) -> u8 { | ||
(self.ws_xpixel / self.ws_col) as u8 | ||
} | ||
|
||
pub fn cell_height(&self) -> u8 { | ||
(self.ws_ypixel / self.ws_row) as u8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters