mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 13:17:23 +00:00
Merge branch 'awesome-gocui' of https://github.com/Rudi9719/kbtui into dev
This commit is contained in:
60
main.go
60
main.go
@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jroimartin/gocui"
|
"github.com/awesome-gocui/gocui"
|
||||||
"samhofi.us/x/keybase"
|
"samhofi.us/x/keybase"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,13 +28,13 @@ func main() {
|
|||||||
fmt.Println("You are not logged in.")
|
fmt.Println("You are not logged in.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
kbtui, err := gocui.NewGui(gocui.OutputNormal)
|
var err error
|
||||||
|
g, err = gocui.NewGui(gocui.OutputNormal, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
fmt.Printf("%+v", err)
|
||||||
}
|
}
|
||||||
defer kbtui.Close()
|
defer g.Close()
|
||||||
kbtui.SetManagerFunc(layout)
|
g.SetManagerFunc(layout)
|
||||||
g = kbtui
|
|
||||||
go populateList()
|
go populateList()
|
||||||
go updateChatWindow()
|
go updateChatWindow()
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
@ -42,11 +42,12 @@ func main() {
|
|||||||
RunCommand(os.Args...)
|
RunCommand(os.Args...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
fmt.Println("initKeybindings")
|
||||||
if err := initKeybindings(); err != nil {
|
if err := initKeybindings(); err != nil {
|
||||||
log.Printf("%+v", err)
|
fmt.Printf("%+v", err)
|
||||||
}
|
}
|
||||||
if err := kbtui.MainLoop(); err != nil && err != gocui.ErrQuit {
|
if err := g.MainLoop(); err != nil && !gocui.IsQuit(err) {
|
||||||
log.Printf("%+v", err)
|
fmt.Printf("%+v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,16 +231,16 @@ func printToView(viewName string, message string) {
|
|||||||
|
|
||||||
func layout(g *gocui.Gui) error {
|
func layout(g *gocui.Gui) error {
|
||||||
maxX, maxY := g.Size()
|
maxX, maxY := g.Size()
|
||||||
if editView, err := g.SetView("Edit", maxX/2-maxX/3+1, maxY/2, maxX-2, maxY/2+10); err != nil {
|
if editView, err := g.SetView("Edit", maxX/2-maxX/3+1, maxY/2, maxX-2, maxY/2+10, 0); err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if !gocui.IsUnknownView(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
editView.Editable = true
|
editView.Editable = true
|
||||||
editView.Wrap = true
|
editView.Wrap = true
|
||||||
fmt.Fprintln(editView, "Edit window. Should disappear")
|
fmt.Fprintln(editView, "Edit window. Should disappear")
|
||||||
}
|
}
|
||||||
if feedView, err := g.SetView("Feed", maxX/2-maxX/3, 0, maxX-1, maxY/5); err != nil {
|
if feedView, err := g.SetView("Feed", maxX/2-maxX/3, 0, maxX-1, maxY/5, 0); err != nil {
|
||||||
if err != gocui.ErrUnknownView {
|
if !gocui.IsUnknownView(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
feedView.Autoscroll = true
|
feedView.Autoscroll = true
|
||||||
@ -247,8 +248,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
feedView.Title = "Feed Window"
|
feedView.Title = "Feed Window"
|
||||||
fmt.Fprintln(feedView, "Feed Window - If you are mentioned or receive a PM it will show here")
|
fmt.Fprintln(feedView, "Feed Window - If you are mentioned or receive a PM it will show here")
|
||||||
}
|
}
|
||||||
if chatView, err2 := g.SetView("Chat", maxX/2-maxX/3, maxY/5+1, maxX-1, maxY-5); err2 != nil {
|
if chatView, err2 := g.SetView("Chat", maxX/2-maxX/3, maxY/5+1, maxX-1, maxY-5, 0); err2 != nil {
|
||||||
if err2 != gocui.ErrUnknownView {
|
if !gocui.IsUnknownView(err2) {
|
||||||
return err2
|
return err2
|
||||||
}
|
}
|
||||||
chatView.Autoscroll = true
|
chatView.Autoscroll = true
|
||||||
@ -256,8 +257,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
|
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
|
||||||
RunCommand("help")
|
RunCommand("help")
|
||||||
}
|
}
|
||||||
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1); err3 != nil {
|
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1, 0); err3 != nil {
|
||||||
if err3 != gocui.ErrUnknownView {
|
if !gocui.IsUnknownView(err3) {
|
||||||
return err3
|
return err3
|
||||||
}
|
}
|
||||||
if _, err := g.SetCurrentView("Input"); err != nil {
|
if _, err := g.SetCurrentView("Input"); err != nil {
|
||||||
@ -268,8 +269,8 @@ func layout(g *gocui.Gui) error {
|
|||||||
inputView.Title = " Not in a chat /j to join"
|
inputView.Title = " Not in a chat /j to join"
|
||||||
g.Cursor = true
|
g.Cursor = true
|
||||||
}
|
}
|
||||||
if listView, err4 := g.SetView("List", 0, 0, maxX/2-maxX/3-1, maxY-1); err4 != nil {
|
if listView, err4 := g.SetView("List", 0, 0, maxX/2-maxX/3-1, maxY-1, 0); err4 != nil {
|
||||||
if err4 != gocui.ErrUnknownView {
|
if !gocui.IsUnknownView(err4) {
|
||||||
return err4
|
return err4
|
||||||
}
|
}
|
||||||
listView.Title = "Channels"
|
listView.Title = "Channels"
|
||||||
@ -277,6 +278,27 @@ func layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func layout2(g *gocui.Gui) error {
|
||||||
|
maxX, maxY := g.Size()
|
||||||
|
if feedView, err := g.SetView("Feed2", maxX/2-maxX/3, 0, maxX-1, maxY/5, 0); err != nil {
|
||||||
|
if !gocui.IsUnknownView(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
feedView.Autoscroll = true
|
||||||
|
feedView.Wrap = true
|
||||||
|
fmt.Fprintln(feedView, "Feed Window - If you are mentioned or receive a PM it will show here")
|
||||||
|
}
|
||||||
|
if chatView, err2 := g.SetView("Chat2", maxX/2-maxX/3, maxY/5+1, maxX-1, maxY-5, 0); err2 != nil {
|
||||||
|
if !gocui.IsUnknownView(err2) {
|
||||||
|
return err2
|
||||||
|
}
|
||||||
|
chatView.Autoscroll = true
|
||||||
|
chatView.Wrap = true
|
||||||
|
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
|
||||||
|
RunCommand("help")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getInputString(viewName string) (string, error) {
|
func getInputString(viewName string) (string, error) {
|
||||||
inputView, _ := g.View(viewName)
|
inputView, _ := g.View(viewName)
|
||||||
|
|||||||
Reference in New Issue
Block a user