package main import ( "code.rocketnine.space/tslocum/cview" "github.com/gdamore/tcell/v2" ) func main() { app := cview.NewApplication() app.EnableMouse(true) newPrimitive := func(text string) cview.Primitive { tv := cview.NewTextView() tv.SetTextAlign(cview.AlignCenter) tv.SetText(text) return tv } inputchan := make(chan string) grid := cview.NewGrid() grid.SetRows(3, 0, 0, 3, 3) grid.SetColumns(30, 0, 30) grid.SetBorders(true) board := cview.NewTable() board.SetBorders(true) cols, rows := 4, 2 for r := 0; r < rows; r++ { for c := 0; c < cols; c++ { color := tcell.ColorWhite.TrueColor() if c < 1 || r < 1 { color = tcell.ColorYellow.TrueColor() } cell := cview.NewTableCell("test") cell.SetTextColor(color) cell.SetAlign(cview.AlignCenter) board.SetCell(r, c, cell) } } rows = 1 hand := cview.NewTable() hand.SetBorders(true) for r := 0; r < rows; r++ { for c := 0; c < cols; c++ { color := tcell.ColorWhite.TrueColor() if c < 1 || r < 1 { color = tcell.ColorYellow.TrueColor() } cell := cview.NewTableCell("test") cell.SetTextColor(color) cell.SetAlign(cview.AlignCenter) hand.SetCell(r, c, cell) } } playerside := newPrimitive("Player") oppside := newPrimitive("Opponent") commandinput := cview.NewInputField() commandoutput := cview.NewTextView() commandinput.SetDoneFunc(func(key tcell.Key) { inputchan <- commandinput.GetText() commandinput.SetText("") }) commandoutput.SetChangedFunc(func() { app.Draw() }) grid.AddItem(playerside, 1, 0, 2, 1, 0, 100, false) grid.AddItem(board, 1, 1, 1, 1, 0, 100, false) grid.AddItem(hand, 2, 1, 1, 1, 0, 100, false) grid.AddItem(oppside, 1, 2, 2, 1, 0, 100, false) grid.AddItem(commandinput, 3, 0, 1, 3, 0, 0, true) grid.AddItem(commandoutput, 4, 0, 1, 3, 0, 0, false) go backend(inputchan, commandoutput) app.SetRoot(grid, true) if err := app.Run(); err != nil { panic(err) } }