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