github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/ssh/terminal/helper.go (about) 1 package terminal 2 3 import ( 4 "io" 5 6 "github.com/moby/moby/pkg/term" 7 ) 8 9 //go:generate counterfeiter . TerminalHelper 10 11 type TerminalHelper interface { 12 StdStreams() (stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) 13 GetFdInfo(in interface{}) (fd uintptr, isTerminal bool) 14 SetRawTerminal(fd uintptr) (*term.State, error) 15 RestoreTerminal(fd uintptr, state *term.State) error 16 IsTerminal(fd uintptr) bool 17 GetWinsize(fd uintptr) (*term.Winsize, error) 18 } 19 20 type terminalHelper struct{} 21 22 func DefaultHelper() TerminalHelper { 23 return &terminalHelper{} 24 } 25 26 func (t *terminalHelper) StdStreams() (io.ReadCloser, io.Writer, io.Writer) { 27 return term.StdStreams() 28 } 29 30 func (t *terminalHelper) GetFdInfo(in interface{}) (uintptr, bool) { 31 return term.GetFdInfo(in) 32 } 33 34 func (t *terminalHelper) SetRawTerminal(fd uintptr) (*term.State, error) { 35 return term.SetRawTerminal(fd) 36 } 37 38 func (t *terminalHelper) RestoreTerminal(fd uintptr, state *term.State) error { 39 return term.RestoreTerminal(fd, state) 40 } 41 42 func (t *terminalHelper) IsTerminal(fd uintptr) bool { 43 return term.IsTerminal(fd) 44 } 45 46 func (t *terminalHelper) GetWinsize(fd uintptr) (*term.Winsize, error) { 47 return term.GetWinsize(fd) 48 }