Add "Connected users" view
This commit is contained in:
parent
ae2477dc77
commit
3921e103a5
|
@ -4,10 +4,13 @@ import (
|
|||
"fmt"
|
||||
"github.com/jroimartin/gocui"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ui()
|
||||
}
|
||||
|
||||
func ui() {
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
|
@ -39,7 +42,7 @@ func sendmsg(g *gocui.Gui, v *gocui.View) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
fmt.Fprintln(chatbox, strings.TrimRight(msg, "\n"))
|
||||
fmt.Fprint(chatbox, msg)
|
||||
textarea.Clear()
|
||||
textarea.SetCursor(0, 0)
|
||||
return nil
|
||||
|
@ -63,7 +66,7 @@ func initKeybindings(g *gocui.Gui) error {
|
|||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
|
||||
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY/2+6); err != nil {
|
||||
if chatbox, err := g.SetView("chatbox", 2, 1, maxX/2+40, maxY-6); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
@ -71,7 +74,7 @@ func layout(g *gocui.Gui) error {
|
|||
fmt.Fprintln(chatbox, "Hello world!")
|
||||
}
|
||||
|
||||
if button, err := g.SetView("button", maxX/2+32, maxY/2+9, maxX/2+40, maxY/2+11); err != nil {
|
||||
if button, err := g.SetView("button", maxX/2+32, maxY-4, maxX/2+40, maxY-2); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
@ -81,7 +84,7 @@ func layout(g *gocui.Gui) error {
|
|||
fmt.Fprintln(button, "Send it")
|
||||
}
|
||||
|
||||
if textarea, err := g.SetView("textarea", 2, maxY/2+9, maxX/2+25, maxY/2+11); err != nil {
|
||||
if textarea, err := g.SetView("textarea", 2, maxY-4, maxX/2+28, maxY-2); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
|
@ -93,6 +96,13 @@ func layout(g *gocui.Gui) error {
|
|||
textarea.Editable = true
|
||||
}
|
||||
|
||||
if currentUsers, err := g.SetView("currentUsers", maxX/2+42, 1, maxX-6, maxY-6); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
currentUsers.Title = "Connected users"
|
||||
}
|
||||
|
||||
// TODO: Add "Users currently online" view
|
||||
// if currentUsers, err := g.SetView("currentUsers", maxX/2+34, 1, maxX/2+40, maxY/2+11); err != nil {
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue