David Ashby
0a5cea9fb1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
141 lines
2.6 KiB
Go
141 lines
2.6 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
)
|
|
|
|
type coord struct {
|
|
x, y int
|
|
}
|
|
|
|
type MockScreen struct {
|
|
x, y, h, w int
|
|
content map[coord]rune
|
|
}
|
|
|
|
func (m *MockScreen) Init() error {
|
|
m.content = map[coord]rune{}
|
|
return nil
|
|
}
|
|
|
|
func (m *MockScreen) Fini() {}
|
|
|
|
func (m *MockScreen) Clear() {
|
|
m.content = map[coord]rune{}
|
|
}
|
|
|
|
func (m *MockScreen) Fill(rune, tcell.Style) {}
|
|
|
|
func (m *MockScreen) SetCell(x int, y int, style tcell.Style, ch ...rune) {}
|
|
|
|
func (m *MockScreen) GetContent(x, y int) (mainc rune, combc []rune, style tcell.Style, width int) {
|
|
return m.content[coord{x, y}], nil, tcell.StyleDefault, 1
|
|
}
|
|
|
|
func (m *MockScreen) SetContent(x int, y int, mainc rune, combc []rune, style tcell.Style) {
|
|
m.content[coord{x, y}] = mainc
|
|
}
|
|
|
|
func (m *MockScreen) Suspend() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockScreen) Resume() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockScreen) SetStyle(style tcell.Style) {}
|
|
|
|
func (m *MockScreen) SetCursorStyle(style tcell.CursorStyle) {}
|
|
|
|
func (m *MockScreen) ShowCursor(x int, y int) {}
|
|
|
|
func (m *MockScreen) HideCursor() {}
|
|
|
|
func (m *MockScreen) Size() (int, int) {
|
|
return m.h, m.w
|
|
}
|
|
|
|
func (m *MockScreen) PollEvent() tcell.Event {
|
|
return tcell.NewEventError(fmt.Errorf("mock error"))
|
|
}
|
|
|
|
func (m *MockScreen) ChannelEvents(ch chan<- tcell.Event, quit <-chan struct{}) {}
|
|
|
|
func (m *MockScreen) HasPendingEvent() bool {
|
|
return false
|
|
}
|
|
|
|
func (m *MockScreen) PostEvent(ev tcell.Event) error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockScreen) PostEventWait(ev tcell.Event) {}
|
|
|
|
func (m *MockScreen) EnableMouse(...tcell.MouseFlags) {}
|
|
|
|
func (m *MockScreen) DisableMouse() {}
|
|
|
|
func (m *MockScreen) EnablePaste() {}
|
|
|
|
func (m *MockScreen) DisablePaste() {}
|
|
|
|
func (m *MockScreen) HasMouse() bool {
|
|
return false
|
|
}
|
|
|
|
func (m *MockScreen) Colors() int {
|
|
return 0
|
|
}
|
|
|
|
func (m *MockScreen) Show() {}
|
|
|
|
func (m *MockScreen) Sync() {}
|
|
|
|
func (m *MockScreen) CharacterSet() string {
|
|
return "UTF-8"
|
|
}
|
|
|
|
func (m *MockScreen) RegisterRuneFallback(r rune, subst string) {}
|
|
|
|
func (m *MockScreen) UnregisterRuneFallback(r rune) {}
|
|
|
|
func (m *MockScreen) CanDisplay(r rune, checkFallbacks bool) bool {
|
|
return true
|
|
}
|
|
|
|
func (m *MockScreen) Resize(x, y, h, w int) {
|
|
m.x, m.y, m.h, m.w = x, y, h, w
|
|
}
|
|
|
|
func (m *MockScreen) SetSize(h, w int) {
|
|
m.h, m.w = h, w
|
|
}
|
|
|
|
func (m *MockScreen) HasKey(tcell.Key) bool {
|
|
return true
|
|
}
|
|
|
|
func (m *MockScreen) Beep() error {
|
|
return nil
|
|
}
|
|
|
|
func (m *MockScreen) DumpContents() string {
|
|
var res string
|
|
for i := m.y; i < m.h; i++ {
|
|
str := []rune{}
|
|
for j := m.x; j < m.w; j++ {
|
|
r, ok := m.content[coord{x: j, y: i}]
|
|
if ok {
|
|
str = append(str, r)
|
|
} else {
|
|
str = append(str, ' ')
|
|
}
|
|
}
|
|
res = res + string(str) + "\n"
|
|
}
|
|
return res
|
|
}
|