2020-01-28 07:18:19 +03:00
|
|
|
module term
|
|
|
|
|
2020-01-28 22:25:17 +03:00
|
|
|
import os
|
2020-01-28 07:18:19 +03:00
|
|
|
|
2020-01-28 22:25:17 +03:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
pub struct C.winsize {
|
|
|
|
pub:
|
|
|
|
ws_row u16
|
|
|
|
ws_col u16
|
|
|
|
ws_xpixel u16
|
|
|
|
ws_ypixel u16
|
2020-01-28 07:18:19 +03:00
|
|
|
}
|
|
|
|
|
2020-01-28 22:25:17 +03:00
|
|
|
fn C.ioctl(fd int, request u64, arg voidptr) int
|
2020-01-28 07:18:19 +03:00
|
|
|
|
|
|
|
|
2020-01-28 22:25:17 +03:00
|
|
|
pub fn get_terminal_size() (int,int) {
|
|
|
|
if is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
|
|
|
|
return 80,25
|
|
|
|
}
|
|
|
|
w := C.winsize{}
|
2020-01-28 07:18:19 +03:00
|
|
|
C.ioctl(0, C.TIOCGWINSZ, &w)
|
2020-01-28 22:25:17 +03:00
|
|
|
return int(w.ws_col),int(w.ws_row)
|
2020-01-28 07:18:19 +03:00
|
|
|
}
|