1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
package real
import (
"io"
ssh_terminal "golang.org/x/crypto/ssh/terminal"
"github.com/twstrike/coyim/cli/terminal"
)
type realTerminalControl struct{}
func (*realTerminalControl) NewTerminal(c io.ReadWriter, prompt string) terminal.Terminal {
return ssh_terminal.NewTerminal(c, prompt)
}
func (*realTerminalControl) ErrPasteIndicator() error {
return ssh_terminal.ErrPasteIndicator
}
func (*realTerminalControl) GetSize(fd int) (width, height int, err error) {
return ssh_terminal.GetSize(fd)
}
func (*realTerminalControl) MakeRaw(fd int) (interface{}, error) {
return ssh_terminal.MakeRaw(fd)
}
func (*realTerminalControl) Restore(fd int, state interface{}) error {
realState := state.(*ssh_terminal.State)
return ssh_terminal.Restore(fd, realState)
}
func (*realTerminalControl) SetAutoCompleteCallback(t terminal.Terminal, f func(string, int, rune) (string, int, bool)) {
realT := t.(*ssh_terminal.Terminal)
realT.AutoCompleteCallback = f
}
func (*realTerminalControl) Escape(t terminal.Terminal) terminal.EscapeCodes {
realT := t.(*ssh_terminal.Terminal)
e := realT.Escape
return terminal.EscapeCodes{
Black: e.Black,
Red: e.Red,
Green: e.Green,
Yellow: e.Yellow,
Blue: e.Blue,
Magenta: e.Magenta,
Cyan: e.Cyan,
White: e.White,
Reset: e.Reset,
}
}
// Factory creates a new terminal.Control that is connected to a real terminal
func Factory() terminal.Control {
return &realTerminalControl{}
}
|