選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

term.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2019 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. // Package term provides support functions for dealing with terminals, as
  5. // commonly found on UNIX systems.
  6. //
  7. // Putting a terminal into raw mode is the most common requirement:
  8. //
  9. // oldState, err := terminal.MakeRaw(0)
  10. // if err != nil {
  11. // panic(err)
  12. // }
  13. // defer terminal.Restore(0, oldState)
  14. package term
  15. // State contains the state of a terminal.
  16. type State struct {
  17. state
  18. }
  19. // IsTerminal returns whether the given file descriptor is a terminal.
  20. func IsTerminal(fd int) bool {
  21. return isTerminal(fd)
  22. }
  23. // MakeRaw puts the terminal connected to the given file descriptor into raw
  24. // mode and returns the previous state of the terminal so that it can be
  25. // restored.
  26. func MakeRaw(fd int) (*State, error) {
  27. return makeRaw(fd)
  28. }
  29. // GetState returns the current state of a terminal which may be useful to
  30. // restore the terminal after a signal.
  31. func GetState(fd int) (*State, error) {
  32. return getState(fd)
  33. }
  34. // Restore restores the terminal connected to the given file descriptor to a
  35. // previous state.
  36. func Restore(fd int, oldState *State) error {
  37. return restore(fd, oldState)
  38. }
  39. // GetSize returns the visible dimensions of the given terminal.
  40. //
  41. // These dimensions don't include any scrollback buffer height.
  42. func GetSize(fd int) (width, height int, err error) {
  43. return getSize(fd)
  44. }
  45. // ReadPassword reads a line of input from a terminal without local echo. This
  46. // is commonly used for inputting passwords and other sensitive data. The slice
  47. // returned does not include the \n.
  48. func ReadPassword(fd int) ([]byte, error) {
  49. return readPassword(fd)
  50. }