From 707195232e9b55296401af80a4a14ed512f5ffa1 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Fri, 18 Oct 2019 14:50:02 -0400 Subject: [PATCH 01/19] Better attachment handling after PR to samhofi.us/x/keybase --- cmdDownload.go | 21 +++++++++++++++++---- main.go | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmdDownload.go b/cmdDownload.go index ff6cbbf..796517c 100644 --- a/cmdDownload.go +++ b/cmdDownload.go @@ -24,16 +24,29 @@ func cmdDownloadFile(cmd []string) { printToView("Feed", fmt.Sprintf("%s%s $messageId $fileName - Download a file to user's downloadpath", cmdPrefix, cmd[0])) return } - messageID, _ := strconv.Atoi(cmd[1]) + messageID, err := strconv.Atoi(cmd[1]) + if err != nil { + printToView("Feed", "There was an error converting your messageID to an int") + return + } + chat := k.NewChat(channel) + api, err := chat.ReadMessage(messageID) + if err != nil { + printToView("Feed", fmt.Sprintf("There was an error pulling message %d", messageID)) + return + } + if api.Result.Messages[0].Msg.Content.Type != "attachment" { + printToView("Feed", "No attachment detected") + return + } var fileName string if len(cmd) == 3 { fileName = cmd[2] } else { - fileName = "" + fileName = api.Result.Messages[0].Msg.Content.Attachment.Object.Filename } - chat := k.NewChat(channel) - _, err := chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName)) + _, err = chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName)) if err != nil { printToView("Feed", fmt.Sprintf("There was an error downloading %s from %s", fileName, channel.Name)) } else { diff --git a/main.go b/main.go index efa5640..2d8cec0 100644 --- a/main.go +++ b/main.go @@ -365,7 +365,7 @@ func formatOutput(api keybase.ChatAPI) string { msg = colorRegex(msg, `(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))`, messageLinkColor, messageBodyColor) msg = colorText(colorReplaceMentionMe(msg, messageBodyColor), messageBodyColor, c) if msgType == "attachment" { - msg = fmt.Sprintf("%s", colorText("[Attachment]", messageAttachmentColor, c)) + msg = fmt.Sprintf("%s\n%s", api.Msg.Content.Attachment.Object.Title, colorText(fmt.Sprintf("[Attachment: %s]", api.Msg.Content.Attachment.Object.Filename), messageAttachmentColor, c)) } user := colorUsername(api.Msg.Sender.Username, c) device := colorText(api.Msg.Sender.DeviceName, messageSenderDeviceColor, c) From 514059e990b0e27e17d078fd84a9d817fcd28e84 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 21 Oct 2019 13:57:26 -0400 Subject: [PATCH 02/19] Separate standard lib imports from remote imports --- mage.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mage.go b/mage.go index 1cb2fcd..c9346e4 100644 --- a/mage.go +++ b/mage.go @@ -5,12 +5,13 @@ package main import ( "encoding/json" "fmt" - "github.com/magefile/mage/mg" - "github.com/magefile/mage/sh" "io/ioutil" "net/http" "os" "strings" + + "github.com/magefile/mage/mg" + "github.com/magefile/mage/sh" ) // emoji related constants From dbf53680e61df88d391b47aaff56b9adff99147f Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 21 Oct 2019 14:58:26 -0400 Subject: [PATCH 03/19] Download package updates before building --- mage.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mage.go b/mage.go index c9346e4..ff15790 100644 --- a/mage.go +++ b/mage.go @@ -62,8 +62,25 @@ func createEmojiSlice() ([]string, error) { return emojiSlice, nil } +func getRemotePackages() error { + var packages = []string{ + "samhofi.us/x/keybase", + "github.com/awesome-gocui/gocui", + "github.com/magefile/mage/mage", + "github.com/magefile/mage/mg", + "github.com/magefile/mage/sh", + } + for _, p := range packages { + if err := sh.Run("go", "get", "-u", p); err != nil { + return err + } + } + return nil +} + // Build kbtui with emoji lookup support func BuildEmoji() error { + mg.Deps(getRemotePackages) emojis, err := createEmojiSlice() if err != nil { return err @@ -93,6 +110,7 @@ func exit(err error) { // Build kbtui with just the basic commands. func Build() { + mg.Deps(getRemotePackages) if err := sh.Run("go", "build"); err != nil { defer func() { exit(err) @@ -104,6 +122,7 @@ func Build() { // The ShowReactions TypeCommand will print a message in the feed window when // a reaction is received in the current conversation. func BuildShowReactions() { + mg.Deps(getRemotePackages) if err := sh.Run("go", "build", "-tags", "showreactionscmd"); err != nil { defer func() { exit(err) @@ -116,6 +135,7 @@ func BuildShowReactions() { // received in the current conversation. This gets pretty annoying, and // is not recommended. func BuildAutoReact() { + mg.Deps(getRemotePackages) if err := sh.Run("go", "build", "-tags", "autoreactcmd"); err != nil { defer func() { exit(err) @@ -125,6 +145,7 @@ func BuildAutoReact() { // Build kbtui with all commands and TypeCommands disabled. func BuildAllCommands() { + mg.Deps(getRemotePackages) if err := sh.Run("go", "build", "-tags", "allcommands"); err != nil { defer func() { exit(err) @@ -134,6 +155,7 @@ func BuildAllCommands() { // Build kbtui with all Commands and TypeCommands enabled. func BuildAllCommandsT() { + mg.Deps(getRemotePackages) if err := sh.Run("go", "build", "-tags", "type_commands,allcommands"); err != nil { defer func() { exit(err) @@ -143,6 +165,7 @@ func BuildAllCommandsT() { // Build kbtui with beta functionality func BuildBeta() { + mg.Deps(getRemotePackages) mg.Deps(BuildEmoji) if err := sh.Run("go", "build", "-tags", "allcommands,showreactionscmd,emojiList,tabcompletion"); err != nil { defer func() { From 14c7f9353a3d823449ea2b23b91eaa7353552c3d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 21 Oct 2019 14:59:39 -0400 Subject: [PATCH 04/19] Move exit helper func above first build target --- mage.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mage.go b/mage.go index ff15790..5fd0f28 100644 --- a/mage.go +++ b/mage.go @@ -78,6 +78,14 @@ func getRemotePackages() error { return nil } +// proper error reporting and exit code +func exit(err error) { + if err != nil { + fmt.Fprintf(os.Stderr, "%+v\n", err) + os.Exit(1) + } +} + // Build kbtui with emoji lookup support func BuildEmoji() error { mg.Deps(getRemotePackages) @@ -100,14 +108,6 @@ func BuildEmoji() error { return nil } -// proper error reporting and exit code -func exit(err error) { - if err != nil { - fmt.Fprintf(os.Stderr, "%+v\n", err) - os.Exit(1) - } -} - // Build kbtui with just the basic commands. func Build() { mg.Deps(getRemotePackages) From 112d2da2e863eb8696048343764fc1d6fd2226da Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Mon, 21 Oct 2019 15:09:04 -0400 Subject: [PATCH 05/19] Basic implementation of config file --- cmdSet.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmdSet.go b/cmdSet.go index fabdc06..0a2dacf 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -5,6 +5,8 @@ package main import ( "fmt" "strings" + + "github.com/pelletier/go-toml" ) func init() { @@ -26,7 +28,8 @@ func cmdSet(cmd []string) { if len(cmd) < 3 { switch cmd[1] { case "load": - printToView("Feed", "Load values from file?") + loadFromToml() + printToView("Feed", fmt.Sprintf("Loading config from toml")) case "downloadPath": printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath)) case "outputFormat": @@ -62,3 +65,16 @@ func cmdSet(cmd []string) { } } +func loadFromToml() { + config, err := toml.LoadFile("kbtui.tml") + if err != nil { + printToView("Feed", fmt.Sprintf("Could not read config file: %+v", err)) + return + } + colorless = config.Get("Basics.colorless").(bool) + downloadPath = config.Get("Basics.downloadPath").(string) + cmdPrefix = config.Get("Basics.cmdPrefix").(string) + outputFormat = config.Get("Formatting.outputFormat").(string) + dateFormat = config.Get("Formatting.dateFormat").(string) + timeFormat = config.Get("Formatting.timeFormat").(string) +} From b960ffdde4e3383c3afec0617882fa32d761a178 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Mon, 21 Oct 2019 15:16:44 -0400 Subject: [PATCH 06/19] Feature: add Config TOML file #17 --- kbtui.tml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 kbtui.tml diff --git a/kbtui.tml b/kbtui.tml new file mode 100644 index 0000000..4ce8ecb --- /dev/null +++ b/kbtui.tml @@ -0,0 +1,30 @@ +[Basics] +downloadPath = "/tmp/" +colorless = false +# The prefix before evaluating a command +cmdPrefix = "/" + +[Formatting] +# BASH-like PS1 variable equivalent +outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG" + +# 02 = Day, Jan = Month, 06 = Year +dateFormat = "02Jan06" + +# 15 = hours, 04 = minutes, 05 = seconds +timeFormat = "15:04" + + +[Colors] +channelsColor = 8 +channelsHeaderColor = 6 +noColor = -1 +mentionColor = 3 +messageHeaderColor = 8 +messageIdColor = 7 +messageTimeColor = 6 +messageSenderDefaultColor = 8 +messageSenderDeviceColor = 8 +messageBodyColor = -1 +messageAttachmentColor = 2 +messageLinkColor = 4 From db6e367facb4f5a1198ff32b3d4ca2b4cf03a2fc Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 08:05:51 -0400 Subject: [PATCH 07/19] Bugfix: Up arrow in stream/start crashes application --- cmdEdit.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmdEdit.go b/cmdEdit.go index af40142..889ac5f 100644 --- a/cmdEdit.go +++ b/cmdEdit.go @@ -25,10 +25,16 @@ func cmdEdit(cmd []string) { if len(cmd) == 2 || len(cmd) == 1 { if len(cmd) == 2 { messageId, _ = strconv.Atoi(cmd[1]) - } else { + } else if lastMessage.ID != 0 { + if lastMessage.Type != "text" { + printToView("Feed", "Last message isn't editable (is it an edit?)") + return + } messageId = lastMessage.ID + } else { + printToView("Feed", "No message to edit") + return } - origMessage, _ := chat.ReadMessage(messageId) if origMessage.Result.Messages[0].Msg.Content.Type != "text" { printToView("Feed", fmt.Sprintf("%+v", origMessage)) From 1fd39aa9abd0d1756c98a179f3002fa81fc8222a Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 08:29:40 -0400 Subject: [PATCH 08/19] Bugfix: Add nullcheck for toml values from #18 --- cmdSet.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/cmdSet.go b/cmdSet.go index 0a2dacf..8757102 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -71,10 +71,22 @@ func loadFromToml() { printToView("Feed", fmt.Sprintf("Could not read config file: %+v", err)) return } - colorless = config.Get("Basics.colorless").(bool) - downloadPath = config.Get("Basics.downloadPath").(string) - cmdPrefix = config.Get("Basics.cmdPrefix").(string) - outputFormat = config.Get("Formatting.outputFormat").(string) - dateFormat = config.Get("Formatting.dateFormat").(string) - timeFormat = config.Get("Formatting.timeFormat").(string) + if config.Has("Basics.colorless") { + colorless = config.Get("Basics.colorless").(bool) + } + if config.Has("Basics.downloadPath") { + downloadPath = config.Get("Basics.downloadPath").(string) + } + if config.Has("Basics.cmdPrefix") { + cmdPrefix = config.Get("Basics.cmdPrefix").(string) + } + if config.Has("Formatting.outputFormat") { + outputFormat = config.Get("Formatting.outputFormat").(string) + } + if config.Has("Formatting.dateFormat") { + dateFormat = config.Get("Formatting.dateFormat").(string) + } + if config.Has("Formatting.timeFormat") { + timeFormat = config.Get("Formatting.timeFormat").(string) + } } From 1d412ed5fd14f615c64e7f6094a89820f2d846c4 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 08:32:05 -0400 Subject: [PATCH 09/19] Update Travis now that mage auto-checks dependancies --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 085d22d..b17a781 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,6 @@ go: install: true script: - - go get -u samhofi.us/x/keybase - - go get -u github.com/awesome-gocui/gocui - go get -u github.com/magefile/mage/mage - go run build.go buildBeta - go vet ./... From 8cab261b1d48f4c1598f320f04d4b893b3e0568c Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 08:32:30 -0400 Subject: [PATCH 10/19] Add go-toml dep for #17 in mage --- mage.go | 1 + 1 file changed, 1 insertion(+) diff --git a/mage.go b/mage.go index 5fd0f28..5a4e11e 100644 --- a/mage.go +++ b/mage.go @@ -69,6 +69,7 @@ func getRemotePackages() error { "github.com/magefile/mage/mage", "github.com/magefile/mage/mg", "github.com/magefile/mage/sh", + "github.com/pelletier/go-toml", } for _, p := range packages { if err := sh.Run("go", "get", "-u", p); err != nil { From cc917a515f6ef24aa886472721988c5ae991feb4 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 08:45:37 -0400 Subject: [PATCH 11/19] Remove printSetting switch from cmdSet --- cmdSet.go | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/cmdSet.go b/cmdSet.go index 8757102..68a2d39 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -19,32 +19,34 @@ func init() { RegisterCommand(command) } +func printSetting(cmd []string) { + switch cmd[1] { + case "load": + loadFromToml() + printToView("Feed", fmt.Sprintf("Loading config from toml")) + case "downloadPath": + printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath)) + case "outputFormat": + printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], outputFormat)) + case "dateFormat": + printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], dateFormat)) + case "timeFormat": + printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], timeFormat)) + case "cmdPrefix": + printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], cmdPrefix)) + default: + printToView("Feed", fmt.Sprintf("Unknown config value %s", cmd[1])) + } + return +} func cmdSet(cmd []string) { if len(cmd) < 2 { printToView("Feed", "No config value specified") return } if len(cmd) < 3 { - switch cmd[1] { - case "load": - loadFromToml() - printToView("Feed", fmt.Sprintf("Loading config from toml")) - case "downloadPath": - printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath)) - case "outputFormat": - printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], outputFormat)) - case "dateFormat": - printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], dateFormat)) - case "timeFormat": - printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], timeFormat)) - case "cmdPrefix": - printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], cmdPrefix)) - default: - printToView("Feed", fmt.Sprintf("Unknown config value %s", cmd[1])) - } - - return + printSetting(cmd) } switch cmd[1] { case "downloadPath": From 2dd635669c3ce3899914258f97260f57ac6ea1e4 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 09:06:45 -0400 Subject: [PATCH 12/19] Linting code --- cmdEdit.go | 20 ++++++++++---------- cmdHelp.go | 2 +- cmdReact.go | 12 ++++++------ main.go | 43 ++++++++++++++++++++----------------------- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/cmdEdit.go b/cmdEdit.go index 889ac5f..58526cf 100644 --- a/cmdEdit.go +++ b/cmdEdit.go @@ -11,7 +11,7 @@ import ( func init() { command := Command{ Cmd: []string{"edit", "e"}, - Description: "$messageId - Edit a message (messageID is optional)", + Description: "$messageID - Edit a message (messageID is optional)", Help: "", Exec: cmdEdit, } @@ -20,22 +20,22 @@ func init() { } func cmdEdit(cmd []string) { - var messageId int + var messageID int chat := k.NewChat(channel) if len(cmd) == 2 || len(cmd) == 1 { if len(cmd) == 2 { - messageId, _ = strconv.Atoi(cmd[1]) + messageID, _ = strconv.Atoi(cmd[1]) } else if lastMessage.ID != 0 { if lastMessage.Type != "text" { printToView("Feed", "Last message isn't editable (is it an edit?)") return } - messageId = lastMessage.ID + messageID = lastMessage.ID } else { printToView("Feed", "No message to edit") return } - origMessage, _ := chat.ReadMessage(messageId) + origMessage, _ := chat.ReadMessage(messageID) if origMessage.Result.Messages[0].Msg.Content.Type != "text" { printToView("Feed", fmt.Sprintf("%+v", origMessage)) return @@ -47,19 +47,19 @@ func cmdEdit(cmd []string) { editString := origMessage.Result.Messages[0].Msg.Content.Text.Body clearView("Edit") popupView("Edit") - printToView("Edit", fmt.Sprintf("/e %d %s", messageId, editString)) - setViewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageId)) + printToView("Edit", fmt.Sprintf("/e %d %s", messageID, editString)) + setViewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageID)) return } if len(cmd) < 3 { printToView("Feed", "Not enough options for Edit") return } - messageId, _ = strconv.Atoi(cmd[1]) + messageID, _ = strconv.Atoi(cmd[1]) newMessage := strings.Join(cmd[2:], " ") - _, err := chat.Edit(messageId, newMessage) + _, err := chat.Edit(messageID, newMessage) if err != nil { - printToView("Feed", fmt.Sprintf("Error editing message %d, %+v", messageId, err)) + printToView("Feed", fmt.Sprintf("Error editing message %d, %+v", messageID, err)) } } diff --git a/cmdHelp.go b/cmdHelp.go index 0c9b1fa..bbf71de 100644 --- a/cmdHelp.go +++ b/cmdHelp.go @@ -28,7 +28,7 @@ func cmdHelp(cmd []string) { helpText = fmt.Sprintf("%s%s%s\t\t%s\n", helpText, cmdPrefix, c, commands[c].Description) } if len(typeCommands) > 0 { - for c, _ := range typeCommands { + for c := range typeCommands { tCommands = append(tCommands, typeCommands[c].Name) } sort.Strings(tCommands) diff --git a/cmdReact.go b/cmdReact.go index 1175216..ddd92f6 100644 --- a/cmdReact.go +++ b/cmdReact.go @@ -10,7 +10,7 @@ import ( func init() { command := Command{ Cmd: []string{"react", "r", "+"}, - Description: "$messageId $reaction - React to a message (messageID is optional)", + Description: "$messageID $reaction - React to a message (messageID is optional)", Help: "", Exec: cmdReact, } @@ -20,7 +20,7 @@ func init() { func cmdReact(cmd []string) { if len(cmd) > 2 { - reactToMessageId(cmd[1], strings.Join(cmd[2:], " ")) + reactToMessageID(cmd[1], strings.Join(cmd[2:], " ")) } else if len(cmd) == 2 { reactToMessage(cmd[1]) } @@ -30,13 +30,13 @@ func cmdReact(cmd []string) { func reactToMessage(reaction string) { doReact(lastMessage.ID, reaction) } -func reactToMessageId(messageId string, reaction string) { - ID, _ := strconv.Atoi(messageId) +func reactToMessageID(messageID string, reaction string) { + ID, _ := strconv.Atoi(messageID) doReact(ID, reaction) } -func doReact(messageId int, reaction string) { +func doReact(messageID int, reaction string) { chat := k.NewChat(channel) - _, err := chat.React(messageId, reaction) + _, err := chat.React(messageID, reaction) if err != nil { printToView("Feed", "There was an error reacting to the message.") } diff --git a/main.go b/main.go index 2d8cec0..6805fb5 100644 --- a/main.go +++ b/main.go @@ -114,9 +114,8 @@ func initKeybindings() error { if input != "" { clearView("Input") return nil - } else { - return gocui.ErrQuit } + return gocui.ErrQuit }); err != nil { return err } @@ -168,9 +167,8 @@ func setViewTitle(viewName string, title string) { updatingView, err := g.View(viewName) if err != nil { return err - } else { - updatingView.Title = title } + updatingView.Title = title return nil }) } @@ -180,9 +178,9 @@ func getViewTitle(viewName string) string { // in case there is active tab completion, filter that to just the view title and not the completion options. printToView("Feed", fmt.Sprintf("Error getting view title: %s", err)) return "" - } else { - return strings.Split(view.Title, "||")[0] } + return strings.Split(view.Title, "||")[0] + } func popupView(viewName string) { _, err := g.SetCurrentView(viewName) @@ -197,10 +195,10 @@ func popupView(viewName string) { updatingView, err := g.View(viewName) if err != nil { return err - } else { - viewX, viewY := updatingView.Size() - updatingView.MoveCursor(viewX, viewY, true) } + viewX, viewY := updatingView.Size() + updatingView.MoveCursor(viewX, viewY, true) + return nil }) @@ -210,11 +208,11 @@ func clearView(viewName string) { inputView, err := g.View(viewName) if err != nil { return err - } else { - inputView.Clear() - inputView.SetCursor(0, 0) - inputView.SetOrigin(0, 0) } + inputView.Clear() + inputView.SetCursor(0, 0) + inputView.SetOrigin(0, 0) + return nil }) @@ -224,11 +222,11 @@ func writeToView(viewName string, message string) { updatingView, err := g.View(viewName) if err != nil { return err - } else { - for _, c := range message { - updatingView.EditWrite(c) - } } + for _, c := range message { + updatingView.EditWrite(c) + } + return nil }) } @@ -237,9 +235,8 @@ func printToView(viewName string, message string) { updatingView, err := g.View(viewName) if err != nil { return err - } else { - fmt.Fprintf(updatingView, "%s\n", message) } + fmt.Fprintf(updatingView, "%s\n", message) return nil }) } @@ -275,11 +272,11 @@ func populateChat() { if err2 != nil { printToView("Feed", fmt.Sprintf("%+v", err)) return - } else { - go populateChat() - go generateChannelTabCompletionSlice() - return } + go populateChat() + go generateChannelTabCompletionSlice() + return + } var printMe []string var actuallyPrintMe string From e084c16ba85931048bc81a63c8352d6c063b7cc9 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 09:18:27 -0400 Subject: [PATCH 13/19] Bugfix #24: Set cursor of popupView to 0,0 to avoid strange input bugs --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 6805fb5..cea2ab1 100644 --- a/main.go +++ b/main.go @@ -196,8 +196,7 @@ func popupView(viewName string) { if err != nil { return err } - viewX, viewY := updatingView.Size() - updatingView.MoveCursor(viewX, viewY, true) + updatingView.MoveCursor(0, 0, true) return nil From 5eb23ff9935437b9a89e747e140a87e2e42ab695 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 09:30:18 -0400 Subject: [PATCH 14/19] Bug #24: Cursor now moves to end of message --- cmdEdit.go | 1 + main.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cmdEdit.go b/cmdEdit.go index 58526cf..ed950eb 100644 --- a/cmdEdit.go +++ b/cmdEdit.go @@ -49,6 +49,7 @@ func cmdEdit(cmd []string) { popupView("Edit") printToView("Edit", fmt.Sprintf("/e %d %s", messageID, editString)) setViewTitle("Edit", fmt.Sprintf(" Editing message %d ", messageID)) + moveCursorToEnd("Edit") return } if len(cmd) < 3 { diff --git a/main.go b/main.go index cea2ab1..96f787d 100644 --- a/main.go +++ b/main.go @@ -202,6 +202,22 @@ func popupView(viewName string) { }) } +func moveCursorToEnd(viewName string) { + g.Update(func(g *gocui.Gui) error { + inputView, err := g.View(viewName) + if err != nil { + return err + } + inputString, _ := getInputString(viewName) + stringLen := len(inputString) + maxX, _ := inputView.Size() + x := stringLen % maxX + y := stringLen / maxX + inputView.MoveCursor(x, y, true) + return nil + + }) +} func clearView(viewName string) { g.Update(func(g *gocui.Gui) error { inputView, err := g.View(viewName) From acf822e5a15813a9a60cb4e84b22096b0b0a2336 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 09:42:11 -0400 Subject: [PATCH 15/19] Add origin to moveCursorToEnd() --- main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.go b/main.go index 96f787d..0e2f84d 100644 --- a/main.go +++ b/main.go @@ -213,6 +213,8 @@ func moveCursorToEnd(viewName string) { maxX, _ := inputView.Size() x := stringLen % maxX y := stringLen / maxX + inputView.SetCursor(0, 0) + inputView.SetOrigin(0, 0) inputView.MoveCursor(x, y, true) return nil From 20a687208a9d9562a26d19f6c6258d8e6d4670d8 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 13:44:49 -0400 Subject: [PATCH 16/19] Linting tabComplete for future Travis checks --- tabComplete.go | 99 +++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/tabComplete.go b/tabComplete.go index 4aaabd7..2c90f88 100644 --- a/tabComplete.go +++ b/tabComplete.go @@ -20,46 +20,46 @@ func handleTab(viewName string) error { inputString, err := getInputString(viewName) if err != nil { return err + } + // if you successfully get an input string, grab the last word from the string + ss := regexp.MustCompile(`[ #]`).Split(inputString, -1) + s := ss[len(ss)-1] + // create a variable in which to store the result + var resultSlice []string + // if the word starts with a : its an emoji lookup + if strings.HasPrefix(s, ":") { + resultSlice = getEmojiTabCompletionSlice(s) + } else if strings.HasPrefix(s, "/") { + generateCommandTabCompletionSlice() + s = strings.Replace(s, "/", "", 1) + resultSlice = getCommandTabCompletionSlice(s) } else { - // if you successfully get an input string, grab the last word from the string - ss := regexp.MustCompile(`[ #]`).Split(inputString, -1) - s := ss[len(ss)-1] - // create a variable in which to store the result - var resultSlice []string - // if the word starts with a : its an emoji lookup - if strings.HasPrefix(s, ":") { - resultSlice = getEmojiTabCompletionSlice(s) - } else if strings.HasPrefix(s, "/") { - generateCommandTabCompletionSlice() - s = strings.Replace(s, "/", "", 1) - resultSlice = getCommandTabCompletionSlice(s) - } else { - if strings.HasPrefix(s, "@") { - // now in case the word (s) is a mention @something, lets remove it to normalize - s = strings.Replace(s, "@", "", 1) - } - // now call get the list of all possible cantidates that have that as a prefix - resultSlice = getChannelTabCompletionSlice(s) + if strings.HasPrefix(s, "@") { + // now in case the word (s) is a mention @something, lets remove it to normalize + s = strings.Replace(s, "@", "", 1) } - rLen := len(resultSlice) - lcp := longestCommonPrefix(resultSlice) - if lcp != "" { - originalViewTitle := getViewTitle("Input") - newViewTitle := "" - if rLen >= 1 && originalViewTitle != "" { - if rLen == 1 { - newViewTitle = originalViewTitle - } else if rLen <= 5 { - newViewTitle = fmt.Sprintf("%s|| %s", originalViewTitle, strings.Join(resultSlice, " ")) - } else if rLen > 5 { - newViewTitle = fmt.Sprintf("%s|| %s +%d more", originalViewTitle, strings.Join(resultSlice[:6], " "), rLen-5) - } - setViewTitle(viewName, newViewTitle) - remainder := stringRemainder(s, lcp) - writeToView(viewName, remainder) + // now call get the list of all possible cantidates that have that as a prefix + resultSlice = getChannelTabCompletionSlice(s) + } + rLen := len(resultSlice) + lcp := longestCommonPrefix(resultSlice) + if lcp != "" { + originalViewTitle := getViewTitle("Input") + newViewTitle := "" + if rLen >= 1 && originalViewTitle != "" { + if rLen == 1 { + newViewTitle = originalViewTitle + } else if rLen <= 5 { + newViewTitle = fmt.Sprintf("%s|| %s", originalViewTitle, strings.Join(resultSlice, " ")) + } else if rLen > 5 { + newViewTitle = fmt.Sprintf("%s|| %s +%d more", originalViewTitle, strings.Join(resultSlice[:6], " "), rLen-5) } + setViewTitle(viewName, newViewTitle) + remainder := stringRemainder(s, lcp) + writeToView(viewName, remainder) } } + return nil } @@ -123,22 +123,23 @@ func getCurrentChannelMembership() []string { var rs []string if channel.Name != "" { t := k.NewTeam(channel.Name) - if testVar, err := t.MemberList(); err != nil { + testVar, err := t.MemberList() + if err != nil { return rs // then this isn't a team, its a PM or there was an error in the API call - } else { - for _, m := range testVar.Result.Members.Owners { - rs = append(rs, fmt.Sprintf("%+v", m.Username)) - } - for _, m := range testVar.Result.Members.Admins { - rs = append(rs, fmt.Sprintf("%+v", m.Username)) - } - for _, m := range testVar.Result.Members.Writers { - rs = append(rs, fmt.Sprintf("%+v", m.Username)) - } - for _, m := range testVar.Result.Members.Readers { - rs = append(rs, fmt.Sprintf("%+v", m.Username)) - } } + for _, m := range testVar.Result.Members.Owners { + rs = append(rs, fmt.Sprintf("%+v", m.Username)) + } + for _, m := range testVar.Result.Members.Admins { + rs = append(rs, fmt.Sprintf("%+v", m.Username)) + } + for _, m := range testVar.Result.Members.Writers { + rs = append(rs, fmt.Sprintf("%+v", m.Username)) + } + for _, m := range testVar.Result.Members.Readers { + rs = append(rs, fmt.Sprintf("%+v", m.Username)) + } + } return rs } From 44310d09f527a48b59a86daf014f782901ae529c Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Tue, 22 Oct 2019 13:59:19 -0400 Subject: [PATCH 17/19] Update README.md Remove external dependency (keeping mage) as well as updating why Mage is required. --- README.md | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d814c18..1b0dd55 100644 --- a/README.md +++ b/README.md @@ -31,16 +31,9 @@ go get -u github.com/rudi9719/kbtui ``` Or you can do the following: ``` -go get ./... -go run build.go +go get github.com/magefile/mage/mage go run build.go {build, buildBeta... etc} ./kbtui ``` - -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](https://keybase.io/dxb) updates his API it will be necessary to run -`go get -u ./...` or `go get -u samhofi.us/x/keybase` +Mage is a requirement for building `kbtui` as it will automatically handle/manage imports as well as mage is used to generate the +file for emoji completion. From f04bf8e54597d39061a6abe668ad4939a386f4db Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 23 Oct 2019 10:11:15 -0400 Subject: [PATCH 18/19] Bugfix: Load displayed an error because of missing return statement --- cmdSet.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmdSet.go b/cmdSet.go index 68a2d39..83e225c 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -23,7 +23,6 @@ func printSetting(cmd []string) { switch cmd[1] { case "load": loadFromToml() - printToView("Feed", fmt.Sprintf("Loading config from toml")) case "downloadPath": printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath)) case "outputFormat": @@ -47,6 +46,7 @@ func cmdSet(cmd []string) { } if len(cmd) < 3 { printSetting(cmd) + return } switch cmd[1] { case "downloadPath": @@ -68,6 +68,7 @@ func cmdSet(cmd []string) { } func loadFromToml() { + printToView("Feed", fmt.Sprintf("Loading config from toml")) config, err := toml.LoadFile("kbtui.tml") if err != nil { printToView("Feed", fmt.Sprintf("Could not read config file: %+v", err)) From 3f33070635b1ca1d6ce9188eaaf077a04fc501d2 Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Wed, 23 Oct 2019 10:31:43 -0400 Subject: [PATCH 19/19] Automatically run clean when configs are loaded from file --- cmdClean.go | 3 ++- cmdSet.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmdClean.go b/cmdClean.go index aeb2eed..21e2853 100644 --- a/cmdClean.go +++ b/cmdClean.go @@ -15,6 +15,7 @@ func init() { func cmdClean(cmd []string) { clearView("Chat") + clearView("List") go populateChat() - + go populateList() } diff --git a/cmdSet.go b/cmdSet.go index 83e225c..bd5e17a 100644 --- a/cmdSet.go +++ b/cmdSet.go @@ -92,4 +92,5 @@ func loadFromToml() { if config.Has("Formatting.timeFormat") { timeFormat = config.Get("Formatting.timeFormat").(string) } + RunCommand("clean") }