package main import ( "log" "github.com/jroimartin/gocui" ) func main() { // create new gocui object g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { log.Panicln(err) } // close gocui on exit defer g.Close() // add main view _, err = g.SetView("main", 0, 0, 30, 10) if err != nil { if err != gocui.ErrUnknownView { log.Panicln(err) } } // set cursor to visible g.Cursor = true // define function to quit application quit := func(g *gocui.Gui, v *gocui.View) error { return gocui.ErrQuit } // set keybinding for quitting application err = g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit) if err != nil { log.Panicln(err) } // start gocui event loop err = g.MainLoop() if err != nil && err != gocui.ErrQuit { log.Panicln(err) } }
package main import ( "log" "github.com/jroimartin/gocui" ) func main() { // create new gocui object g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { log.Panicln(err) } // close gocui on exit defer g.Close() // add main view mainView, err := g.SetView("main", 0, 0, 30, 10) if err != nil { if err != gocui.ErrUnknownView { log.Panicln(err) } } // set cursor to visible mainView.Highlight = true mainView.SelBgColor = gocui.ColorGreen // add secondary view _, err = g.SetView("secondary", 31, 0, 60, 10) if err != nil { if err != gocui.ErrUnknownView { log.Panicln(err) } } // define function to switch between views switchView := func(g *gocui.Gui, v *gocui.View) error { if v == nil || v.Name() == "main" { _, err := g.SetCurrentView("secondary") return err } else { _, err := g.SetCurrentView("main") return err } } // set keybinding for switching views err = g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, switchView) if err != nil { log.Panicln(err) } // start gocui event loop err = g.MainLoop() if err != nil && err != gocui.ErrQuit { log.Panicln(err) } }Overall, the 'github.com/jroimartin/gocui' package is a powerful and flexible library for creating console-based GUI applications in Go. It provides a wide range of features, such as multiple views, menus, popups, keybindings, and more. It is a package library focused on creating terminal interfaces.