feat(config): add fine-grained style control to theme.messages_text
This commit is contained in:
parent
7baf434235
commit
db4ded3b03
4 changed files with 41 additions and 44 deletions
|
|
@ -52,7 +52,6 @@ func newMessagesText(cfg *config.Config) *messagesText {
|
|||
SetRegions(true).
|
||||
SetWordWrap(true).
|
||||
ScrollToEnd().
|
||||
SetTextColor(tcell.GetColor(t.MessagesText.ContentColor)).
|
||||
SetHighlightedFunc(mt.onHighlighted).
|
||||
SetChangedFunc(func() {
|
||||
app.Draw()
|
||||
|
|
@ -60,13 +59,7 @@ func newMessagesText(cfg *config.Config) *messagesText {
|
|||
SetTitle("Messages").
|
||||
SetInputCapture(mt.onInputCapture)
|
||||
|
||||
markdown.DefaultRenderer.AddOptions(
|
||||
renderer.WithOption("emojiColor", t.MessagesText.EmojiColor),
|
||||
renderer.WithOption("linkColor", t.MessagesText.LinkColor),
|
||||
renderer.WithOption("mentionColor", t.MessagesText.MentionColor),
|
||||
renderer.WithOption("showNicknames", t.MessagesText.ShowNicknames),
|
||||
)
|
||||
|
||||
markdown.DefaultRenderer.AddOptions(renderer.WithOption("theme", t.MessagesText))
|
||||
return mt
|
||||
}
|
||||
|
||||
|
|
@ -132,10 +125,8 @@ func (mt *messagesText) createMsg(msg discord.Message) {
|
|||
}
|
||||
case discord.InlinedReplyMessage:
|
||||
mt.createReplyMsg(msg)
|
||||
|
||||
case discord.ChannelPinnedMessage:
|
||||
fmt.Fprint(mt, "["+mt.cfg.Theme.MessagesText.ContentColor+"]"+msg.Author.Username+" pinned a message"+"[-:-:-]")
|
||||
|
||||
fmt.Fprintf(mt, "%s pinned a message", msg.Author.DisplayOrUsername())
|
||||
default:
|
||||
mt.drawTimestamps(msg.Timestamp)
|
||||
mt.drawAuthor(msg)
|
||||
|
|
@ -154,8 +145,8 @@ func (mt *messagesText) drawTimestamps(ts discord.Timestamp) {
|
|||
|
||||
func (mt *messagesText) drawAuthor(msg discord.Message) {
|
||||
name := mt.authorName(msg.Author, msg.GuildID)
|
||||
color := mt.authorColor(msg.Author, msg.GuildID)
|
||||
fmt.Fprintf(mt, "[%s]%s[-] ", color, name)
|
||||
fg, bg, _ := mt.authorStyle(msg.Author, msg.GuildID).Decompose()
|
||||
_, _ = fmt.Fprintf(mt, "[%s:%s]%s[-] ", fg.String(), bg.String(), name)
|
||||
}
|
||||
|
||||
func (mt *messagesText) drawContent(msg discord.Message) {
|
||||
|
|
@ -188,10 +179,12 @@ func (mt *messagesText) createDefaultMsg(msg discord.Message) {
|
|||
|
||||
for _, a := range msg.Attachments {
|
||||
fmt.Fprintln(mt)
|
||||
|
||||
fg, bg, _ := mt.cfg.Theme.MessagesText.AttachmentStyle.Decompose()
|
||||
if mt.cfg.ShowAttachmentLinks {
|
||||
fmt.Fprintf(mt, "[%s][%s]:\n%s[-]", mt.cfg.Theme.MessagesText.AttachmentColor, a.Filename, a.URL)
|
||||
fmt.Fprintf(mt, "[%s:%s][%s]:\n%s[-]", fg, bg, a.Filename, a.URL)
|
||||
} else {
|
||||
fmt.Fprintf(mt, "[%s][%s][-]", mt.cfg.Theme.MessagesText.AttachmentColor, a.Filename)
|
||||
fmt.Fprintf(mt, "[%s:%s][%s][-]", fg, bg, a.Filename)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -230,16 +223,16 @@ func (mt *messagesText) createForwardedMsg(msg discord.Message) {
|
|||
fmt.Fprintf(mt, " [::d](%s)[-:-:-] ", mt.formatTimestamp(msg.MessageSnapshots[0].Message.Timestamp))
|
||||
}
|
||||
|
||||
func (mt *messagesText) authorColor(user discord.User, gID discord.GuildID) string {
|
||||
color := mt.cfg.Theme.MessagesText.AuthorColor
|
||||
func (mt *messagesText) authorStyle(user discord.User, gID discord.GuildID) config.StyleWrapper {
|
||||
style := mt.cfg.Theme.MessagesText.AuthorStyle
|
||||
if app.cfg.Theme.MessagesText.ShowUsernameColors && gID.IsValid() {
|
||||
// Use color from highest role in guild
|
||||
if c, ok := discordState.MemberColor(gID, user.ID); ok {
|
||||
color = c.String()
|
||||
style = config.StyleWrapper{Style: tcell.StyleDefault.Foreground(tcell.GetColor(c.String()))}
|
||||
}
|
||||
}
|
||||
|
||||
return color
|
||||
return style
|
||||
}
|
||||
|
||||
func (mt *messagesText) selectedMsg() (*discord.Message, error) {
|
||||
|
|
|
|||
|
|
@ -121,9 +121,8 @@ show_user_nicks = true
|
|||
show_user_colors = true
|
||||
reply_indicator = ">"
|
||||
forwarded_indicator = "<"
|
||||
author_color = "aqua"
|
||||
content_color = "white"
|
||||
emoji_color = "green"
|
||||
link_color = "blue"
|
||||
attachment_color = "yellow"
|
||||
mention_color = "blue"
|
||||
author_style = { foreground = "aqua" }
|
||||
mention_style = { foreground = "blue" }
|
||||
emoji_style = { foreground = "green" }
|
||||
url_style = { foreground = "blue" }
|
||||
attachment_style = { foreground = "yellow" }
|
||||
|
|
|
|||
|
|
@ -105,11 +105,10 @@ type (
|
|||
ReplyIndicator string `toml:"reply_indicator"`
|
||||
ForwardedIndicator string `toml:"forwarded_indicator"`
|
||||
|
||||
AuthorColor string `toml:"author_color"`
|
||||
ContentColor string `toml:"content_color"`
|
||||
EmojiColor string `toml:"emoji_color"`
|
||||
LinkColor string `toml:"link_color"`
|
||||
AttachmentColor string `toml:"attachment_color"`
|
||||
MentionColor string `toml:"mention_color"`
|
||||
AuthorStyle StyleWrapper `toml:"author_style"`
|
||||
MentionStyle StyleWrapper `toml:"mention_style"`
|
||||
EmojiStyle StyleWrapper `toml:"emoji_style"`
|
||||
URLStyle StyleWrapper `toml:"url_style"`
|
||||
AttachmentStyle StyleWrapper `toml:"attachment_style"`
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/ayn2op/discordo/internal/config"
|
||||
"github.com/diamondburned/ningen/v3/discordmd"
|
||||
"github.com/yuin/goldmark/ast"
|
||||
gmr "github.com/yuin/goldmark/renderer"
|
||||
|
|
@ -75,20 +76,22 @@ func (r *renderer) renderFencedCodeBlock(w io.Writer, n *ast.FencedCodeBlock, en
|
|||
|
||||
func (r *renderer) renderAutoLink(w io.Writer, n *ast.AutoLink, entering bool, source []byte) {
|
||||
if entering {
|
||||
linkColor := r.config.Options["linkColor"].(string)
|
||||
io.WriteString(w, "["+linkColor+"]")
|
||||
theme := r.config.Options["theme"].(config.MessagesTextTheme)
|
||||
fg, bg, _ := theme.URLStyle.Decompose()
|
||||
_, _ = fmt.Fprintf(w, "[%s:%s]", fg, bg)
|
||||
w.Write(n.URL(source))
|
||||
} else {
|
||||
io.WriteString(w, "[-::]")
|
||||
io.WriteString(w, "[-:-]")
|
||||
}
|
||||
}
|
||||
|
||||
func (r *renderer) renderLink(w io.Writer, n *ast.Link, entering bool) {
|
||||
if entering {
|
||||
linkColor := r.config.Options["linkColor"].(string)
|
||||
io.WriteString(w, fmt.Sprintf("[%s:::%s]", linkColor, n.Destination))
|
||||
theme := r.config.Options["theme"].(config.MessagesTextTheme)
|
||||
fg, bg, _ := theme.URLStyle.Decompose()
|
||||
_, _ = fmt.Fprintf(w, "[%s:%s::%s]", fg, bg, n.Destination)
|
||||
} else {
|
||||
io.WriteString(w, "[-:::-]")
|
||||
io.WriteString(w, "[-:-::-]")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,15 +139,17 @@ func (r *renderer) renderInline(w io.Writer, n *discordmd.Inline, entering bool)
|
|||
|
||||
func (r *renderer) renderMention(w io.Writer, n *discordmd.Mention, entering bool) {
|
||||
if entering {
|
||||
mentionColor := r.config.Options["mentionColor"].(string)
|
||||
_, _ = fmt.Fprintf(w, "[%s::b]", mentionColor)
|
||||
theme := r.config.Options["theme"].(config.MessagesTextTheme)
|
||||
fg, bg, _ := theme.MentionStyle.Decompose()
|
||||
_, _ = fmt.Fprintf(w, "[%s:%s:b]", fg, bg)
|
||||
|
||||
switch {
|
||||
case n.Channel != nil:
|
||||
io.WriteString(w, "#"+n.Channel.Name)
|
||||
case n.GuildUser != nil:
|
||||
username := n.GuildUser.DisplayOrUsername()
|
||||
if r.config.Options["showNicknames"].(bool) && n.GuildUser.Member != nil && n.GuildUser.Member.Nick != "" {
|
||||
theme := r.config.Options["theme"].(config.MessagesTextTheme)
|
||||
if theme.ShowNicknames && n.GuildUser.Member != nil && n.GuildUser.Member.Nick != "" {
|
||||
username = n.GuildUser.Member.Nick
|
||||
}
|
||||
io.WriteString(w, "@"+username)
|
||||
|
|
@ -152,16 +157,17 @@ func (r *renderer) renderMention(w io.Writer, n *discordmd.Mention, entering boo
|
|||
io.WriteString(w, "@"+n.GuildRole.Name)
|
||||
}
|
||||
} else {
|
||||
io.WriteString(w, "[-::B]")
|
||||
io.WriteString(w, "[-:-:B]")
|
||||
}
|
||||
}
|
||||
|
||||
func (r *renderer) renderEmoji(w io.Writer, n *discordmd.Emoji, entering bool) {
|
||||
if entering {
|
||||
emojiColor := r.config.Options["emojiColor"].(string)
|
||||
io.WriteString(w, "["+emojiColor+"]")
|
||||
theme := r.config.Options["theme"].(config.MessagesTextTheme)
|
||||
fg, bg, _ := theme.EmojiStyle.Decompose()
|
||||
fmt.Fprintf(w, "[%s:%s]", fg, bg)
|
||||
io.WriteString(w, ":"+n.Name+":")
|
||||
} else {
|
||||
io.WriteString(w, "[-]")
|
||||
io.WriteString(w, "[-:-]")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue