winsize.ha (608B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 use errors; 5 use io; 6 use rt; 7 8 // Returns the dimensions of underlying terminal for an [[io::file]]. 9 export fn winsize(fd: io::file) (ttysize | error) = { 10 let wsz = rt::winsize { ... }; 11 match (rt::ioctl(fd, rt::TIOCGWINSZ, &wsz: *opaque)) { 12 case let e: rt::errno => 13 switch (e) { 14 case rt::EBADF => 15 return errors::invalid; 16 case rt::ENOTTY => 17 return errors::unsupported; 18 case => 19 abort("Unexpected error from ioctl"); 20 }; 21 case int => 22 return ttysize { 23 rows = wsz.ws_row, 24 columns = wsz.ws_col, 25 }; 26 }; 27 };