Modifying a view from another one
This commit is contained in:
parent
d93be2b37b
commit
23a65fcb01
|
@ -9,6 +9,8 @@ import (
|
|||
//"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
var input chan string
|
||||
|
||||
func main() {
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
|
@ -30,7 +32,8 @@ func quit(*gocui.Gui, *gocui.View) error {
|
|||
}
|
||||
|
||||
func sendmsg(g *gocui.Gui, v *gocui.View) error {
|
||||
fmt.Fprintln(v, "HEEEE")
|
||||
v.Clear()
|
||||
v.SetCursor(0, 0)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -38,30 +41,61 @@ func initKeybindings(g *gocui.Gui) error {
|
|||
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.SetKeybinding("button", gocui.MouseLeft, gocui.ModNone, sendmsg); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.SetKeybinding("button", gocui.MouseLeft, gocui.ModNone,
|
||||
func(g *gocui.Gui, v *gocui.View) error {
|
||||
texter, err := g.View("chatbox")
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
fmt.Fprintln(texter, "wow")
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := g.SetKeybinding("textarea", gocui.KeyEnter, gocui.ModNone, sendmsg); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
|
||||
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY/2-2); err != nil {
|
||||
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY/2+6); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(chatbox, "Hello!")
|
||||
}
|
||||
|
||||
if button, err := g.SetView("button", 20, 20, 30, 30); err != nil {
|
||||
if button, err := g.SetView("button", maxX/2+32, maxY/2+9, maxX/2+40, maxY/2+11); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
button.BgColor = gocui.ColorRed
|
||||
//button.BgColor = gocui.ColorRed
|
||||
button.Wrap = true
|
||||
button.Frame = false
|
||||
fmt.Fprintln(button, "BUTTON")
|
||||
button.Frame = true
|
||||
fmt.Fprintln(button, "Send it")
|
||||
}
|
||||
|
||||
if textarea, err := g.SetView("textarea", 2, maxY/2+9, maxX/2+25, maxY/2+11); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
if _, err := g.SetCurrentView("textarea"); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
textarea.Title = "Send message"
|
||||
textarea.Wrap = true
|
||||
textarea.Editable = true
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue