Closed EdytoDyte closed 1 year ago
I try the Example of button
package main
import ( "fmt" "log"
"github.com/jroimartin/gocui" )
func main() { g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { log.Panicln(err) } defer g.Close()
g.Cursor = true g.Mouse = true
g.SetManagerFunc(layout2)
if err := keybindings(g); err != nil { log.Panicln(err) }
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { log.Panicln(err) } }
func layout2(g *gocui.Gui) error { if v, err := g.SetView("but1", 2, 2, 22, 7); err != nil { if err != gocui.ErrUnknownView { return err } v.Highlight = true v.SelBgColor = gocui.ColorGreen v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 1 - line 1") fmt.Fprintln(v, "Button 1 - line 2") fmt.Fprintln(v, "Button 1 - line 3") fmt.Fprintln(v, "Button 1 - line 4") } if v, err := g.SetView("but2", 24, 2, 44, 4); err != nil { if err != gocui.ErrUnknownView { return err } v.Highlight = true v.SelBgColor = gocui.ColorGreen v.SelFgColor = gocui.ColorBlack fmt.Fprintln(v, "Button 2 - line 1") } return nil }
func keybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit2); err != nil { return err } for _, n := range []string{"but1", "but2"} { if err := g.SetKeybinding(n, gocui.MouseLeft, gocui.ModNone, showMsg); err != nil { return err } } if err := g.SetKeybinding("msg", gocui.MouseLeft, gocui.ModNone, delMsg); err != nil { return err } return nil }
func quit2(g gocui.Gui, v gocui.View) error { return gocui.ErrQuit }
func showMsg(g gocui.Gui, v gocui.View) error { var l string var err error
if _, err := g.SetCurrentView(v.Name()); err != nil { return err }
_, cy := v.Cursor() if l, err = v.Line(cy); err != nil { l = "" }
maxX, maxY := g.Size() if v, err := g.SetView("msg", maxX/2-10, maxY/2, maxX/2+10, maxY/2+2); err != nil { if err != gocui.ErrUnknownView { return err } fmt.Fprintln(v, l) } return nil }
func delMsg(g gocui.Gui, v gocui.View) error { if err := g.DeleteView("msg"); err != nil { return err } return nil }
But nothing occurs
With this i solved the case
Here is the keybinding
Output Nothing 😄