term.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package term
  2. // State contains platform-specific state of a terminal.
  3. type State struct {
  4. state
  5. }
  6. // IsTerminal returns whether the given file descriptor is a terminal.
  7. func IsTerminal(fd uintptr) bool {
  8. return isTerminal(fd)
  9. }
  10. // MakeRaw puts the terminal connected to the given file descriptor into raw
  11. // mode and returns the previous state of the terminal so that it can be
  12. // restored.
  13. func MakeRaw(fd uintptr) (*State, error) {
  14. return makeRaw(fd)
  15. }
  16. // GetState returns the current state of a terminal which may be useful to
  17. // restore the terminal after a signal.
  18. func GetState(fd uintptr) (*State, error) {
  19. return getState(fd)
  20. }
  21. // SetState sets the given state of the terminal.
  22. func SetState(fd uintptr, state *State) error {
  23. return setState(fd, state)
  24. }
  25. // Restore restores the terminal connected to the given file descriptor to a
  26. // previous state.
  27. func Restore(fd uintptr, oldState *State) error {
  28. return restore(fd, oldState)
  29. }
  30. // GetSize returns the visible dimensions of the given terminal.
  31. //
  32. // These dimensions don't include any scrollback buffer height.
  33. func GetSize(fd uintptr) (width, height int, err error) {
  34. return getSize(fd)
  35. }
  36. // ReadPassword reads a line of input from a terminal without local echo. This
  37. // is commonly used for inputting passwords and other sensitive data. The slice
  38. // returned does not include the \n.
  39. func ReadPassword(fd uintptr) ([]byte, error) {
  40. return readPassword(fd)
  41. }