library/ui/mock.go

151 lines
2.9 KiB
Go
Raw Normal View History

package ui
import (
"fmt"
2023-04-08 02:42:54 +00:00
"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
}
2023-04-08 02:42:54 +00:00
func (m *MockScreen) Suspend() error {
return nil
}
func (m *MockScreen) Resume() error {
return nil
}
func (m *MockScreen) SetStyle(style tcell.Style) {}
2023-04-08 02:42:54 +00:00
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"))
}
2023-04-08 02:42:54 +00:00
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) {}
2023-04-08 02:42:54 +00:00
func (m *MockScreen) EnableMouse(...tcell.MouseFlags) {}
func (m *MockScreen) DisableMouse() {}
2023-04-08 02:42:54 +00:00
func (m *MockScreen) EnablePaste() {}
func (m *MockScreen) DisablePaste() {}
2023-12-24 20:05:11 +00:00
func (m *MockScreen) EnableFocus() {}
func (m *MockScreen) DisableFocus() {}
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
}
2023-04-08 02:42:54 +00:00
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
}
2023-12-24 20:05:11 +00:00
func (m *MockScreen) LockRegion(x, y, width, height int, lock bool) {}
func (m *MockScreen) Tty() (tcell.Tty, bool) {
return nil, false
}
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
}