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