feat: color-coded & formatted emotes (#428)

This commit is contained in:
Retropaint 2024-09-20 22:40:48 +08:00 • committed by GitHub
parent 9d001a522e
commit d9026d3dd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View file

@ -111,6 +111,7 @@ graphics = true
[theme.messages_text]
author_color = "aqua"
emote_color = "green"
reply_indicator = "╭ "
```

View file

@ -146,7 +146,7 @@ func (mt *MessagesText) createBody(w io.Writer, m discord.Message, isReply bool)
if isReply {
fmt.Fprint(w, "[::d]")
}
fmt.Fprint(w, markdown.Parse(tview.Escape(body)))
fmt.Fprint(w, markdown.Parse(tview.Escape(body), cfg.Theme.MessagesText.EmoteColor))
if isReply {
fmt.Fprint(w, "[::-]")
}

View file

@ -21,8 +21,9 @@ type (
}
MessagesTextTheme struct {
AuthorColor string `toml:"author_color"`
ReplyIndicator string `toml:"reply_indicator"`
AuthorColor string `toml:"author_color"`
EmoteColor string `toml:"emote_color"`
ReplyIndicator string `toml:"reply_indicator"`
}
)
@ -40,8 +41,9 @@ func defaultTheme() Theme {
Graphics: true,
},
MessagesText: MessagesTextTheme{
AuthorColor: "aqua",
ReplyIndicator: string(tview.BoxDrawingsLightArcDownAndRight) + " ",
AuthorColor: "aqua",
EmoteColor: "green",
ReplyIndicator: string(tview.BoxDrawingsLightArcDownAndRight) + " ",
},
}
}

View file

@ -10,13 +10,16 @@ var (
underlineRe = regexp.MustCompile(`(?ms)__(.*?)__`)
strikethroughRe = regexp.MustCompile(`(?ms)~~(.*?)~~`)
codeblockRe = regexp.MustCompile("(?ms)`" + `([^` + "`" + `\n]+)` + "`")
emoteRe = regexp.MustCompile(`<(:[a-zA-Z0-9]+:)[0-9]+>`)
)
func Parse(input string) string {
func Parse(input string, emoteColor string) string {
input = boldRe.ReplaceAllString(input, "[::b]$1[::B]")
input = italicRe.ReplaceAllString(input, "[::i]$1[::I]")
input = underlineRe.ReplaceAllString(input, "[::u]$1[::U]")
input = strikethroughRe.ReplaceAllString(input, "[::s]$1[::S]")
input = codeblockRe.ReplaceAllString(input, "[::r]$1[::R]")
input = emoteRe.ReplaceAllString(input, "[" + emoteColor + "]$1[-:-:-]")
return input
}