github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/clissh/terminal_helper.go (about)

     1  package clissh
     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  	GetFdInfo(in interface{}) (fd uintptr, isTerminal bool)
    13  	SetRawTerminal(fd uintptr) (*term.State, error)
    14  	RestoreTerminal(fd uintptr, state *term.State) error
    15  	GetWinsize(fd uintptr) (*term.Winsize, error)
    16  	StdStreams() (stdin io.ReadCloser, stdout io.Writer, stderr io.Writer)
    17  }
    18  
    19  type terminalHelper struct{}
    20  
    21  func DefaultTerminalHelper() terminalHelper {
    22  	return terminalHelper{}
    23  }
    24  
    25  func (terminalHelper) GetFdInfo(in interface{}) (uintptr, bool) {
    26  	return term.GetFdInfo(in)
    27  }
    28  
    29  func (terminalHelper) GetWinsize(fd uintptr) (*term.Winsize, error) {
    30  	return term.GetWinsize(fd)
    31  }
    32  
    33  func (terminalHelper) RestoreTerminal(fd uintptr, state *term.State) error {
    34  	return term.RestoreTerminal(fd, state)
    35  }
    36  
    37  func (terminalHelper) SetRawTerminal(fd uintptr) (*term.State, error) {
    38  	return term.SetRawTerminal(fd)
    39  }
    40  
    41  func (terminalHelper) StdStreams() (io.ReadCloser, io.Writer, io.Writer) {
    42  	return term.StdStreams()
    43  }