terminal_normal.go 842 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //go:build !js
  2. package terminal
  3. import (
  4. "fmt"
  5. "os"
  6. "golang.org/x/term"
  7. )
  8. // GetSize reads the dimensions of the current terminal or returns a
  9. // sensible default
  10. func GetSize() (w, h int) {
  11. w, h, err := term.GetSize(int(os.Stdout.Fd()))
  12. if err != nil {
  13. w, h = 80, 25
  14. }
  15. return w, h
  16. }
  17. // IsTerminal returns whether the fd passed in is a terminal or not
  18. func IsTerminal(fd int) bool {
  19. return term.IsTerminal(fd)
  20. }
  21. // ReadPassword reads a line of input from a terminal without local echo. This
  22. // is commonly used for inputting passwords and other sensitive data. The slice
  23. // returned does not include the \n.
  24. func ReadPassword(fd int) ([]byte, error) {
  25. return term.ReadPassword(fd)
  26. }
  27. // WriteTerminalTitle writes a string to the terminal title
  28. func WriteTerminalTitle(title string) {
  29. fmt.Printf(ChangeTitle + title + BEL)
  30. }