From 4a49ae20cf3b33f7111b59033bb5d51e21cd6043 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:05:40 -0400 Subject: [PATCH 01/10] Update input title on join --- cmdJoin.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmdJoin.go b/cmdJoin.go index fecc1f4..8d040d4 100644 --- a/cmdJoin.go +++ b/cmdJoin.go @@ -27,6 +27,7 @@ func cmdJoin(cmd []string) { channel.TopicName = cmd[2] printToView("Feed", fmt.Sprintf("You are joining: @%s#%s", channel.Name, channel.TopicName)) clearView("Chat") + viewTitle("Input", fmt.Sprintf(" @%s#%s ", channel.Name, channel.TopicName)) go populateChat() } else if len(cmd) == 2 { channel.MembersType = keybase.USER @@ -34,6 +35,7 @@ func cmdJoin(cmd []string) { channel.TopicName = "" printToView("Feed", fmt.Sprintf("You are joining: @%s", channel.Name)) clearView("Chat") + viewTitle("Input", fmt.Sprintf(" @%s ", channel.Name)) go populateChat() } else { printToView("Feed", fmt.Sprintf("To join a team use %sjoin ", cmdPrefix)) From 6aa1302bbe684ca43bc9215ee16b0ec3de875555 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:06:25 -0400 Subject: [PATCH 02/10] Add editView (WIP) and funcs to set viewTitle/popup a view --- main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/main.go b/main.go index 98adadf..5728e8f 100644 --- a/main.go +++ b/main.go @@ -49,6 +49,25 @@ func main() { log.Printf("%+v", err) } } + +func viewTitle(viewName string, title string) { + g.Update(func(g *gocui.Gui) error { + updatingView, err := g.View(viewName) + if err != nil { + return err + } else { + updatingView.Title = title + } + return nil + }) +} +func popupView(viewName string) { + _, err := g.SetViewOnTop(viewName) + if err != nil { + printToView("Feed", fmt.Sprintf("%+v", err)) + } +} + func populateChat() { lastMessage.ID = 0 chat := k.NewChat(channel) @@ -196,12 +215,19 @@ func printToView(viewName string, message string) { func layout(g *gocui.Gui) error { maxX, maxY := g.Size() + if editView, err := g.SetView("Edit", maxX/2, maxY/2, maxX/2+10, maxY/2+10); err != nil { + if err != gocui.ErrUnknownView { + return err + } + 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 err != gocui.ErrUnknownView { return err } feedView.Autoscroll = true feedView.Wrap = true + feedView.Title = "Feed" 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 { From 9d7ca47595d3307c7e07d142c43c3b6236a06e5b Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:06:48 -0400 Subject: [PATCH 03/10] No more auto-react --- tcmdAutoReact.go | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 tcmdAutoReact.go diff --git a/tcmdAutoReact.go b/tcmdAutoReact.go deleted file mode 100644 index 7919927..0000000 --- a/tcmdAutoReact.go +++ /dev/null @@ -1,27 +0,0 @@ -// +ignore -// +build type_commands autoreactcmd - -package main - -import ( - "samhofi.us/x/keybase" -) - -func init() { - command := TypeCommand{ - Cmd: []string{"text"}, - Name: "AutoReact", - Description: "Automatically reacts to every incoming message with an emoji", - Exec: tcmdAutoReact, - } - - RegisterTypeCommand(command) -} - -func tcmdAutoReact(m keybase.ChatAPI) { - msgID := m.Msg.ID - channel := m.Msg.Channel - chat := k.NewChat(channel) - chat.React(msgID, ":+1:") - -} From ed1edb40423e5c0598ee647236c499d1389c6f52 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:48:01 -0400 Subject: [PATCH 04/10] Simplified editing with popup funcs in main --- cmdEdit.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/cmdEdit.go b/cmdEdit.go index dbfc766..aaebe84 100644 --- a/cmdEdit.go +++ b/cmdEdit.go @@ -6,8 +6,6 @@ import ( "fmt" "strconv" "strings" - - "github.com/jroimartin/gocui" ) func init() { @@ -37,24 +35,10 @@ func cmdEdit(cmd []string) { return } editString := origMessage.Result.Messages[0].Msg.Content.Text.Body - g.Update(func(g *gocui.Gui) error { - inputView, err := g.View("Input") - if err != nil { - return err - } else { - editString = fmt.Sprintf("/edit %d %s", messageId, editString) - fmt.Fprintf(inputView, editString) - viewX, viewY := inputView.Size() - if len(editString) < viewX { - viewX = len(editString) - viewY = 0 - } else { - viewX = viewX / len(editString) - } - inputView.MoveCursor(viewX, viewY, true) - } - return nil - }) + clearView("Edit") + popupView("Edit") + printToView("Edit", fmt.Sprintf("/e %d %s", messageId, editString)) + viewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageId)) return } if len(cmd) < 3 { From 3da9fd039096e8a3ee6869123e603d3e2df7132d Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:48:19 -0400 Subject: [PATCH 05/10] Popup funcs and edit view input handler --- main.go | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 5728e8f..f83efb6 100644 --- a/main.go +++ b/main.go @@ -62,10 +62,25 @@ func viewTitle(viewName string, title string) { }) } func popupView(viewName string) { - _, err := g.SetViewOnTop(viewName) + _, err := g.SetCurrentView(viewName) if err != nil { printToView("Feed", fmt.Sprintf("%+v", err)) } + _, err = g.SetViewOnTop(viewName) + if err != nil { + printToView("Feed", fmt.Sprintf("%+v", err)) + } + g.Update(func(g *gocui.Gui) error { + updatingView, err := g.View(viewName) + if err != nil { + return err + } else { + viewX, viewY := updatingView.Size() + updatingView.MoveCursor(viewX, viewY, true) + } + return nil + + }) } func populateChat() { @@ -215,10 +230,12 @@ func printToView(viewName string, message string) { func layout(g *gocui.Gui) error { maxX, maxY := g.Size() - if editView, err := g.SetView("Edit", maxX/2, maxY/2, maxX/2+10, maxY/2+10); err != nil { + if editView, err := g.SetView("Edit", maxX/2-maxX/3+1, maxY/2, maxX-2, maxY/2+10); err != nil { if err != gocui.ErrUnknownView { return err } + editView.Editable = true + editView.Wrap = true fmt.Fprintln(editView, "Edit window. Should disappear") } if feedView, err := g.SetView("Feed", maxX/2-maxX/3, 0, maxX-1, maxY/5); err != nil { @@ -259,15 +276,15 @@ func layout(g *gocui.Gui) error { return nil } -func getInputString() (string, error) { - inputView, _ := g.View("Input") +func getInputString(viewName string) (string, error) { + inputView, _ := g.View(viewName) return inputView.Line(0) } func initKeybindings() error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - input, err := getInputString() + input, err := getInputString("Input") if err != nil { return err } @@ -282,7 +299,16 @@ func initKeybindings() error { } if err := g.SetKeybinding("Input", gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { - return handleInput() + return handleInput("Input") + }); err != nil { + return err + } + if err := g.SetKeybinding("Edit", gocui.KeyEnter, gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + popupView("Chat") + popupView("Input") + return handleInput("Edit") + }); err != nil { return err } @@ -369,9 +395,9 @@ func handleMessage(api keybase.ChatAPI) { } } -func handleInput() error { - clearView("Input") - inputString, _ := getInputString() +func handleInput(viewName string) error { + clearView(viewName) + inputString, _ := getInputString(viewName) if inputString == "" { return nil } From f37739ed700a22eb0b9c9323edd218a51a4b9082 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 11:48:53 -0400 Subject: [PATCH 06/10] Formatting --- mage.go | 1 + 1 file changed, 1 insertion(+) diff --git a/mage.go b/mage.go index c06f835..fb1b1d2 100644 --- a/mage.go +++ b/mage.go @@ -35,6 +35,7 @@ func BuildAllCommands() { func BuildAllCommandsT() { sh.Run("go", "build", "-tags", "type_commands,allcommands") } + // Build kbtui with beta functionality func BuildBeta() { sh.Run("go", "build", "-tags", "allcommands,showreactionscmd") From 502467a16260d73d1d352d3266b25f43fd5e1f77 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 12:13:11 -0400 Subject: [PATCH 07/10] Updated readme to remove old command and update build instructions --- README.md | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6d08f61..040ea9b 100644 --- a/README.md +++ b/README.md @@ -16,27 +16,31 @@ For support or suggestions check out the [kbtui team](https://keybase.io/team/kb * Reactions to messages * Auto #general teams when not given a channel * Pretty format headers in List view from window size - -## Todo * Message editing * Twitter-style feed reading public messages + +## Todo * Track multiple conversations at once +* Message replies + ### Building and Running Easiest Way: ``` go get -u github.com/rudi9719/kbtui ``` - +Or you can do the following: ``` go get ./ -go build +go run build.go +go run build.go {build, buildBeta... etc} ./kbtui ``` -Or -``` -go get ./ -go run *.go -``` + +You may see an error with `go get ./` about PATHs, that may be safely ignored. + +If you see an error about a missing dependancy during a build, you'll want to resolve that. + + Occasionally when @dxb updates his API it will be necessary to run `go get -u ./` From 80ecb530d469b8842c15626a53479705a59c5e59 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 12:14:25 -0400 Subject: [PATCH 08/10] Set inputView title when out of chat --- cmdStream.go | 1 + main.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmdStream.go b/cmdStream.go index 9b60920..cbfc0ba 100644 --- a/cmdStream.go +++ b/cmdStream.go @@ -17,5 +17,6 @@ func cmdStream(cmd []string) { stream = true channel.Name = "" printToView("Feed", "You are now viewing the formatted stream") + viewTitle("Input", " Not in a chat /j to join ") clearView("Chat") } diff --git a/main.go b/main.go index f83efb6..eb72da6 100644 --- a/main.go +++ b/main.go @@ -265,6 +265,7 @@ func layout(g *gocui.Gui) error { } inputView.Editable = true inputView.Wrap = true + inputView.Title = " Not in a chat /j to join" g.Cursor = true } if listView, err4 := g.SetView("List", 0, 0, maxX/2-maxX/3-1, maxY-1); err4 != nil { From 21f2d29289edc9109887c0427bbfca0a462e536d Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 12:59:41 -0400 Subject: [PATCH 09/10] Add ShowReactions to basic commands --- tcmdShowReactions.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tcmdShowReactions.go b/tcmdShowReactions.go index c4c1b40..e0cfa98 100644 --- a/tcmdShowReactions.go +++ b/tcmdShowReactions.go @@ -1,5 +1,4 @@ -// +ignore -// +build type_commands showreactionscmd +// +build !rm_basic_commands type_commands showreactionscmd package main From 1f016ca09a1648ac655c118a17662308b91c4a7b Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 9 Oct 2019 14:20:54 -0400 Subject: [PATCH 10/10] Added titles to feed and channels, as well as ring terminal bell when feed is populated --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index eb72da6..8ded3a5 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func layout(g *gocui.Gui) error { } feedView.Autoscroll = true feedView.Wrap = true - feedView.Title = "Feed" + feedView.Title = "Feed Window" 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 { @@ -272,6 +272,7 @@ func layout(g *gocui.Gui) error { if err4 != gocui.ErrUnknownView { return err4 } + listView.Title = "Channels" fmt.Fprintf(listView, "Lists\nWindow\nTo view\n activity") } return nil @@ -367,6 +368,7 @@ func handleMessage(api keybase.ChatAPI) { } } + fmt.Print("\a") } if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name { if channel.MembersType == keybase.TEAM && channel.TopicName != api.Msg.Channel.TopicName {