Skip to content

Instantly share code, notes, and snippets.

@nakabonne
Created November 4, 2017 03:56
Show Gist options
  • Save nakabonne/6247637a39f32ba0543f5b0421297357 to your computer and use it in GitHub Desktop.
Save nakabonne/6247637a39f32ba0543f5b0421297357 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"time"
"github.com/marcusolsson/tui-go"
)
type post struct {
username string
message string
time string
}
var posts = []post{
{username: "ryo", message: "Hello!", time: "14:41"},
}
func main() {
var name = flag.String("u", "kazuki", "Set your name")
flag.Parse()
sidebar := tui.NewVBox(
tui.NewLabel("CHANNELS"),
tui.NewLabel("general"),
tui.NewLabel("random"),
tui.NewLabel(""),
tui.NewLabel("DIRECT MESSAGES"),
tui.NewLabel("slackbot"),
tui.NewSpacer(),
)
sidebar.SetBorder(true)
history := tui.NewVBox()
history.SetBorder(true)
history.Append(tui.NewSpacer())
for _, m := range posts {
history.Append(tui.NewHBox(
tui.NewLabel(m.time),
tui.NewPadder(1, 0, tui.NewLabel(fmt.Sprintf("<%s>", m.username))),
tui.NewLabel(m.message),
tui.NewSpacer(),
))
}
input := tui.NewEntry()
input.SetFocused(true)
input.SetSizePolicy(tui.Expanding, tui.Maximum)
inputBox := tui.NewHBox(input)
inputBox.SetBorder(true)
inputBox.SetSizePolicy(tui.Expanding, tui.Maximum)
chat := tui.NewVBox(history, inputBox)
chat.SetSizePolicy(tui.Expanding, tui.Expanding)
input.OnSubmit(func(e *tui.Entry) {
history.Append(tui.NewHBox(
tui.NewLabel(time.Now().Format("15:04")),
tui.NewPadder(1, 0, tui.NewLabel(fmt.Sprintf("<%s>", *name))),
tui.NewLabel(e.Text()),
tui.NewSpacer(),
))
input.SetText("")
})
root := tui.NewHBox(sidebar, chat)
ui := tui.New(root)
ui.SetKeybinding("Esc", func() { ui.Quit() })
if err := ui.Run(); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment