2020-01-28 05:18:19 +01:00
|
|
|
module term
|
|
|
|
|
2020-01-28 23:44:57 +01:00
|
|
|
import os
|
|
|
|
|
2020-04-04 11:56:43 +02:00
|
|
|
struct Coord {
|
|
|
|
x i16
|
|
|
|
y i16
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SmallRect {
|
2020-05-16 16:12:23 +02:00
|
|
|
left i16
|
|
|
|
top i16
|
|
|
|
right i16
|
|
|
|
bottom i16
|
2020-01-28 23:44:57 +01:00
|
|
|
}
|
|
|
|
|
2020-04-04 11:56:43 +02:00
|
|
|
struct ConsoleScreenBufferInfo {
|
2020-05-16 16:12:23 +02:00
|
|
|
dw_size Coord
|
|
|
|
dw_cursor_position Coord
|
|
|
|
w_attributes u16
|
|
|
|
sr_window SmallRect
|
|
|
|
dw_maximum_window_size Coord
|
2020-01-28 23:44:57 +01:00
|
|
|
}
|
|
|
|
|
2020-04-04 11:56:43 +02:00
|
|
|
fn C.GetConsoleScreenBufferInfo(handle os.HANDLE, info &ConsoleScreenBufferInfo) bool
|
2020-01-28 23:44:57 +01:00
|
|
|
|
|
|
|
// get_terminal_size returns a number of colums and rows of terminal window.
|
|
|
|
pub fn get_terminal_size() (int, int) {
|
|
|
|
if is_atty(1) > 0 && os.getenv('TERM') != 'dumb' {
|
2020-04-04 11:56:43 +02:00
|
|
|
info := ConsoleScreenBufferInfo{}
|
2020-01-28 23:44:57 +01:00
|
|
|
if C.GetConsoleScreenBufferInfo(C.GetStdHandle(C.STD_OUTPUT_HANDLE), &info) {
|
2020-05-16 16:12:23 +02:00
|
|
|
columns := int(info.sr_window.right - info.sr_window.left + 1)
|
|
|
|
rows := int(info.sr_window.bottom - info.sr_window.top + 1)
|
2020-01-28 23:44:57 +01:00
|
|
|
return columns, rows
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 05:12:12 +01:00
|
|
|
return default_columns_size, default_rows_size
|
2020-01-28 05:18:19 +01:00
|
|
|
}
|