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.

terminal.go 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Package terminal provides support functions for dealing with terminals, as
  5. // commonly found on UNIX systems.
  6. //
  7. // Deprecated: this package moved to golang.org/x/term.
  8. package terminal
  9. import (
  10. "io"
  11. "golang.org/x/term"
  12. )
  13. // EscapeCodes contains escape sequences that can be written to the terminal in
  14. // order to achieve different styles of text.
  15. type EscapeCodes = term.EscapeCodes
  16. // Terminal contains the state for running a VT100 terminal that is capable of
  17. // reading lines of input.
  18. type Terminal = term.Terminal
  19. // NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is
  20. // a local terminal, that terminal must first have been put into raw mode.
  21. // prompt is a string that is written at the start of each input line (i.e.
  22. // "> ").
  23. func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
  24. return term.NewTerminal(c, prompt)
  25. }
  26. // ErrPasteIndicator may be returned from ReadLine as the error, in addition
  27. // to valid line data. It indicates that bracketed paste mode is enabled and
  28. // that the returned line consists only of pasted data. Programs may wish to
  29. // interpret pasted data more literally than typed data.
  30. var ErrPasteIndicator = term.ErrPasteIndicator
  31. // State contains the state of a terminal.
  32. type State = term.State
  33. // IsTerminal returns whether the given file descriptor is a terminal.
  34. func IsTerminal(fd int) bool {
  35. return term.IsTerminal(fd)
  36. }
  37. // ReadPassword reads a line of input from a terminal without local echo. This
  38. // is commonly used for inputting passwords and other sensitive data. The slice
  39. // returned does not include the \n.
  40. func ReadPassword(fd int) ([]byte, error) {
  41. return term.ReadPassword(fd)
  42. }
  43. // MakeRaw puts the terminal connected to the given file descriptor into raw
  44. // mode and returns the previous state of the terminal so that it can be
  45. // restored.
  46. func MakeRaw(fd int) (*State, error) {
  47. return term.MakeRaw(fd)
  48. }
  49. // Restore restores the terminal connected to the given file descriptor to a
  50. // previous state.
  51. func Restore(fd int, oldState *State) error {
  52. return term.Restore(fd, oldState)
  53. }
  54. // GetState returns the current state of a terminal which may be useful to
  55. // restore the terminal after a signal.
  56. func GetState(fd int) (*State, error) {
  57. return term.GetState(fd)
  58. }
  59. // GetSize returns the dimensions of the given terminal.
  60. func GetSize(fd int) (width, height int, err error) {
  61. return term.GetSize(fd)
  62. }