42 lines
969 B
Plaintext
42 lines
969 B
Plaintext
get_console_size :: () -> s64, s64 {
|
|
//@Hack - This is terrible, but this is typically called only once, so maybe it doesn't matter...
|
|
width := string_to_int(get_stdout_from_cmd("tput cols"));
|
|
height := string_to_int(get_stdout_from_cmd("tput lines"));
|
|
|
|
return cast(s64)width, cast(s64)height;
|
|
}
|
|
|
|
#scope_file
|
|
|
|
get_stdout_from_cmd :: (cmd: string) -> string {
|
|
buffer: [256]u8;
|
|
stream : *FILE;
|
|
data : string;
|
|
|
|
// m_cmd := tprint("% %", cmd, " 2>&1");
|
|
|
|
stream = popen(to_c_string(cmd), to_c_string("r"));
|
|
|
|
if stream {
|
|
while !feof(stream) {
|
|
if fgets(buffer.data, buffer.count, stream) {
|
|
data = tprint("%1%2", data, cast(string)(buffer));
|
|
}
|
|
}
|
|
|
|
pclose(stream);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
to_c_string :: (s: string) -> *u8 {
|
|
result := cast(*u8) alloc(s.count + 1);
|
|
memcpy(result, s.data, s.count);
|
|
result[s.count] = 0;
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
#import "POSIX"; |