package tui import ( "errors" "fmt" "testing" "git.tordarus.net/Tordarus/tui" "git.tordarus.net/Tordarus/tui/views" "github.com/gdamore/tcell" ) func TestFlowGroup(t *testing.T) { textView := views.NewTextView("hello world!") textView.SetStyle(tui.StyleDefault.Background(tcell.ColorRed).Foreground(tcell.ColorBlack)) marginView := views.NewMarginView(textView) marginView.SetMargin(3, 1, 1, 0) //borderView := views.NewBorderView(textView) textView2 := views.NewTextView("Hi!") textView2.SetStyle(tui.StyleDefault.Background(tcell.ColorBlue).Foreground(tcell.ColorYellow)) growView := views.NewGrowView() growView.SetStyle(tui.StyleDefault.Background(tcell.ColorGreen)) growView2 := views.NewGrowView() growView2.SetStyle(tui.StyleDefault.Background(tcell.ColorYellow)) flowGroup := views.NewFlowGroup(tui.Vertical) flowGroup.AppendViews(marginView, growView, textView2) constrainView := views.NewConstrainView(flowGroup) constrainView.SetStyle(tui.StyleDefault.Background(tcell.ColorPurple)) constrainView.Constrain(-1, -1) screen, err := tui.NewScreen(constrainView) if err != nil { t.Error(err) return } screen.KeyPressed = func(event *tui.KeyEvent) (consumed bool) { textView.Text = event.When().String() if event.Key() == tcell.KeyCtrlC { screen.StopWithError(errors.New(fmt.Sprintf("key: %#v | rune: %s", event.Key(), string(event.Rune())))) } return true } err = screen.Start() fmt.Println(err) } func TestBorderGroup(t *testing.T) { topView := views.NewConstrainView(nil) topView.SetStyle(tui.StyleDefault.Background(tcell.ColorBlue)) topView.Constrain(10, 10) bottomView := views.NewConstrainView(nil) bottomView.SetStyle(tui.StyleDefault.Background(tcell.ColorRed)) bottomView.Constrain(10, 10) leftView := views.NewConstrainView(nil) leftView.SetStyle(tui.StyleDefault.Background(tcell.ColorYellow)) leftView.Constrain(10, 10) rightView := views.NewConstrainView(nil) rightView.SetStyle(tui.StyleDefault.Background(tcell.ColorGreen)) rightView.Constrain(10, 10) centerView := views.NewConstrainView(nil) centerView.SetStyle(tui.StyleDefault.Background(tcell.ColorPurple)) centerView.Constrain(10, 10) borderGroup := views.NewBorderGroup() borderGroup.SetStyle(tui.StyleDefault.Background(tcell.ColorPurple)) borderGroup.SetView(topView, views.Top) borderGroup.SetView(bottomView, views.Bottom) borderGroup.SetView(leftView, views.Left) borderGroup.SetView(rightView, views.Right) borderGroup.SetView(centerView, views.Center) screen, err := tui.NewScreen(borderGroup) if err != nil { t.Error(err) return } screen.KeyPressed = func(event *tui.KeyEvent) (consumed bool) { if event.Key() == tcell.KeyCtrlC { screen.StopWithError(errors.New(fmt.Sprintf("key: %#v | rune: %s", event.Key(), string(event.Rune())))) } return true } err = screen.Start() fmt.Println(err) }