go-prompt/console_interface.go

122 lines
3.0 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 */
// WriteRaw to write raw byte array.
2017-07-18 10:06:38 +00:00
WriteRaw(data []byte)
2018-02-15 06:51:02 +00:00
// Write to write safety byte array by removing control sequences.
2017-07-16 08:20:58 +00:00
Write(data []byte)
// WriteStr to write raw string.
2017-07-18 10:06:38 +00:00
WriteRawStr(data string)
2018-02-15 06:51:02 +00:00
// WriteStr to write safety string by removing control sequences.
WriteStr(data string)
// Flush to flush buffer.
2017-07-16 08:20:58 +00:00
Flush() error
/* Erasing */
// EraseScreen erases the screen with the background colour and moves the cursor to home.
2017-07-16 08:20:58 +00:00
EraseScreen()
// EraseUp erases the screen from the current line up to the top of the screen.
2017-07-16 08:20:58 +00:00
EraseUp()
// EraseDown erases the screen from the current line down to the bottom of the screen.
2017-07-16 08:20:58 +00:00
EraseDown()
// EraseStartOfLine erases from the current cursor position to the start of the current line.
2017-07-16 08:20:58 +00:00
EraseStartOfLine()
// EraseEndOfLine erases from the current cursor position to the end of the current line.
2017-07-16 08:20:58 +00:00
EraseEndOfLine()
// EraseLine erases the entire current line.
2017-07-16 08:20:58 +00:00
EraseLine()
/* Cursor */
// ShowCursor stops blinking cursor and show.
2017-07-16 08:20:58 +00:00
ShowCursor()
// HideCursor hides cursor.
2017-07-16 08:20:58 +00:00
HideCursor()
// CursorGoTo sets the cursor position where subsequent text will begin.
2017-07-16 08:20:58 +00:00
CursorGoTo(row, col int)
// CursorUp moves the cursor up by 'n' rows; the default count is 1.
2017-07-16 08:20:58 +00:00
CursorUp(n int)
// CursorDown moves the cursor down by 'n' rows; the default count is 1.
2017-07-16 08:20:58 +00:00
CursorDown(n int)
// CursorForward moves the cursor forward by 'n' columns; the default count is 1.
2017-07-16 08:20:58 +00:00
CursorForward(n int)
// CursorBackward moves the cursor backward by 'n' columns; the default count is 1.
2017-07-16 08:20:58 +00:00
CursorBackward(n int)
// AskForCPR asks for a cursor position report (CPR).
2017-07-16 08:20:58 +00:00
AskForCPR()
// SaveCursor saves current cursor position.
2017-07-16 08:20:58 +00:00
SaveCursor()
// UnSaveCursor restores cursor position after a Save Cursor.
2017-07-16 08:20:58 +00:00
UnSaveCursor()
/* Scrolling */
// ScrollDown scrolls display down one line.
2017-07-16 08:20:58 +00:00
ScrollDown()
// ScrollUp scroll display up one line.
2017-07-16 08:20:58 +00:00
ScrollUp()
/* Title */
// SetTitle sets a title of terminal window.
2017-07-16 08:20:58 +00:00
SetTitle(title string)
// ClearTitle clears a title of terminal window.
2017-07-16 08:20:58 +00:00
ClearTitle()
2017-07-18 16:16:51 +00:00
/* Font */
2017-07-16 08:20:58 +00:00
// SetColor sets text and background colors. and specify whether text is bold.
2017-07-18 16:16:51 +00:00
SetColor(fg, bg Color, bold bool)
2017-07-16 08:20:58 +00:00
}