import ( "github.com/jroimartin/gocui" ) func layout(g *gocui.Gui) error { v, err := g.SetView("hello", 0, 0, 10, 1) if err != nil { if err != gocui.ErrUnknownView { return err } v.Frame = false fmt.Fprint(v, "Hello world!") } return nil } func main() { g := gocui.NewGui() if err := g.Init(); err != nil { log.Fatalf("Failed to initialize gui: %v", err) } defer g.Close() g.SetLayout(layout) if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { log.Fatalf("Failed to run main loop: %v", err) } }
import ( "github.com/jroimartin/gocui" ) func layout(g *gocui.Gui) error { v, err := g.SetView("list", 0, 0, 20, 10) if err != nil { if err != gocui.ErrUnknownView { return err } v.Frame = false items := []string{"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"} for _, item := range items { fmt.Fprintln(v, item) } v.Highlight = true v.SelBgColor = gocui.ColorGreen } return nil } func main() { g := gocui.NewGui() if err := g.Init(); err != nil { log.Fatalf("Failed to initialize gui: %v", err) } defer g.Close() g.SetLayout(layout) if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { log.Fatalf("Failed to run main loop: %v", err) } }This example creates a scrolling list view that displays five items ("Item 1" through "Item 5") and highlights the currently selected item with a green background color. The view is created using the SetView function, and the list of items is generated using a loop that writes each item to the view using the fmt.Fprintln function. Overall, the go-github.com/jroimartin/gocui package is a powerful tool for creating terminal-based user interfaces with Go. The SetView function, in particular, is a key component of this package as it allows developers to easily define and configure UI components that are displayed in the terminal window.