Last active
April 25, 2021 06:33
-
-
Save nanonanomachine/713a5dbdd53602fd75ef7733d15cfb31 to your computer and use it in GitHub Desktop.
tview initialize setting for white terminal lovers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/rivo/tview/pull/395 | |
package main | |
import ( | |
"github.com/gdamore/tcell/v2" | |
"github.com/rivo/tview" | |
) | |
func main() { | |
// Set this so we don't overwrite the default terminal colors | |
// See https://github.com/rivo/tview/blob/master/styles.go | |
tview.Styles.PrimitiveBackgroundColor = tcell.ColorDefault | |
tview.Styles.ContrastBackgroundColor = tcell.ColorDefault | |
tview.Styles.PrimaryTextColor = tcell.ColorDefault | |
tview.Styles.BorderColor = tcell.ColorDefault | |
newPrimitive := func(text string) tview.Primitive { | |
return tview.NewTextView(). | |
SetTextAlign(tview.AlignCenter). | |
SetText(text) | |
} | |
menu := newPrimitive("Menu") | |
main := newPrimitive("Main content") | |
sideBar := newPrimitive("Side Bar") | |
grid := tview.NewGrid(). | |
SetRows(3, 0, 3). | |
SetColumns(30, 0, 30). | |
SetBorders(true). | |
AddItem(newPrimitive("Header"), 0, 0, 1, 3, 0, 0, false). | |
AddItem(newPrimitive("Footer"), 2, 0, 1, 3, 0, 0, false) | |
// Layout for screens narrower than 100 cells (menu and side bar are hidden). | |
grid.AddItem(menu, 0, 0, 0, 0, 0, 0, false). | |
AddItem(main, 1, 0, 1, 3, 0, 0, false). | |
AddItem(sideBar, 0, 0, 0, 0, 0, 0, false) | |
// Layout for screens wider than 100 cells. | |
grid.AddItem(menu, 1, 0, 1, 1, 0, 100, false). | |
AddItem(main, 1, 1, 1, 1, 0, 100, false). | |
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false) | |
if err := tview.NewApplication().SetRoot(grid, true).SetFocus(grid).Run(); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment