|
|
|
@ -376,7 +376,7 @@ func populateChat() {
@@ -376,7 +376,7 @@ func populateChat() {
|
|
|
|
|
chat := k.NewChat(channel) |
|
|
|
|
maxX, _ := g.Size() |
|
|
|
|
api, err := chat.Read(maxX / 2) |
|
|
|
|
if err != nil { |
|
|
|
|
if err != nil || api.Result == nil { |
|
|
|
|
for _, testChan := range channels { |
|
|
|
|
if channel.Name == testChan.Name { |
|
|
|
|
channel = testChan |
|
|
|
@ -405,7 +405,7 @@ func populateChat() {
@@ -405,7 +405,7 @@ func populateChat() {
|
|
|
|
|
} |
|
|
|
|
var apiCast keybase.ChatAPI |
|
|
|
|
apiCast.Msg = &message.Msg |
|
|
|
|
newMessage := formatOutput(apiCast) |
|
|
|
|
newMessage := formatOutput(apiCast).string() |
|
|
|
|
printMe = append(printMe, newMessage) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -424,6 +424,7 @@ func populateList() {
@@ -424,6 +424,7 @@ func populateList() {
|
|
|
|
|
log.Printf("%+v", err) |
|
|
|
|
} else { |
|
|
|
|
clearView("List") |
|
|
|
|
|
|
|
|
|
var textBase = config.Colors.Channels.Basic.stylize("") |
|
|
|
|
var recentPMs = textBase.append(config.Colors.Channels.Header.stylize("---[PMs]---\n")) |
|
|
|
|
var recentPMsCount = 0 |
|
|
|
@ -463,19 +464,24 @@ func populateList() {
@@ -463,19 +464,24 @@ func populateList() {
|
|
|
|
|
|
|
|
|
|
// Formatting
|
|
|
|
|
func formatMessageBody(body string) StyledString { |
|
|
|
|
body = strings.Replace(body, "```", "\n<code>\n", -1) |
|
|
|
|
message := config.Colors.Message.Body.stylize(body) |
|
|
|
|
|
|
|
|
|
message = message.colorRegex(`@[\w_]*([\.#][\w_]+)*`, config.Colors.Message.LinkKeybase) |
|
|
|
|
message = colorReplaceMentionMe(message) |
|
|
|
|
message = message.colorRegex(`_[^_]*_`, config.Colors.Message.Body.withItalic()) |
|
|
|
|
message = message.colorRegex(`~[^~]*~`, config.Colors.Message.Body.withStrikethrough()) |
|
|
|
|
|
|
|
|
|
// TODO when gocui actually fixes there shit with formatting, then un comment these lines
|
|
|
|
|
// message = message.colorRegex(`_[^_]*_`, config.Colors.Message.Body.withItalic())
|
|
|
|
|
// message = message.colorRegex(`~[^~]*~`, config.Colors.Message.Body.withStrikethrough())
|
|
|
|
|
message = message.colorRegex(`@[\w_]*([\.#][\w_]+)*`, config.Colors.Message.LinkKeybase) |
|
|
|
|
// TODO change how bold, italic etc works, so it uses boldOn boldOff ([1m and [22m)
|
|
|
|
|
message = message.colorRegex(`\*[^\*]*\*`, config.Colors.Message.Body.withBold()) |
|
|
|
|
message = message.colorRegex(">.*$", config.Colors.Message.Quote) |
|
|
|
|
message = message.regexReplaceFunc("```(.*\n)*```", func(match string) string { |
|
|
|
|
message = message.colorRegex("^>.*$", config.Colors.Message.Quote) |
|
|
|
|
message = message.regexReplaceFunc("\n<code>(.*\n)*<code>\n", func(match string) string { |
|
|
|
|
maxWidth, _ := g.Size() |
|
|
|
|
output := "\n" |
|
|
|
|
match = strings.Replace(strings.Replace(match, "```", "<code>", -1), "\t", " ", -1) |
|
|
|
|
output := "" |
|
|
|
|
match = strings.Replace(strings.Replace(match, "```", "\n<code>\n", -1), "\t", " ", -1) |
|
|
|
|
match = removeFormatting(match) |
|
|
|
|
lines := strings.Split(match, "\n") |
|
|
|
|
for _, line := range lines { |
|
|
|
|
maxLineLength := maxWidth/2 + maxWidth/3 - 2 |
|
|
|
@ -485,6 +491,8 @@ func formatMessageBody(body string) StyledString {
@@ -485,6 +491,8 @@ func formatMessageBody(body string) StyledString {
|
|
|
|
|
} |
|
|
|
|
output += line + strings.Repeat(" ", spaces) + "\n" |
|
|
|
|
} |
|
|
|
|
// TODO stylize should remove formatting - in general everything should
|
|
|
|
|
|
|
|
|
|
return config.Colors.Message.Code.stylize(output).stringFollowedByStyle(message.style) |
|
|
|
|
}) |
|
|
|
|
message = message.colorRegex("`[^`]*`", config.Colors.Message.Code) |
|
|
|
@ -515,49 +523,70 @@ func cleanChannelName(c string) string {
@@ -515,49 +523,70 @@ func cleanChannelName(c string) string {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formatMessage(api keybase.ChatAPI, formatString string) StyledString { |
|
|
|
|
msg := api.Msg |
|
|
|
|
ret := config.Colors.Message.Header.stylize("") |
|
|
|
|
msgType := api.Msg.Content.Type |
|
|
|
|
msgType := msg.Content.Type |
|
|
|
|
switch msgType { |
|
|
|
|
case "text", "attachment": |
|
|
|
|
ret = config.Colors.Message.Header.stylize(formatString) |
|
|
|
|
tm := time.Unix(int64(api.Msg.SentAt), 0) |
|
|
|
|
var msg = formatMessageBody(api.Msg.Content.Text.Body) |
|
|
|
|
tm := time.Unix(int64(msg.SentAt), 0) |
|
|
|
|
var body = formatMessageBody(msg.Content.Text.Body) |
|
|
|
|
if msgType == "attachment" { |
|
|
|
|
msg = config.Colors.Message.Body.stylize("$TITLE\n$FILE") |
|
|
|
|
attachment := api.Msg.Content.Attachment |
|
|
|
|
msg = msg.replaceString("$TITLE", attachment.Object.Title) |
|
|
|
|
msg = msg.replace("$FILE", config.Colors.Message.Attachment.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename))) |
|
|
|
|
body = config.Colors.Message.Body.stylize("$TITLE\n$FILE") |
|
|
|
|
attachment := msg.Content.Attachment |
|
|
|
|
body = body.replaceString("$TITLE", attachment.Object.Title) |
|
|
|
|
body = body.replace("$FILE", config.Colors.Message.Attachment.stylize(fmt.Sprintf("[Attachment: %s]", attachment.Object.Filename))) |
|
|
|
|
} |
|
|
|
|
reply := "" |
|
|
|
|
if msg.Content.Text.ReplyTo != 0 { |
|
|
|
|
chat := k.NewChat(channel) |
|
|
|
|
replyMsg, replErr := chat.ReadMessage(msg.Content.Text.ReplyTo) |
|
|
|
|
if replErr == nil { |
|
|
|
|
replyUser := replyMsg.Result.Messages[0].Msg.Sender.Username |
|
|
|
|
replyBody := "" |
|
|
|
|
if replyMsg.Result.Messages[0].Msg.Content.Type == "text" { |
|
|
|
|
replyBody = replyMsg.Result.Messages[0].Msg.Content.Text.Body |
|
|
|
|
} |
|
|
|
|
reply = fmt.Sprintf("\nReplyTo> %s: %s\n", replyUser, replyBody) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
user := colorUsername(api.Msg.Sender.Username) |
|
|
|
|
device := config.Colors.Message.SenderDevice.stylize(api.Msg.Sender.DeviceName) |
|
|
|
|
msgID := config.Colors.Message.ID.stylize(fmt.Sprintf("%d", api.Msg.ID)) |
|
|
|
|
user := colorUsername(msg.Sender.Username) |
|
|
|
|
device := config.Colors.Message.SenderDevice.stylize(msg.Sender.DeviceName) |
|
|
|
|
msgID := config.Colors.Message.ID.stylize(fmt.Sprintf("%d", msg.ID)) |
|
|
|
|
date := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.DateFormat)) |
|
|
|
|
msgTime := config.Colors.Message.Time.stylize(tm.Format(config.Formatting.TimeFormat)) |
|
|
|
|
|
|
|
|
|
channelName := config.Colors.Message.ID.stylize(fmt.Sprintf("@%s#%s", api.Msg.Channel.Name, api.Msg.Channel.TopicName)) |
|
|
|
|
ret = ret.replace("$MSG", msg) |
|
|
|
|
c0ck := config.Colors.Message.Quote.stylize(reply) |
|
|
|
|
channelName := config.Colors.Message.ID.stylize(fmt.Sprintf("@%s#%s", msg.Channel.Name, msg.Channel.TopicName)) |
|
|
|
|
ret = ret.replace("$REPL", c0ck) |
|
|
|
|
ret = ret.replace("$MSG", body) |
|
|
|
|
ret = ret.replace("$USER", user) |
|
|
|
|
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) |
|
|
|
|
ret = ret.replace("$TAGS", getUserFlags(api.Msg.Sender.Username)) |
|
|
|
|
} |
|
|
|
|
return ret |
|
|
|
|
} |
|
|
|
|
func formatOutput(api keybase.ChatAPI) string { |
|
|
|
|
|
|
|
|
|
func formatOutput(api keybase.ChatAPI) StyledString { |
|
|
|
|
format := config.Formatting.OutputFormat |
|
|
|
|
if stream { |
|
|
|
|
format = config.Formatting.OutputStreamFormat |
|
|
|
|
} |
|
|
|
|
return formatMessage(api, format).string() |
|
|
|
|
return formatMessage(api, format) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// End formatting
|
|
|
|
|
|
|
|
|
|
// Input handling
|
|
|
|
|
func handleMessage(api keybase.ChatAPI) { |
|
|
|
|
if api.ErrorListen != nil { |
|
|
|
|
printError(fmt.Sprintf("%+v", api.ErrorListen)) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if _, ok := typeCommands[api.Msg.Content.Type]; ok { |
|
|
|
|
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 { |
|
|
|
@ -594,7 +623,7 @@ func handleMessage(api keybase.ChatAPI) {
@@ -594,7 +623,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|
|
|
|
} |
|
|
|
|
if api.Msg.Channel.MembersType == channel.MembersType && cleanChannelName(api.Msg.Channel.Name) == channel.Name { |
|
|
|
|
if channel.MembersType == keybase.USER || channel.MembersType == keybase.TEAM && channel.TopicName == api.Msg.Channel.TopicName { |
|
|
|
|
printToView("Chat", formatOutput(api)) |
|
|
|
|
printToView("Chat", formatOutput(api).string()) |
|
|
|
|
chat := k.NewChat(channel) |
|
|
|
|
lastMessage.ID = api.Msg.ID |
|
|
|
|
chat.Read(api.Msg.ID) |
|
|
|
@ -602,7 +631,7 @@ func handleMessage(api keybase.ChatAPI) {
@@ -602,7 +631,7 @@ func handleMessage(api keybase.ChatAPI) {
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if api.Msg.Channel.MembersType == keybase.TEAM { |
|
|
|
|
printToView("Chat", formatOutput(api)) |
|
|
|
|
printToView("Chat", formatOutput(api).string()) |
|
|
|
|
} else { |
|
|
|
|
printToView("Chat", formatMessage(api, config.Formatting.PMFormat).string()) |
|
|
|
|
} |
|
|
|
|