2020-01-28 07:18:19 +03:00
|
|
|
module term
|
|
|
|
|
2020-01-29 01:44:57 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
struct C.SMALL_RECT {
|
|
|
|
Left i16
|
|
|
|
Top i16
|
|
|
|
Right i16
|
|
|
|
Bottom i16
|
|
|
|
}
|
|
|
|
|
|
|
|
struct C.CONSOLE_SCREEN_BUFFER_INFO {
|
|
|
|
dwSize C.COORD
|
|
|
|
dwCursorPosition C.COORD
|
|
|
|
wAttributes C.COORD
|
|
|
|
srWindow C.SMALL_RECT
|
|
|
|
dwMaximumWindowSize C.COORD
|
|
|
|
}
|
|
|
|
|
2020-02-09 17:40:32 +03:00
|
|
|
fn C.GetConsoleScreenBufferInfo(handle os.HANDLE, info &CONSOLE_SCREEN_BUFFER_INFO) bool
|
2020-01-29 01:44:57 +03: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-03-20 23:15:45 +03:00
|
|
|
info := CONSOLE_SCREEN_BUFFER_INFO{}
|
2020-01-29 01:44:57 +03:00
|
|
|
|
|
|
|
if C.GetConsoleScreenBufferInfo(C.GetStdHandle(C.STD_OUTPUT_HANDLE), &info) {
|
2020-02-08 01:16:31 +03:00
|
|
|
columns := int(info.srWindow.Right - info.srWindow.Left + 1)
|
|
|
|
rows := int(info.srWindow.Bottom - info.srWindow.Top + 1)
|
2020-01-29 01:44:57 +03:00
|
|
|
return columns, rows
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 07:12:12 +03:00
|
|
|
return default_columns_size, default_rows_size
|
2020-01-28 07:18:19 +03:00
|
|
|
}
|