aboutsummaryrefslogtreecommitdiffstats
path: root/src/tiocgwinsz.rs
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2023-12-26 18:11:55 -0800
committerRose Hogenson <rosehogenson@posteo.net>2023-12-26 18:11:55 -0800
commit9f6447adb277ac7ea6332600d56b98666189168e (patch)
tree75a06e33220d93ea682d4c4904bb62e1e1d9c90a /src/tiocgwinsz.rs
parentAdd the basic rope. (diff)
downloadeditor-9f6447adb277ac7ea6332600d56b98666189168e.tar.zst
Add function to get terminal size.
Diffstat (limited to 'src/tiocgwinsz.rs')
-rw-r--r--src/tiocgwinsz.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/tiocgwinsz.rs b/src/tiocgwinsz.rs
new file mode 100644
index 0000000..9fdf9a4
--- /dev/null
+++ b/src/tiocgwinsz.rs
@@ -0,0 +1,18 @@
+use libc::{c_int, winsize};
+
+pub fn size() -> Option<winsize> {
+ let mut window: winsize = winsize {
+ ws_row: 0,
+ ws_col: 0,
+ ws_xpixel: 0,
+ ws_ypixel: 0,
+ };
+ let result: c_int;
+ unsafe {
+ result = libc::ioctl(0, libc::TIOCGWINSZ, &mut window);
+ }
+ if result < 0 {
+ return None;
+ }
+ return Some(window);
+}