This commit is contained in:
28
ui/mock.go
28
ui/mock.go
@@ -3,7 +3,7 @@ package ui
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type coord struct {
|
||||
@@ -38,8 +38,18 @@ func (m *MockScreen) SetContent(x int, y int, mainc rune, combc []rune, style tc
|
||||
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() {}
|
||||
@@ -52,16 +62,26 @@ 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() {}
|
||||
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
|
||||
}
|
||||
@@ -90,6 +110,10 @@ 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
|
||||
}
|
||||
|
6
ui/ui.go
6
ui/ui.go
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.yetaga.in/alazyreader/library/media"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type Drawable interface {
|
||||
@@ -37,8 +37,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
StyleActive = tcell.Style(0).Foreground(tcell.ColorWhite).Background(tcell.ColorBlack)
|
||||
StyleInactive = tcell.Style(0).Foreground(tcell.ColorGray).Background(tcell.ColorBlack)
|
||||
StyleActive = tcell.Style{}.Foreground(tcell.ColorWhite).Background(tcell.ColorBlack)
|
||||
StyleInactive = tcell.Style{}.Foreground(tcell.ColorGray).Background(tcell.ColorBlack)
|
||||
)
|
||||
|
||||
// A Container has no visible UI of its own, but arranges sub-components on the screen.
|
||||
|
@@ -3,6 +3,8 @@ package ui
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
func TestContainerOneBox(t *testing.T) {
|
||||
@@ -13,7 +15,7 @@ func TestContainerOneBox(t *testing.T) {
|
||||
└──────────────────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("box one", nil, Contents{}, 0, false)
|
||||
one := NewBox("box one", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{{Container: one}},
|
||||
LayoutHorizontalEven,
|
||||
@@ -38,8 +40,8 @@ func TestContainerTwoBoxesHStack(t *testing.T) {
|
||||
└────────┘└────────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("one", nil, Contents{}, 0, false)
|
||||
two := NewBox("two", nil, Contents{}, 0, false)
|
||||
one := NewBox("one", nil, Contents{}, tcell.Style{}, false)
|
||||
two := NewBox("two", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{{Container: one}, {Container: two}},
|
||||
LayoutHorizontalEven,
|
||||
@@ -64,9 +66,9 @@ func TestContainerThreeBoxesUnevenHStack(t *testing.T) {
|
||||
└────────┘└────────┘└───────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("one", nil, Contents{}, 0, false)
|
||||
two := NewBox("two", nil, Contents{}, 0, false)
|
||||
three := NewBox("three", nil, Contents{}, 0, false)
|
||||
one := NewBox("one", nil, Contents{}, tcell.Style{}, false)
|
||||
two := NewBox("two", nil, Contents{}, tcell.Style{}, false)
|
||||
three := NewBox("three", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{{Container: one}, {Container: two}, {Container: three}},
|
||||
LayoutHorizontalEven,
|
||||
@@ -91,8 +93,8 @@ func TestContainerTwoBoxesHPercentStack(t *testing.T) {
|
||||
└────────────┘└──────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("one", nil, Contents{}, 0, false)
|
||||
two := NewBox("two", nil, Contents{}, 0, false)
|
||||
one := NewBox("one", nil, Contents{}, tcell.Style{}, false)
|
||||
two := NewBox("two", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{
|
||||
{Container: one, Offsets: Offsets{Percent: 2}},
|
||||
@@ -124,8 +126,8 @@ func TestContainerTwoBoxesVStack(t *testing.T) {
|
||||
└────────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("one", nil, Contents{}, 0, false)
|
||||
two := NewBox("two", nil, Contents{}, 0, false)
|
||||
one := NewBox("one", nil, Contents{}, tcell.Style{}, false)
|
||||
two := NewBox("two", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{{Container: one}, {Container: two}},
|
||||
LayoutVerticalEven,
|
||||
@@ -155,8 +157,8 @@ func TestContainerTwoBoxesPercentageVStack(t *testing.T) {
|
||||
└────────┘
|
||||
`
|
||||
m := &MockScreen{}
|
||||
one := NewBox("one", nil, Contents{}, 0, false)
|
||||
two := NewBox("two", nil, Contents{}, 0, false)
|
||||
one := NewBox("one", nil, Contents{}, tcell.Style{}, false)
|
||||
two := NewBox("two", nil, Contents{}, tcell.Style{}, false)
|
||||
container := NewContainer(
|
||||
Contents{
|
||||
{Container: one, Offsets: Offsets{Percent: 2}},
|
||||
|
Reference in New Issue
Block a user