| 1 |
// +build unix, !windows |
| 2 |
|
| 3 |
package consolesize |
| 4 |
|
| 5 |
import ( |
| 6 |
"syscall" |
| 7 |
"unsafe" |
| 8 |
) |
| 9 |
|
| 10 |
// GetConsoleSize returns the current number of columns and rows in the active console window. |
| 11 |
// The return value of this function is in the order of cols, rows. |
| 12 |
func GetConsoleSize() (int, int) { |
| 13 |
var sz struct { |
| 14 |
rows uint16 |
| 15 |
cols uint16 |
| 16 |
xpixels uint16 |
| 17 |
ypixels uint16 |
| 18 |
} |
| 19 |
_, _, _ = syscall.Syscall(syscall.SYS_IOCTL, |
| 20 |
uintptr(syscall.Stdout), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&sz))) |
| 21 |
return int(sz.cols), int(sz.rows) |
| 22 |
} |