2015-02-26 23:58:24 +08:00
|
|
|
package sys
|
2013-09-03 22:22:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
#include <termios.h>
|
|
|
|
#include <sys/ioctl.h>
|
2016-01-29 10:25:50 +08:00
|
|
|
|
|
|
|
void getwinsize(int fd, int *row, int *col) {
|
|
|
|
struct winsize wsz;
|
|
|
|
ioctl(fd, TIOCGWINSZ, &wsz);
|
|
|
|
*row = wsz.ws_row;
|
|
|
|
*col = wsz.ws_col;
|
|
|
|
}
|
2013-09-03 22:22:28 +08:00
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
|
2015-02-25 05:56:38 +08:00
|
|
|
// GetWinsize queries the size of the terminal referenced by the given file
|
|
|
|
// descriptor.
|
2016-01-29 10:25:50 +08:00
|
|
|
func GetWinsize(fd int) (row, col int) {
|
|
|
|
var r, c C.int
|
|
|
|
C.getwinsize(C.int(fd), &r, &c)
|
|
|
|
return int(r), int(c)
|
2013-09-03 22:22:28 +08:00
|
|
|
}
|