mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 08:47:24 +00:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
@ -3,7 +3,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ func cmdDelete(cmd []string) {
|
|||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
_, err := chat.Delete(messageID)
|
_, err := chat.Delete(messageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error deleting your message."))
|
printError("There was an error deleting your message.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,22 +21,22 @@ func init() {
|
|||||||
func cmdDownloadFile(cmd []string) {
|
func cmdDownloadFile(cmd []string) {
|
||||||
|
|
||||||
if len(cmd) < 2 {
|
if len(cmd) < 2 {
|
||||||
printToView("Feed", fmt.Sprintf("%s%s $messageId $fileName - Download a file to user's downloadpath", cmdPrefix, cmd[0]))
|
printInfo(fmt.Sprintf("%s%s $messageId $fileName - Download a file to user's downloadpath", cmdPrefix, cmd[0]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messageID, err := strconv.Atoi(cmd[1])
|
messageID, err := strconv.Atoi(cmd[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", "There was an error converting your messageID to an int")
|
printError("There was an error converting your messageID to an int")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
api, err := chat.ReadMessage(messageID)
|
api, err := chat.ReadMessage(messageID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error pulling message %d", messageID))
|
printError(fmt.Sprintf("There was an error pulling message %d", messageID))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if api.Result.Messages[0].Msg.Content.Type != "attachment" {
|
if api.Result.Messages[0].Msg.Content.Type != "attachment" {
|
||||||
printToView("Feed", "No attachment detected")
|
printError("No attachment detected")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var fileName string
|
var fileName string
|
||||||
@ -47,9 +47,10 @@ func cmdDownloadFile(cmd []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, err = chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName))
|
_, err = chat.Download(messageID, fmt.Sprintf("%s/%s", downloadPath, fileName))
|
||||||
|
channelName := messageLinkKeybaseColor.stylize(channel.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error downloading %s from %s", fileName, channel.Name))
|
printErrorF(fmt.Sprintf("There was an error downloading %s from $TEXT", fileName), channelName)
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", fmt.Sprintf("Downloaded %s from %s", fileName, channel.Name))
|
printInfoF(fmt.Sprintf("Downloaded %s from $TEXT", fileName), channelName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
cmdEdit.go
14
cmdEdit.go
@ -26,22 +26,24 @@ func cmdEdit(cmd []string) {
|
|||||||
if len(cmd) == 2 {
|
if len(cmd) == 2 {
|
||||||
messageID, _ = strconv.Atoi(cmd[1])
|
messageID, _ = strconv.Atoi(cmd[1])
|
||||||
} else if lastMessage.ID != 0 {
|
} else if lastMessage.ID != 0 {
|
||||||
|
message, _ := chat.ReadMessage(lastMessage.ID)
|
||||||
|
lastMessage.Type = message.Result.Messages[0].Msg.Content.Type
|
||||||
if lastMessage.Type != "text" {
|
if lastMessage.Type != "text" {
|
||||||
printToView("Feed", "Last message isn't editable (is it an edit?)")
|
printError("Last message isn't editable (is it an edit?)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messageID = lastMessage.ID
|
messageID = lastMessage.ID
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", "No message to edit")
|
printError("No message to edit")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
origMessage, _ := chat.ReadMessage(messageID)
|
origMessage, _ := chat.ReadMessage(messageID)
|
||||||
if origMessage.Result.Messages[0].Msg.Content.Type != "text" {
|
if origMessage.Result.Messages[0].Msg.Content.Type != "text" {
|
||||||
printToView("Feed", fmt.Sprintf("%+v", origMessage))
|
printInfo(fmt.Sprintf("%+v", origMessage))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if origMessage.Result.Messages[0].Msg.Sender.Username != k.Username {
|
if origMessage.Result.Messages[0].Msg.Sender.Username != k.Username {
|
||||||
printToView("Feed", "You cannot edit another user's messages.")
|
printError("You cannot edit another user's messages.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
editString := origMessage.Result.Messages[0].Msg.Content.Text.Body
|
editString := origMessage.Result.Messages[0].Msg.Content.Text.Body
|
||||||
@ -53,14 +55,14 @@ func cmdEdit(cmd []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(cmd) < 3 {
|
if len(cmd) < 3 {
|
||||||
printToView("Feed", "Not enough options for Edit")
|
printError("Not enough options for Edit")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messageID, _ = strconv.Atoi(cmd[1])
|
messageID, _ = strconv.Atoi(cmd[1])
|
||||||
newMessage := strings.Join(cmd[2:], " ")
|
newMessage := strings.Join(cmd[2:], " ")
|
||||||
_, err := chat.Edit(messageID, newMessage)
|
_, err := chat.Edit(messageID, newMessage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("Error editing message %d, %+v", messageID, err))
|
printError(fmt.Sprintf("Error editing message %d, %+v", messageID, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,12 +41,12 @@ func cmdJoin(cmd []string) {
|
|||||||
channel.TopicName = ""
|
channel.TopicName = ""
|
||||||
channel.MembersType = keybase.USER
|
channel.MembersType = keybase.USER
|
||||||
}
|
}
|
||||||
printToView("Feed", fmt.Sprintf("You are joining: %s", joinedName))
|
printInfoF("You are joining: $TEXT", messageLinkKeybaseColor.stylize(joinedName))
|
||||||
clearView("Chat")
|
clearView("Chat")
|
||||||
setViewTitle("Input", fmt.Sprintf(" %s ", joinedName))
|
setViewTitle("Input", fmt.Sprintf(" %s ", joinedName))
|
||||||
go populateChat()
|
go populateChat()
|
||||||
default:
|
default:
|
||||||
printToView("Feed", fmt.Sprintf("To join a team use %sjoin <team> <channel>", cmdPrefix))
|
printInfo(fmt.Sprintf("To join a team use %sjoin <team> <channel>", cmdPrefix))
|
||||||
printToView("Feed", fmt.Sprintf("To join a PM use %sjoin <user>", cmdPrefix))
|
printInfo(fmt.Sprintf("To join a PM use %sjoin <user>", cmdPrefix))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,8 +29,8 @@ func cmdPost(cmd []string) {
|
|||||||
chat := k.NewChat(pubChan)
|
chat := k.NewChat(pubChan)
|
||||||
_, err := chat.Send(post)
|
_, err := chat.Send(post)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error with your post: %+v", err))
|
printError(fmt.Sprintf("There was an error with your post: %+v", err))
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", "You have publically posted to your wall, signed by your current device.")
|
printInfo("You have publically posted to your wall, signed by your current device.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,6 +38,6 @@ func doReact(messageID int, reaction string) {
|
|||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
_, err := chat.React(messageID, reaction)
|
_, err := chat.React(messageID, reaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", "There was an error reacting to the message.")
|
printError("There was an error reacting to the message.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,18 +22,17 @@ func init() {
|
|||||||
func cmdReply(cmd []string) {
|
func cmdReply(cmd []string) {
|
||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
if len(cmd) < 2 {
|
if len(cmd) < 2 {
|
||||||
printToView("Feed", fmt.Sprintf("%s%s $ID - Reply to message $ID", cmdPrefix, cmd[0]))
|
printInfo(fmt.Sprintf("%s%s $ID - Reply to message $ID", cmdPrefix, cmd[0]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
messageID, err := strconv.Atoi(cmd[1])
|
messageID, err := strconv.Atoi(cmd[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error determining message ID %s", cmd[1]))
|
printError(fmt.Sprintf("There was an error determining message ID %s", cmd[1]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = chat.Reply(messageID, strings.Join(cmd[2:], " "))
|
_, err = chat.Reply(messageID, strings.Join(cmd[2:], " "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", "There was an error with your reply.")
|
printError("There was an error with your reply.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
57
cmdSet.go
57
cmdSet.go
@ -4,6 +4,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
@ -24,24 +25,22 @@ func printSetting(cmd []string) {
|
|||||||
case "load":
|
case "load":
|
||||||
loadFromToml()
|
loadFromToml()
|
||||||
case "downloadPath":
|
case "downloadPath":
|
||||||
printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath))
|
printInfo(fmt.Sprintf("Setting for %s -> %s", cmd[1], downloadPath))
|
||||||
case "outputFormat":
|
case "outputFormat":
|
||||||
printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], outputFormat))
|
printInfo(fmt.Sprintf("Setting for %s -> %s", cmd[1], outputFormat))
|
||||||
case "dateFormat":
|
case "dateFormat":
|
||||||
printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], dateFormat))
|
printInfo(fmt.Sprintf("Setting for %s -> %s", cmd[1], dateFormat))
|
||||||
case "timeFormat":
|
case "timeFormat":
|
||||||
printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], timeFormat))
|
printInfo(fmt.Sprintf("Setting for %s -> %s", cmd[1], timeFormat))
|
||||||
case "cmdPrefix":
|
case "cmdPrefix":
|
||||||
printToView("Feed", fmt.Sprintf("Setting for %s -> %s", cmd[1], cmdPrefix))
|
printInfo(fmt.Sprintf("Setting for %s -> %s", cmd[1], cmdPrefix))
|
||||||
default:
|
default:
|
||||||
printToView("Feed", fmt.Sprintf("Unknown config value %s", cmd[1]))
|
printError(fmt.Sprintf("Unknown config value %s", cmd[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func cmdSet(cmd []string) {
|
func cmdSet(cmd []string) {
|
||||||
if len(cmd) < 2 {
|
if len(cmd) < 2 {
|
||||||
printToView("Feed", "No config value specified")
|
printError("No config value specified")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(cmd) < 3 {
|
if len(cmd) < 3 {
|
||||||
@ -51,7 +50,7 @@ func cmdSet(cmd []string) {
|
|||||||
switch cmd[1] {
|
switch cmd[1] {
|
||||||
case "downloadPath":
|
case "downloadPath":
|
||||||
if len(cmd) != 3 {
|
if len(cmd) != 3 {
|
||||||
printToView("Feed", "Invalid download path.")
|
printError("Invalid download path.")
|
||||||
}
|
}
|
||||||
downloadPath = cmd[2]
|
downloadPath = cmd[2]
|
||||||
case "outputFormat":
|
case "outputFormat":
|
||||||
@ -63,17 +62,26 @@ func cmdSet(cmd []string) {
|
|||||||
case "cmdPrefix":
|
case "cmdPrefix":
|
||||||
cmdPrefix = cmd[2]
|
cmdPrefix = cmd[2]
|
||||||
default:
|
default:
|
||||||
printToView("Feed", fmt.Sprintf("Unknown config value %s", cmd[1]))
|
printError(fmt.Sprintf("Unknown config value %s", cmd[1]))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
func loadFromToml() {
|
func loadFromToml() {
|
||||||
printToView("Feed", fmt.Sprintf("Loading config from toml"))
|
configFile, env := os.LookupEnv("KBTUI_CFG")
|
||||||
config, err := toml.LoadFile("kbtui.tml")
|
if !env {
|
||||||
|
configFile = "~/.config/kbtui.toml"
|
||||||
|
if _, err := os.Stat(configFile); os.IsNotExist(err) {
|
||||||
|
configFile = "kbtui.toml"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
printInfoF("Loading config from toml: $TEXT", messageAttachmentColor.stylize(configFile))
|
||||||
|
config, err := toml.LoadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("Could not read config file: %+v", err))
|
printError(fmt.Sprintf("Could not read config file: %+v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
colorless = config.GetDefault("Basics.colorless", false).(bool)
|
||||||
if config.Has("Basics.colorless") {
|
if config.Has("Basics.colorless") {
|
||||||
colorless = config.Get("Basics.colorless").(bool)
|
colorless = config.Get("Basics.colorless").(bool)
|
||||||
}
|
}
|
||||||
@ -92,5 +100,26 @@ func loadFromToml() {
|
|||||||
if config.Has("Formatting.timeFormat") {
|
if config.Has("Formatting.timeFormat") {
|
||||||
timeFormat = config.Get("Formatting.timeFormat").(string)
|
timeFormat = config.Get("Formatting.timeFormat").(string)
|
||||||
}
|
}
|
||||||
|
channelsColor = styleFromConfig(config, "channels.basic")
|
||||||
|
|
||||||
|
channelsHeaderColor = styleFromConfig(config, "channels.header")
|
||||||
|
channelUnreadColor = styleFromConfig(config, "channels.unread")
|
||||||
|
|
||||||
|
mentionColor = styleFromConfig(config, "message.mention")
|
||||||
|
messageHeaderColor = styleFromConfig(config, "message.header")
|
||||||
|
messageIDColor = styleFromConfig(config, "message.id")
|
||||||
|
messageTimeColor = styleFromConfig(config, "message.time")
|
||||||
|
messageSenderDefaultColor = styleFromConfig(config, "message.sender_default")
|
||||||
|
messageSenderDeviceColor = styleFromConfig(config, "message.sender_device")
|
||||||
|
messageBodyColor = styleFromConfig(config, "message.body")
|
||||||
|
messageAttachmentColor = styleFromConfig(config, "message.attachment")
|
||||||
|
messageLinkURLColor = styleFromConfig(config, "message.link_url")
|
||||||
|
messageLinkKeybaseColor = styleFromConfig(config, "message.link_keybase")
|
||||||
|
messageReactionColor = styleFromConfig(config, "message.reaction")
|
||||||
|
messageCodeColor = styleFromConfig(config, "message.code")
|
||||||
|
|
||||||
|
feedColor = styleFromConfig(config, "feed.basic")
|
||||||
|
errorColor = styleFromConfig(config, "feed.error")
|
||||||
|
|
||||||
RunCommand("clean")
|
RunCommand("clean")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
command := Command{
|
command := Command{
|
||||||
Cmd: []string{"stream", "s"},
|
Cmd: []string{"stream", "s"},
|
||||||
@ -17,7 +21,7 @@ func cmdStream(cmd []string) {
|
|||||||
stream = true
|
stream = true
|
||||||
channel.Name = ""
|
channel.Name = ""
|
||||||
|
|
||||||
printToView("Feed", "You are now viewing the formatted stream")
|
printInfo("You are now viewing the formatted stream")
|
||||||
setViewTitle("Input", " Stream - Not in a chat /j to join ")
|
setViewTitle("Input", fmt.Sprintf(" Stream - Not in a chat. %sj to join ", cmdPrefix))
|
||||||
clearView("Chat")
|
clearView("Chat")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,14 +21,14 @@ func init() {
|
|||||||
|
|
||||||
func cmdUploadFile(cmd []string) {
|
func cmdUploadFile(cmd []string) {
|
||||||
if len(cmd) < 2 {
|
if len(cmd) < 2 {
|
||||||
printToView("Feed", fmt.Sprintf("%s%s $filePath $fileName - Upload file from absolute path with optional name", cmdPrefix, cmd[0]))
|
printInfo(fmt.Sprintf("%s%s $filePath $fileName - Upload file from absolute path with optional name", cmdPrefix, cmd[0]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filePath := cmd[1]
|
filePath := cmd[1]
|
||||||
if !strings.HasPrefix(filePath, "/") {
|
if !strings.HasPrefix(filePath, "/") {
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error determining path %+v", err))
|
printError(fmt.Sprintf("There was an error determining path %+v", err))
|
||||||
}
|
}
|
||||||
filePath = fmt.Sprintf("%s/%s", dir, filePath)
|
filePath = fmt.Sprintf("%s/%s", dir, filePath)
|
||||||
}
|
}
|
||||||
@ -40,9 +40,10 @@ func cmdUploadFile(cmd []string) {
|
|||||||
}
|
}
|
||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
_, err := chat.Upload(fileName, filePath)
|
_, err := chat.Upload(fileName, filePath)
|
||||||
|
channelName := messageLinkKeybaseColor.stylize(channel.Name).string()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error uploading %s to %s\n%+v", filePath, channel.Name, err))
|
printError(fmt.Sprintf("There was an error uploading %s to %s\n%+v", filePath, channelName, err))
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", fmt.Sprintf("Uploaded %s to %s", filePath, channel.Name))
|
printInfo(fmt.Sprintf("Uploaded %s to %s", filePath, channelName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,13 +64,14 @@ func cmdPopulateWall(cmd []string) {
|
|||||||
if len(users) < 1 {
|
if len(users) < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
printToView("Feed", fmt.Sprintf("Displaying public messages for user %s", requestedUsers))
|
|
||||||
|
printInfoF("Displaying public messages for user $TEXT", messageLinkKeybaseColor.stylize(requestedUsers))
|
||||||
for _, chann := range users {
|
for _, chann := range users {
|
||||||
chat := k.NewChat(chann)
|
chat := k.NewChat(chann)
|
||||||
api, err := chat.Read()
|
api, err := chat.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if len(users) < 6 {
|
if len(users) < 6 {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error for user %s: %+v", cleanChannelName(chann.Name), err))
|
printError(fmt.Sprintf("There was an error for user %s: %+v", cleanChannelName(chann.Name), err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -42,20 +42,20 @@ func cmdWallet(cmd []string) {
|
|||||||
walletConfirmationCode = b.String()
|
walletConfirmationCode = b.String()
|
||||||
walletConfirmationUser = cmd[1]
|
walletConfirmationUser = cmd[1]
|
||||||
walletTransactionAmnt = cmd[2]
|
walletTransactionAmnt = cmd[2]
|
||||||
printToView("Feed", fmt.Sprintf("To confirm sending %s to %s, type /confirm %s %s", cmd[2], cmd[1], cmd[1], walletConfirmationCode))
|
printInfo(fmt.Sprintf("To confirm sending %s to %s, type /confirm %s %s", cmd[2], cmd[1], cmd[1], walletConfirmationCode))
|
||||||
|
|
||||||
} else if cmd[0] == "confirm" {
|
} else if cmd[0] == "confirm" {
|
||||||
if cmd[1] == walletConfirmationUser && cmd[2] == walletConfirmationCode {
|
if cmd[1] == walletConfirmationUser && cmd[2] == walletConfirmationCode {
|
||||||
txWallet := k.NewWallet()
|
txWallet := k.NewWallet()
|
||||||
wAPI, err := txWallet.SendXLM(walletConfirmationUser, walletTransactionAmnt, "")
|
wAPI, err := txWallet.SendXLM(walletConfirmationUser, walletTransactionAmnt, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error with your wallet tx:\n\t%+v", err))
|
printError(fmt.Sprintf("There was an error with your wallet tx:\n\t%+v", err))
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", fmt.Sprintf("You have sent %sXLM to %s with tx ID: %s", wAPI.Result.Amount, wAPI.Result.ToUsername, wAPI.Result.TxID))
|
printInfo(fmt.Sprintf("You have sent %sXLM to %s with tx ID: %s", wAPI.Result.Amount, wAPI.Result.ToUsername, wAPI.Result.TxID))
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", "There was an error validating your confirmation. Your wallet has been untouched.")
|
printError("There was an error validating your confirmation. Your wallet has been untouched.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
245
colors.go
245
colors.go
@ -2,42 +2,231 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelletier/go-toml"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO maybe datastructure
|
// Begin Colors
|
||||||
// BASH-like PS1 variable equivalent (without colours)
|
type color int
|
||||||
// TODO bold? cursive etc?
|
|
||||||
func color(c int) string {
|
const (
|
||||||
|
black color = iota
|
||||||
|
red
|
||||||
|
green
|
||||||
|
yellow
|
||||||
|
purple
|
||||||
|
magenta
|
||||||
|
cyan
|
||||||
|
grey
|
||||||
|
normal color = -1
|
||||||
|
)
|
||||||
|
|
||||||
|
func colorFromString(s string) color {
|
||||||
|
s = strings.ToLower(s)
|
||||||
|
switch s {
|
||||||
|
case "black":
|
||||||
|
return black
|
||||||
|
case "red":
|
||||||
|
return red
|
||||||
|
case "green":
|
||||||
|
return green
|
||||||
|
case "yellow":
|
||||||
|
return yellow
|
||||||
|
case "purple":
|
||||||
|
return purple
|
||||||
|
case "magenta":
|
||||||
|
return magenta
|
||||||
|
case "cyan":
|
||||||
|
return cyan
|
||||||
|
case "grey":
|
||||||
|
return grey
|
||||||
|
case "normal":
|
||||||
|
return normal
|
||||||
|
default:
|
||||||
|
printError(fmt.Sprintf("color `%s` cannot be parsed.", s))
|
||||||
|
}
|
||||||
|
return normal
|
||||||
|
}
|
||||||
|
|
||||||
|
// Style struct for specializing the style/color of a stylize
|
||||||
|
type Style struct {
|
||||||
|
foregroundColor color
|
||||||
|
backgroundColor color
|
||||||
|
bold bool
|
||||||
|
italic bool // Currently not supported by the UI library
|
||||||
|
underline bool
|
||||||
|
strikethrough bool // Currently not supported by the UI library
|
||||||
|
inverse bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var basicStyle = Style{normal, normal, false, false, false, false, false}
|
||||||
|
|
||||||
|
func styleFromConfig(config *toml.Tree, key string) Style {
|
||||||
|
key = "Colors." + key + "."
|
||||||
|
style := basicStyle
|
||||||
|
if config.Has(key + "foreground") {
|
||||||
|
style = style.withForeground(colorFromString(config.Get(key + "foreground").(string)))
|
||||||
|
}
|
||||||
|
if config.Has(key + "background") {
|
||||||
|
style = style.withForeground(colorFromString(config.Get(key + "background").(string)))
|
||||||
|
}
|
||||||
|
if config.GetDefault(key+"bold", false).(bool) {
|
||||||
|
style = style.withBold()
|
||||||
|
}
|
||||||
|
if config.GetDefault(key+"italic", false).(bool) {
|
||||||
|
style = style.withItalic()
|
||||||
|
}
|
||||||
|
if config.GetDefault(key+"underline", false).(bool) {
|
||||||
|
style = style.withUnderline()
|
||||||
|
}
|
||||||
|
if config.GetDefault(key+"strikethrough", false).(bool) {
|
||||||
|
style = style.withStrikethrough()
|
||||||
|
}
|
||||||
|
if config.GetDefault(key+"inverse", false).(bool) {
|
||||||
|
style = style.withInverse()
|
||||||
|
}
|
||||||
|
|
||||||
|
return style
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) withForeground(f color) Style {
|
||||||
|
s.foregroundColor = f
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withBackground(f color) Style {
|
||||||
|
s.backgroundColor = f
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withBold() Style {
|
||||||
|
s.bold = true
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withInverse() Style {
|
||||||
|
s.inverse = true
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withItalic() Style {
|
||||||
|
s.italic = true
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withStrikethrough() Style {
|
||||||
|
s.strikethrough = true
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func (s Style) withUnderline() Style {
|
||||||
|
s.underline = true
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO create both as `reset` (which it is now) as well as `append`
|
||||||
|
// which essentially just adds on top. that is relevant in the case of
|
||||||
|
// bold/italic etc - it should add style - not clear.
|
||||||
|
func (s Style) toANSI() string {
|
||||||
if colorless {
|
if colorless {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if c < 0 {
|
output := "\x1b[0m\x1b[0"
|
||||||
return "\033[0m"
|
if s.foregroundColor != normal {
|
||||||
} else {
|
output += fmt.Sprintf(";%d", 30+s.foregroundColor)
|
||||||
return fmt.Sprintf("\033[0;%dm", 29+c)
|
|
||||||
}
|
}
|
||||||
}
|
if s.backgroundColor != normal {
|
||||||
|
output += fmt.Sprintf(";%d", 40+s.backgroundColor)
|
||||||
// TODO maybe make the text into some datastructure which remembers the color
|
|
||||||
func colorText(text string, color string, offColor string) string {
|
|
||||||
return fmt.Sprintf("%s%s%s", color, text, offColor)
|
|
||||||
}
|
|
||||||
|
|
||||||
func colorUsername(username string, offColor string) string {
|
|
||||||
var color = messageSenderDefaultColor
|
|
||||||
if username == k.Username {
|
|
||||||
color = mentionColor
|
|
||||||
}
|
}
|
||||||
return colorText(username, color, offColor)
|
if s.bold {
|
||||||
}
|
output += ";1"
|
||||||
func colorRegex(msg string, match string, color string, offColor string) string {
|
}
|
||||||
var re = regexp.MustCompile(match)
|
if s.italic {
|
||||||
return re.ReplaceAllString(msg, colorText(`$1`, color, offColor))
|
output += ";3"
|
||||||
|
}
|
||||||
|
if s.underline {
|
||||||
|
output += ";4"
|
||||||
|
}
|
||||||
|
if s.inverse {
|
||||||
|
output += ";7"
|
||||||
|
}
|
||||||
|
if s.strikethrough {
|
||||||
|
output += ";9"
|
||||||
|
}
|
||||||
|
|
||||||
|
return output + "m"
|
||||||
}
|
}
|
||||||
|
|
||||||
func colorReplaceMentionMe(msg string, offColor string) string {
|
// End Colors
|
||||||
//var coloredOwnName = colorText(k.Username, mentionColor, offColor)
|
// Begin StyledString
|
||||||
//return strings.Replace(msg, k.Username, coloredOwnName, -1)
|
|
||||||
return colorRegex(msg, "(@?"+k.Username+")", mentionColor, offColor)
|
// StyledString is used to save a message with a style, which can then later be rendered to a string
|
||||||
|
type StyledString struct {
|
||||||
|
message string
|
||||||
|
style Style
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO handle all formatting types
|
||||||
|
func (s Style) sprintf(base string, parts ...StyledString) StyledString {
|
||||||
|
text := s.stylize(removeFormatting(base))
|
||||||
|
//TODO handle posibility to escape
|
||||||
|
re := regexp.MustCompile(`\$TEXT`)
|
||||||
|
for len(re.FindAllString(text.message, 1)) > 0 {
|
||||||
|
part := parts[0]
|
||||||
|
parts = parts[1:]
|
||||||
|
text = text.replaceN("$TEXT", part, 1)
|
||||||
|
}
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Style) stylize(msg string) StyledString {
|
||||||
|
return StyledString{msg, s}
|
||||||
|
}
|
||||||
|
func (t StyledString) stringFollowedByStyle(style Style) string {
|
||||||
|
return t.style.toANSI() + t.message + style.toANSI()
|
||||||
|
}
|
||||||
|
func (t StyledString) string() string {
|
||||||
|
return t.stringFollowedByStyle(basicStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t StyledString) replace(match string, value StyledString) StyledString {
|
||||||
|
return t.replaceN(match, value, -1)
|
||||||
|
}
|
||||||
|
func (t StyledString) replaceN(match string, value StyledString, n int) StyledString {
|
||||||
|
t.message = strings.Replace(t.message, match, value.stringFollowedByStyle(t.style), n)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
func (t StyledString) replaceString(match string, value string) StyledString {
|
||||||
|
t.message = strings.Replace(t.message, match, value, -1)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overrides current formatting
|
||||||
|
func (t StyledString) colorRegex(match string, style Style) StyledString {
|
||||||
|
re := regexp.MustCompile("(" + match + ")")
|
||||||
|
locations := re.FindAllStringIndex(t.message, -1)
|
||||||
|
var newMessage string
|
||||||
|
var prevIndex int
|
||||||
|
for _, loc := range locations {
|
||||||
|
cleanSubstring := style.stylize(removeFormatting(string(t.message[loc[0]:loc[1]])))
|
||||||
|
newMessage += t.message[prevIndex:loc[0]]
|
||||||
|
newMessage += cleanSubstring.stringFollowedByStyle(t.style)
|
||||||
|
prevIndex = loc[1]
|
||||||
|
}
|
||||||
|
// Append any string after the final match
|
||||||
|
newMessage += t.message[prevIndex:len(t.message)]
|
||||||
|
t.message = newMessage
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appends the other stylize at the end, but retains same style
|
||||||
|
func (t StyledString) append(other StyledString) StyledString {
|
||||||
|
t.message = t.message + other.stringFollowedByStyle(t.style)
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
func (t StyledString) appendString(other string) StyledString {
|
||||||
|
t.message += other
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
|
// Begin Formatting
|
||||||
|
|
||||||
|
func removeFormatting(s string) string {
|
||||||
|
reFormatting := regexp.MustCompile(`(?m)\x1b\[(\d*;?)*m`)
|
||||||
|
return reFormatting.ReplaceAllString(s, "")
|
||||||
}
|
}
|
||||||
|
|||||||
30
kbtui.tml
30
kbtui.tml
@ -1,30 +0,0 @@
|
|||||||
[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
|
|
||||||
63
kbtui.toml
Normal file
63
kbtui.toml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
[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]
|
||||||
|
[Colors.channels]
|
||||||
|
[Colors.channels.basic]
|
||||||
|
foreground = "normal"
|
||||||
|
[Colors.channels.header]
|
||||||
|
foreground = "magenta"
|
||||||
|
bold = true
|
||||||
|
[Colors.channels.unread]
|
||||||
|
foreground = "green"
|
||||||
|
italic = true
|
||||||
|
|
||||||
|
[Colors.message]
|
||||||
|
[Colors.message.body]
|
||||||
|
foreground = "normal"
|
||||||
|
[Colors.message.header]
|
||||||
|
foreground = "grey"
|
||||||
|
[Colors.message.mention]
|
||||||
|
foreground = "green"
|
||||||
|
italic = true
|
||||||
|
bold = true
|
||||||
|
[Colors.message.id]
|
||||||
|
foreground = "yellow"
|
||||||
|
[Colors.message.time]
|
||||||
|
foreground = "magenta"
|
||||||
|
[Colors.message.sender_default]
|
||||||
|
foreground = "cyan"
|
||||||
|
bold = true
|
||||||
|
[Colors.message.sender_device]
|
||||||
|
foreground = "cyan"
|
||||||
|
[Colors.message.attachment]
|
||||||
|
foreground = "red"
|
||||||
|
[Colors.message.link_url]
|
||||||
|
foreground = "yellow"
|
||||||
|
[Colors.message.link_keybase]
|
||||||
|
foreground = "yellow"
|
||||||
|
[Colors.message.reaction]
|
||||||
|
foreground = "magenta"
|
||||||
|
bold = true
|
||||||
|
[Colors.message.code]
|
||||||
|
foreground = "cyan"
|
||||||
|
background = "grey"
|
||||||
|
[Colors.feed]
|
||||||
|
[Colors.feed.basic]
|
||||||
|
foreground = "grey"
|
||||||
|
[Colors.feed.error]
|
||||||
|
foreground = "red"
|
||||||
161
main.go
161
main.go
@ -37,6 +37,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer g.Close()
|
defer g.Close()
|
||||||
g.SetManagerFunc(layout)
|
g.SetManagerFunc(layout)
|
||||||
|
go RunCommand("config", "load")
|
||||||
go populateList()
|
go populateList()
|
||||||
go updateChatWindow()
|
go updateChatWindow()
|
||||||
// use flag to parse command line arguments
|
// use flag to parse command line arguments
|
||||||
@ -70,7 +71,7 @@ func layout(g *gocui.Gui) error {
|
|||||||
feedView.Autoscroll = true
|
feedView.Autoscroll = true
|
||||||
feedView.Wrap = true
|
feedView.Wrap = true
|
||||||
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")
|
printInfo("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, 0); err2 != nil {
|
if chatView, err2 := g.SetView("Chat", maxX/2-maxX/3, maxY/5+1, maxX-1, maxY-5, 0); err2 != nil {
|
||||||
if !gocui.IsUnknownView(err2) {
|
if !gocui.IsUnknownView(err2) {
|
||||||
@ -78,7 +79,9 @@ func layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
chatView.Autoscroll = true
|
chatView.Autoscroll = true
|
||||||
chatView.Wrap = true
|
chatView.Wrap = true
|
||||||
fmt.Fprintf(chatView, "Welcome %s!\n\nYour chats will appear here.\nSupported commands are as follows:\n\n", k.Username)
|
welcomeText := basicStyle.stylize("Welcome $USER!\n\nYour chats will appear here.\nSupported commands are as follows:\n")
|
||||||
|
welcomeText = welcomeText.replace("$USER", mentionColor.stylize(k.Username))
|
||||||
|
fmt.Fprintln(chatView, welcomeText.string())
|
||||||
RunCommand("help")
|
RunCommand("help")
|
||||||
}
|
}
|
||||||
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1, 0); err3 != nil {
|
if inputView, err3 := g.SetView("Input", maxX/2-maxX/3, maxY-4, maxX-1, maxY-1, 0); err3 != nil {
|
||||||
@ -174,20 +177,19 @@ func getViewTitle(viewName string) string {
|
|||||||
view, err := g.View(viewName)
|
view, err := g.View(viewName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// in case there is active tab completion, filter that to just the view title and not the completion options.
|
// 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))
|
printError(fmt.Sprintf("Error getting view title: %s", err))
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return strings.Split(view.Title, "||")[0]
|
return strings.Split(view.Title, "||")[0]
|
||||||
|
|
||||||
}
|
}
|
||||||
func popupView(viewName string) {
|
func popupView(viewName string) {
|
||||||
_, err := g.SetCurrentView(viewName)
|
_, err := g.SetCurrentView(viewName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("%+v", err))
|
printError(fmt.Sprintf("%+v", err))
|
||||||
}
|
}
|
||||||
_, err = g.SetViewOnTop(viewName)
|
_, err = g.SetViewOnTop(viewName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("%+v", err))
|
printError(fmt.Sprintf("%+v", err))
|
||||||
}
|
}
|
||||||
g.Update(func(g *gocui.Gui) error {
|
g.Update(func(g *gocui.Gui) error {
|
||||||
updatingView, err := g.View(viewName)
|
updatingView, err := g.View(viewName)
|
||||||
@ -245,6 +247,24 @@ func writeToView(viewName string, message string) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this removes formatting
|
||||||
|
func printError(message string) {
|
||||||
|
printErrorF(message)
|
||||||
|
}
|
||||||
|
func printErrorF(message string, parts ...StyledString) {
|
||||||
|
printToView("Feed", errorColor.sprintf(removeFormatting(message), parts...).string())
|
||||||
|
}
|
||||||
|
|
||||||
|
// this removes formatting
|
||||||
|
func printInfo(message string) {
|
||||||
|
printInfoF(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// this removes formatting
|
||||||
|
func printInfoF(message string, parts ...StyledString) {
|
||||||
|
printToView("Feed", feedColor.sprintf(removeFormatting(message), parts...).string())
|
||||||
|
}
|
||||||
func printToView(viewName string, message string) {
|
func printToView(viewName string, message string) {
|
||||||
g.Update(func(g *gocui.Gui) error {
|
g.Update(func(g *gocui.Gui) error {
|
||||||
updatingView, err := g.View(viewName)
|
updatingView, err := g.View(viewName)
|
||||||
@ -289,13 +309,12 @@ func populateChat() {
|
|||||||
chat = k.NewChat(channel)
|
chat = k.NewChat(channel)
|
||||||
_, err2 := chat.Read(2)
|
_, err2 := chat.Read(2)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
printToView("Feed", fmt.Sprintf("%+v", err))
|
printError(fmt.Sprintf("%+v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go populateChat()
|
go populateChat()
|
||||||
go generateChannelTabCompletionSlice()
|
go generateChannelTabCompletionSlice()
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
var printMe []string
|
var printMe []string
|
||||||
var actuallyPrintMe string
|
var actuallyPrintMe string
|
||||||
@ -327,75 +346,122 @@ func populateList() {
|
|||||||
if testVar, err := k.ChatList(); err != nil {
|
if testVar, err := k.ChatList(); err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
clearView("List")
|
clearView("List")
|
||||||
var recentPMs = fmt.Sprintf("%s---[PMs]---%s\n", channelsHeaderColor, channelsColor)
|
var textBase = channelsColor.stylize("")
|
||||||
|
var recentPMs = textBase.append(channelsHeaderColor.stylize("---[PMs]---\n"))
|
||||||
var recentPMsCount = 0
|
var recentPMsCount = 0
|
||||||
var recentChannels = fmt.Sprintf("%s---[Teams]---%s\n", channelsHeaderColor, channelsColor)
|
var recentChannels = textBase.append(channelsHeaderColor.stylize("---[Teams]---\n"))
|
||||||
var recentChannelsCount = 0
|
var recentChannelsCount = 0
|
||||||
for _, s := range testVar.Result.Conversations {
|
for _, s := range testVar.Result.Conversations {
|
||||||
channels = append(channels, s.Channel)
|
channels = append(channels, s.Channel)
|
||||||
if s.Channel.MembersType == keybase.TEAM {
|
if s.Channel.MembersType == keybase.TEAM {
|
||||||
recentChannelsCount++
|
recentChannelsCount++
|
||||||
if recentChannelsCount <= ((maxY - 2) / 3) {
|
if recentChannelsCount <= ((maxY - 2) / 3) {
|
||||||
|
channel := fmt.Sprintf("%s\n\t#%s\n", s.Channel.Name, s.Channel.TopicName)
|
||||||
if s.Unread {
|
if s.Unread {
|
||||||
recentChannels += fmt.Sprintf("%s*", color(0))
|
recentChannels = recentChannels.append(channelUnreadColor.stylize("*" + channel))
|
||||||
|
} else {
|
||||||
|
recentChannels = recentChannels.appendString(channel)
|
||||||
}
|
}
|
||||||
recentChannels += fmt.Sprintf("%s\n\t#%s\n%s", s.Channel.Name, s.Channel.TopicName, channelsColor)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
recentPMsCount++
|
recentPMsCount++
|
||||||
if recentPMsCount <= ((maxY - 2) / 3) {
|
if recentPMsCount <= ((maxY - 2) / 3) {
|
||||||
|
pmName := fmt.Sprintf("%s\n", cleanChannelName(s.Channel.Name))
|
||||||
if s.Unread {
|
if s.Unread {
|
||||||
recentChannels += fmt.Sprintf("%s*", color(0))
|
recentPMs = recentPMs.append(channelUnreadColor.stylize("*" + pmName))
|
||||||
|
} else {
|
||||||
|
recentPMs = recentPMs.appendString(pmName)
|
||||||
}
|
}
|
||||||
recentPMs += fmt.Sprintf("%s\n%s", cleanChannelName(s.Channel.Name), channelsColor)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Millisecond)
|
time.Sleep(1 * time.Millisecond)
|
||||||
printToView("List", fmt.Sprintf("%s%s%s%s", channelsColor, recentPMs, recentChannels, noColor))
|
printToView("List", fmt.Sprintf("%s%s", recentPMs.string(), recentChannels.string()))
|
||||||
go generateRecentTabCompletionSlice()
|
generateRecentTabCompletionSlice()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// End update/populate views automatically
|
// End update/populate views automatically
|
||||||
|
|
||||||
// Formatting
|
// Formatting
|
||||||
|
func formatMessageBody(body string) StyledString {
|
||||||
|
output := messageBodyColor.stylize(body)
|
||||||
|
|
||||||
|
output = colorReplaceMentionMe(output)
|
||||||
|
output = output.colorRegex(`_[^_]*_`, messageBodyColor.withItalic())
|
||||||
|
output = output.colorRegex(`~[^~]*~`, messageBodyColor.withStrikethrough())
|
||||||
|
output = output.colorRegex(`@[\w_]*(\.[\w_]+)*`, messageLinkKeybaseColor)
|
||||||
|
// TODO change how bold, italic etc works, so it uses boldOn boldOff ([1m and [22m)
|
||||||
|
output = output.colorRegex(`\*[^\*]*\*`, messageBodyColor.withBold())
|
||||||
|
output = output.replaceString("```", "<code>")
|
||||||
|
// TODO make background color cover whole line
|
||||||
|
output = output.colorRegex("<code>(.*\n)*<code>", messageCodeColor)
|
||||||
|
output = output.colorRegex("`[^`]*`", messageCodeColor)
|
||||||
|
// mention URL
|
||||||
|
output = output.colorRegex(`(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*))`, messageLinkURLColor)
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO use this more
|
||||||
|
func formatChannel(ch keybase.Channel) StyledString {
|
||||||
|
return messageLinkKeybaseColor.stylize(fmt.Sprintf("@%s#%s", ch.Name, ch.TopicName))
|
||||||
|
}
|
||||||
|
|
||||||
|
func colorReplaceMentionMe(msg StyledString) StyledString {
|
||||||
|
return msg.colorRegex(`(@?\b`+k.Username+`\b)`, mentionColor)
|
||||||
|
}
|
||||||
|
func colorUsername(username string) StyledString {
|
||||||
|
var color = messageSenderDefaultColor
|
||||||
|
if username == k.Username {
|
||||||
|
color = mentionColor
|
||||||
|
}
|
||||||
|
return color.stylize(username)
|
||||||
|
}
|
||||||
|
|
||||||
func cleanChannelName(c string) string {
|
func cleanChannelName(c string) string {
|
||||||
newChannelName := strings.Replace(c, fmt.Sprintf("%s,", k.Username), "", 1)
|
newChannelName := strings.Replace(c, fmt.Sprintf("%s,", k.Username), "", 1)
|
||||||
return strings.Replace(newChannelName, fmt.Sprintf(",%s", k.Username), "", 1)
|
return strings.Replace(newChannelName, fmt.Sprintf(",%s", k.Username), "", 1)
|
||||||
}
|
}
|
||||||
func formatOutput(api keybase.ChatAPI) string {
|
|
||||||
ret := ""
|
func formatMessage(api keybase.ChatAPI, formatString string) string {
|
||||||
|
ret := messageHeaderColor.stylize("")
|
||||||
msgType := api.Msg.Content.Type
|
msgType := api.Msg.Content.Type
|
||||||
switch msgType {
|
switch msgType {
|
||||||
case "text", "attachment":
|
case "text", "attachment":
|
||||||
var c = messageHeaderColor
|
ret = messageHeaderColor.stylize(formatString)
|
||||||
ret = colorText(outputFormat, c, noColor)
|
|
||||||
tm := time.Unix(int64(api.Msg.SentAt), 0)
|
tm := time.Unix(int64(api.Msg.SentAt), 0)
|
||||||
var msg = api.Msg.Content.Text.Body
|
var msg = formatMessageBody(api.Msg.Content.Text.Body)
|
||||||
// mention teams or users
|
|
||||||
msg = colorRegex(msg, `(@\w*(\.\w+)*)`, messageLinkColor, messageBodyColor)
|
|
||||||
// mention URL
|
|
||||||
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" {
|
if msgType == "attachment" {
|
||||||
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))
|
msg = messageBodyColor.stylize("$TITLE\n$FILE")
|
||||||
|
attachment := api.Msg.Content.Attachment
|
||||||
|
msg = msg.replaceString("$TITLE", attachment.Object.Title)
|
||||||
|
msg = msg.replace("$FILE", messageAttachmentColor.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename)))
|
||||||
}
|
}
|
||||||
user := colorUsername(api.Msg.Sender.Username, c)
|
|
||||||
device := colorText(api.Msg.Sender.DeviceName, messageSenderDeviceColor, c)
|
user := colorUsername(api.Msg.Sender.Username)
|
||||||
msgID := colorText(fmt.Sprintf("%d", api.Msg.ID), messageIdColor, c)
|
device := messageSenderDeviceColor.stylize(api.Msg.Sender.DeviceName)
|
||||||
ts := colorText(tm.Format(timeFormat), messageTimeColor, c)
|
msgID := messageIDColor.stylize(fmt.Sprintf("%d", api.Msg.ID))
|
||||||
ret = strings.Replace(ret, "$MSG", msg, 1)
|
date := messageTimeColor.stylize(tm.Format(dateFormat))
|
||||||
ret = strings.Replace(ret, "$USER", user, 1)
|
msgTime := messageTimeColor.stylize(tm.Format(timeFormat))
|
||||||
ret = strings.Replace(ret, "$DEVICE", device, 1)
|
|
||||||
ret = strings.Replace(ret, "$ID", msgID, 1)
|
channelName := messageIDColor.stylize(fmt.Sprintf("@%s#%s", api.Msg.Channel.Name, api.Msg.Channel.TopicName))
|
||||||
ret = strings.Replace(ret, "$TIME", ts, 1)
|
ret = ret.replace("$MSG", msg)
|
||||||
ret = strings.Replace(ret, "$DATE", colorText(tm.Format(dateFormat), messageTimeColor, c), 1)
|
ret = ret.replace("$USER", user)
|
||||||
ret = strings.Replace(ret, "```", fmt.Sprintf("\n<code>\n"), -1)
|
ret = ret.replace("$DEVICE", device)
|
||||||
|
ret = ret.replace("$ID", msgID)
|
||||||
|
ret = ret.replace("$TIME", msgTime)
|
||||||
|
ret = ret.replace("$DATE", date)
|
||||||
|
ret = ret.replace("$TEAM", channelName)
|
||||||
}
|
}
|
||||||
return ret
|
return ret.string()
|
||||||
|
}
|
||||||
|
func formatOutput(api keybase.ChatAPI) string {
|
||||||
|
format := outputFormat
|
||||||
|
if stream {
|
||||||
|
format = outputStreamFormat
|
||||||
|
}
|
||||||
|
return formatMessage(api, format)
|
||||||
}
|
}
|
||||||
|
|
||||||
// End formatting
|
// End formatting
|
||||||
@ -412,9 +478,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
if api.Msg.Content.Type == "text" || api.Msg.Content.Type == "attachment" {
|
if api.Msg.Content.Type == "text" || api.Msg.Content.Type == "attachment" {
|
||||||
go populateList()
|
go populateList()
|
||||||
msgBody := api.Msg.Content.Text.Body
|
|
||||||
msgSender := api.Msg.Sender.Username
|
msgSender := api.Msg.Sender.Username
|
||||||
channelName := api.Msg.Channel.Name
|
|
||||||
if !stream {
|
if !stream {
|
||||||
if msgSender != k.Username {
|
if msgSender != k.Username {
|
||||||
if api.Msg.Channel.MembersType == keybase.TEAM {
|
if api.Msg.Channel.MembersType == keybase.TEAM {
|
||||||
@ -423,7 +487,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
if m.Text == k.Username {
|
if m.Text == k.Username {
|
||||||
// We are in a team
|
// We are in a team
|
||||||
if topicName != channel.TopicName {
|
if topicName != channel.TopicName {
|
||||||
printToView("Feed", fmt.Sprintf("[ %s#%s ] %s: %s", channelName, topicName, msgSender, msgBody))
|
printInfo(formatMessage(api, mentionFormat))
|
||||||
fmt.Print("\a")
|
fmt.Print("\a")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +496,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if msgSender != channel.Name {
|
if msgSender != channel.Name {
|
||||||
printToView("Feed", fmt.Sprintf("PM from @%s: %s", cleanChannelName(channelName), msgBody))
|
printInfo(formatMessage(api, pmFormat))
|
||||||
fmt.Print("\a")
|
fmt.Print("\a")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,10 +512,9 @@ func handleMessage(api keybase.ChatAPI) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if api.Msg.Channel.MembersType == keybase.TEAM {
|
if api.Msg.Channel.MembersType == keybase.TEAM {
|
||||||
topicName := api.Msg.Channel.TopicName
|
printToView("Chat", formatOutput(api))
|
||||||
printToView("Chat", fmt.Sprintf("@%s#%s [%s]: %s", channelName, topicName, msgSender, msgBody))
|
|
||||||
} else {
|
} else {
|
||||||
printToView("Chat", fmt.Sprintf("PM @%s [%s]: %s", cleanChannelName(channelName), msgSender, msgBody))
|
printToView("Chat", formatMessage(api, pmFormat))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -496,7 +559,7 @@ func handleInput(viewName string) error {
|
|||||||
} else if cmd[0] == "q" || cmd[0] == "quit" {
|
} else if cmd[0] == "q" || cmd[0] == "quit" {
|
||||||
return gocui.ErrQuit
|
return gocui.ErrQuit
|
||||||
} else {
|
} else {
|
||||||
printToView("Feed", fmt.Sprintf("Command '%s' not recognized", cmd[0]))
|
printError(fmt.Sprintf("Command '%s' not recognized", cmd[0]))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -520,7 +583,7 @@ func sendChat(message string) {
|
|||||||
chat := k.NewChat(channel)
|
chat := k.NewChat(channel)
|
||||||
_, err := chat.Send(message)
|
_, err := chat.Send(message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printToView("Feed", fmt.Sprintf("There was an error %+v", err))
|
printError(fmt.Sprintf("There was an error %+v", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,15 +20,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tcmdShowReactions(m keybase.ChatAPI) {
|
func tcmdShowReactions(m keybase.ChatAPI) {
|
||||||
where := ""
|
|
||||||
team := false
|
team := false
|
||||||
|
user := colorUsername(m.Msg.Sender.Username)
|
||||||
|
id := messageIDColor.stylize(fmt.Sprintf("%d", m.Msg.Content.Reaction.M))
|
||||||
|
reaction := messageReactionColor.stylize(m.Msg.Content.Reaction.B)
|
||||||
|
where := messageLinkKeybaseColor.stylize("a PM")
|
||||||
if m.Msg.Channel.MembersType == keybase.TEAM {
|
if m.Msg.Channel.MembersType == keybase.TEAM {
|
||||||
team = true
|
team = true
|
||||||
where = fmt.Sprintf("in @%s#%s", m.Msg.Channel.Name, m.Msg.Channel.TopicName)
|
where = formatChannel(m.Msg.Channel)
|
||||||
} else {
|
} else {
|
||||||
where = fmt.Sprintf("in a PM")
|
|
||||||
}
|
}
|
||||||
printToView("Feed", fmt.Sprintf("%s reacted to %d with %s %s", m.Msg.Sender.Username, m.Msg.Content.Reaction.M, m.Msg.Content.Reaction.B, where))
|
printInfoF("$TEXT reacted to [$TEXT] with $TEXT in $TEXT", user, id, reaction, where)
|
||||||
if channel.Name == m.Msg.Channel.Name {
|
if channel.Name == m.Msg.Channel.Name {
|
||||||
if team {
|
if team {
|
||||||
if channel.TopicName == m.Msg.Channel.TopicName {
|
if channel.TopicName == m.Msg.Channel.TopicName {
|
||||||
|
|||||||
@ -3,22 +3,32 @@ package main
|
|||||||
// Path where Downloaded files will default to
|
// Path where Downloaded files will default to
|
||||||
var downloadPath = "/tmp/"
|
var downloadPath = "/tmp/"
|
||||||
|
|
||||||
var colorless = false
|
var colorless bool = false
|
||||||
var channelsColor = color(8)
|
var channelsColor = basicStyle
|
||||||
var channelsHeaderColor = color(6)
|
var channelUnreadColor = channelsColor.withForeground(green).withItalic()
|
||||||
var noColor = color(-1)
|
var channelsHeaderColor = channelsColor.withForeground(magenta).withBold()
|
||||||
var mentionColor = color(3)
|
|
||||||
var messageHeaderColor = color(8)
|
var mentionColor = basicStyle.withForeground(green)
|
||||||
var messageIdColor = color(7)
|
var messageHeaderColor = basicStyle.withForeground(grey)
|
||||||
var messageTimeColor = color(6)
|
var messageIDColor = basicStyle.withForeground(yellow)
|
||||||
var messageSenderDefaultColor = color(8)
|
var messageTimeColor = basicStyle.withForeground(magenta)
|
||||||
var messageSenderDeviceColor = color(8)
|
var messageSenderDefaultColor = basicStyle.withForeground(cyan)
|
||||||
var messageBodyColor = noColor
|
var messageSenderDeviceColor = messageSenderDefaultColor
|
||||||
var messageAttachmentColor = color(2)
|
var messageBodyColor = basicStyle
|
||||||
var messageLinkColor = color(4)
|
var messageAttachmentColor = basicStyle.withForeground(red)
|
||||||
|
var messageLinkURLColor = basicStyle.withForeground(yellow)
|
||||||
|
var messageLinkKeybaseColor = basicStyle.withForeground(yellow)
|
||||||
|
var messageReactionColor = basicStyle.withForeground(magenta)
|
||||||
|
var messageCodeColor = basicStyle.withBackground(grey).withForeground(cyan)
|
||||||
|
|
||||||
|
var feedColor = basicStyle.withForeground(grey)
|
||||||
|
var errorColor = basicStyle.withForeground(red)
|
||||||
|
|
||||||
// BASH-like PS1 variable equivalent
|
// BASH-like PS1 variable equivalent
|
||||||
var outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
var outputFormat = "┌──[$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
|
var outputStreamFormat = "┌──[$TEAM] [$USER@$DEVICE] [$ID] [$DATE - $TIME]\n└╼ $MSG"
|
||||||
|
var mentionFormat = outputStreamFormat
|
||||||
|
var pmFormat = "PM from $USER@$DEVICE: $MSG"
|
||||||
|
|
||||||
// 02 = Day, Jan = Month, 06 = Year
|
// 02 = Day, Jan = Month, 06 = Year
|
||||||
var dateFormat = "02Jan06"
|
var dateFormat = "02Jan06"
|
||||||
|
|||||||
Reference in New Issue
Block a user