You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
663 B

  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build darwin dragonfly freebsd linux,!appengine netbsd openbsd
  5. package readline
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  10. type Termios syscall.Termios
  11. // GetSize returns the dimensions of the given terminal.
  12. func GetSize(fd int) (int, int, error) {
  13. var dimensions [4]uint16
  14. _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0)
  15. if err != 0 {
  16. return 0, 0, err
  17. }
  18. return int(dimensions[1]), int(dimensions[0]), nil
  19. }