2020-01-28 05:18:19 +01:00
|
|
|
module term
|
|
|
|
|
2020-01-28 20:25:17 +01:00
|
|
|
import os
|
2020-01-28 05:18:19 +01:00
|
|
|
|
2020-01-28 20:25:17 +01:00
|
|
|
#include <sys/ioctl.h>
|
2020-03-19 07:07:43 +01:00
|
|
|
|
2020-01-28 20:25:17 +01:00
|
|
|
pub struct C.winsize {
|
|
|
|
pub:
|
|
|
|
ws_row u16
|
|
|
|
ws_col u16
|
|
|
|
ws_xpixel u16
|
|
|
|
ws_ypixel u16
|
2020-01-28 05:18:19 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 20:25:17 +01:00
|
|
|
fn C.ioctl(fd int, request u64, arg voidptr) int
|
2020-01-28 05:18:19 +01:00
|
|
|
|
2020-01-29 05:12:12 +01:00
|
|
|
// get_terminal_size returns a number of colums and rows of terminal window.
|
2020-01-28 20:25:17 +01:00
|
|
|
pub fn get_terminal_size() (int,int) {
|
|
|
|
if is_atty(1) <= 0 || os.getenv('TERM') == 'dumb' {
|
2020-01-29 05:12:12 +01:00
|
|
|
return default_columns_size, default_rows_size
|
2020-01-28 20:25:17 +01:00
|
|
|
}
|
|
|
|
w := C.winsize{}
|
2020-01-29 05:12:12 +01:00
|
|
|
C.ioctl(1, C.TIOCGWINSZ, &w)
|
2020-01-28 20:25:17 +01:00
|
|
|
return int(w.ws_col),int(w.ws_row)
|
2020-01-28 05:18:19 +01:00
|
|
|
}
|