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.

32 lines
786 B

  1. // Copyright 2013 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 solaris
  5. package readline
  6. import "golang.org/x/sys/unix"
  7. // GetSize returns the dimensions of the given terminal.
  8. func GetSize(fd int) (int, int, error) {
  9. ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
  10. if err != nil {
  11. return 0, 0, err
  12. }
  13. return int(ws.Col), int(ws.Row), nil
  14. }
  15. type Termios unix.Termios
  16. func getTermios(fd int) (*Termios, error) {
  17. termios, err := unix.IoctlGetTermios(fd, unix.TCGETS)
  18. if err != nil {
  19. return nil, err
  20. }
  21. return (*Termios)(termios), nil
  22. }
  23. func setTermios(fd int, termios *Termios) error {
  24. return unix.IoctlSetTermios(fd, unix.TCSETSF, (*unix.Termios)(termios))
  25. }