Files
odo/vendor/github.com/hinshun/vt10x/vt.go
Anand Kumar Singh 3eb92b6a47 POC for odo interactive testing (#5466)
* POC for odo interactive testing

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* add interactive tests to make target test-integration

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* [WIP] use func to pass test instructions

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* cleanup comments/test

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* cleanup minor changes

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* fix unit test failure

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* skip for windows

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* skip for windows by not compiling, cleanup

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* cleanup, and add the make target to test files

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* incorporate review, adding comments, cleanup

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* fix failing make validate

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* update test dependency, and possible fix for windows

Signed-off-by: anandrkskd <anandrkskd@gmail.com>

* Revert "update test dependency, and possible fix for windows"

This reverts commit 55580b7dc5.

* Final cleanup

Signed-off-by: anandrkskd <anandrkskd@gmail.com>
2022-03-02 13:50:26 -05:00

90 lines
1.9 KiB
Go

package vt10x
import (
"bufio"
"fmt"
"io"
"io/ioutil"
)
// Terminal represents the virtual terminal emulator.
type Terminal interface {
// View displays the virtual terminal.
View
// Write parses input and writes terminal changes to state.
io.Writer
// Parse blocks on read on pty or io.Reader, then parses sequences until
// buffer empties. State is locked as soon as first rune is read, and unlocked
// when buffer is empty.
Parse(bf *bufio.Reader) error
}
// View represents the view of the virtual terminal emulator.
type View interface {
// String dumps the virtual terminal contents.
fmt.Stringer
// Size returns the size of the virtual terminal.
Size() (cols, rows int)
// Resize changes the size of the virtual terminal.
Resize(cols, rows int)
// Mode returns the current terminal mode.//
Mode() ModeFlag
// Title represents the title of the console window.
Title() string
// Cell returns the glyph containing the character code, foreground color, and
// background color at position (x, y) relative to the top left of the terminal.
Cell(x, y int) Glyph
// Cursor returns the current position of the cursor.
Cursor() Cursor
// CursorVisible returns the visible state of the cursor.
CursorVisible() bool
// Lock locks the state object's mutex.
Lock()
// Unlock resets change flags and unlocks the state object's mutex.
Unlock()
}
type TerminalOption func(*TerminalInfo)
type TerminalInfo struct {
w io.Writer
cols, rows int
}
func WithWriter(w io.Writer) TerminalOption {
return func(info *TerminalInfo) {
info.w = w
}
}
func WithSize(cols, rows int) TerminalOption {
return func(info *TerminalInfo) {
info.cols = cols
info.rows = rows
}
}
// New returns a new virtual terminal emulator.
func New(opts ...TerminalOption) Terminal {
info := TerminalInfo{
w: ioutil.Discard,
cols: 80,
rows: 24,
}
for _, opt := range opts {
opt(&info)
}
return newTerminal(info)
}