go-prompt/console_interface.go

96 lines
1.5 KiB
Go
Raw Normal View History

2017-07-16 08:20:58 +00:00
package prompt
2018-02-13 16:14:22 +00:00
// WinSize represents the width and height of terminal.
2017-07-16 08:20:58 +00:00
type WinSize struct {
Row uint16
Col uint16
}
2018-02-13 16:14:22 +00:00
// Color represents color on terminal.
2017-07-18 16:16:51 +00:00
type Color int
2017-08-03 06:53:38 +00:00
2017-07-18 16:16:51 +00:00
const (
DefaultColor Color = iota
// Low intensity
Black
DarkRed
DarkGreen
Brown
DarkBlue
Purple
Cyan
LightGray
// High intensity
DarkGray
Red
Green
Yellow
Blue
Fuchsia
Turquoise
White
)
2018-02-13 16:14:22 +00:00
// ConsoleParser is an interface to abstract input layer.
2017-07-16 08:20:58 +00:00
type ConsoleParser interface {
2018-02-13 16:14:22 +00:00
// Setup should be called before starting input
2017-07-16 08:20:58 +00:00
Setup() error
2018-02-13 16:14:22 +00:00
// TearDown should be called after stopping input
2017-07-16 08:20:58 +00:00
TearDown() error
2018-02-13 16:14:22 +00:00
// GetKey returns Key correspond to input byte codes.
2017-08-03 06:53:38 +00:00
GetKey(b []byte) Key
2018-02-13 16:14:22 +00:00
// GetWinSize returns WinSize object to represent width and height of terminal.
2017-07-16 08:20:58 +00:00
GetWinSize() *WinSize
2018-02-12 10:12:31 +00:00
// Read returns byte array.
Read() ([]byte, error)
2017-07-16 08:20:58 +00:00
}
2018-02-13 16:14:22 +00:00
// ConsoleWriter is an interface to abstract output layer.
2017-07-16 08:20:58 +00:00
type ConsoleWriter interface {
/* Write */
2017-07-18 10:06:38 +00:00
WriteRaw(data []byte)
2017-07-16 08:20:58 +00:00
Write(data []byte)
WriteStr(data string)
2017-07-18 10:06:38 +00:00
WriteRawStr(data string)
2017-07-16 08:20:58 +00:00
Flush() error
/* Erasing */
EraseScreen()
EraseUp()
EraseDown()
EraseStartOfLine()
EraseEndOfLine()
EraseLine()
/* Cursor */
ShowCursor()
HideCursor()
CursorGoTo(row, col int)
CursorUp(n int)
CursorDown(n int)
CursorForward(n int)
CursorBackward(n int)
AskForCPR()
SaveCursor()
UnSaveCursor()
/* Scrolling */
ScrollDown()
ScrollUp()
/* Title */
SetTitle(title string)
ClearTitle()
2017-07-18 16:16:51 +00:00
/* Font */
2017-07-16 08:20:58 +00:00
2017-07-18 16:16:51 +00:00
SetColor(fg, bg Color, bold bool)
2017-07-16 08:20:58 +00:00
}