feat(config): add support for attributes (#567)

This commit is contained in:
Ayyan 2025-06-26 15:48:40 -04:00 • committed by GitHub
parent 9026c75040
commit d701e7d15b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 63 additions and 18 deletions

View file

@ -100,14 +100,15 @@ up = "Up"
down = "Down"
# Applies to all
# style = { foreground = "", background = "", attributes = "" or [""] }
[theme]
background_color = "default"
[theme.title]
# `"left"`, `"center"`, or `"right"`.
alignment = "left"
normal_style = { foreground = "default", background = "default" }
active_style = { foreground = "green", background = "default" }
normal_style = { attributes = "dim" }
active_style = { attributes = "bold" }
[theme.border]
enabled = true
@ -115,17 +116,17 @@ enabled = true
padding = [0, 0, 1, 1]
# `"plain"`, `"round"`, `"thick"`, or `"double"`.
set = "plain"
normal_style = { foreground = "default", background = "default" }
active_style = { foreground = "green", background = "default" }
normal_style = { attributes = "dim" }
active_style = { attributes = "bold" }
[theme.guilds_tree]
auto_expand_folders = true
# Give tree-like shape
graphics = true
graphics_color = "default"
private_channel_style = { foreground = "default", background = "default" }
guild_style = { foreground = "default", background = "default" }
channel_style = { foreground = "default", background = "default" }
# graphics_color = "default"
# private_channel_style = { foreground = "default" }
# guild_style = { foreground = "default" }
# channel_style = { foreground = "default" }
[theme.messages_list]
# Set to false to show messages with usernames instead of nicknames
@ -135,11 +136,11 @@ show_user_colors = true
reply_indicator = ">"
forwarded_indicator = "<"
author_style = { foreground = "aqua", background = "default" }
mention_style = { foreground = "blue", background = "default" }
emoji_style = { foreground = "green", background = "default" }
url_style = { foreground = "blue", background = "default" }
attachment_style = { foreground = "yellow", background = "default" }
author_style = { foreground = "aqua" }
mention_style = { foreground = "blue" }
emoji_style = { foreground = "green" }
url_style = { foreground = "blue" }
attachment_style = { foreground = "yellow" }
[theme.mentions_list]
show_user_nicks = true

View file

@ -66,18 +66,41 @@ func (sw *StyleWrapper) UnmarshalTOML(v any) error {
}
for key, val := range m {
s, ok := val.(string)
if !ok {
continue
}
switch key {
case "foreground":
s, ok := val.(string)
if !ok {
continue
}
color := tcell.GetColor(s)
sw.Style = sw.Foreground(color)
case "background":
s, ok := val.(string)
if !ok {
continue
}
color := tcell.GetColor(s)
sw.Style = sw.Background(color)
case "attributes":
var attrs tcell.AttrMask
switch val := val.(type) {
case string:
attrs |= stringToAttrMask(val)
case []any:
for _, attr := range val {
s, ok := attr.(string)
if !ok {
continue
}
attrs |= stringToAttrMask(s)
}
}
sw.Style = sw.Attributes(attrs)
}
}
@ -146,3 +169,24 @@ type (
MentionsList MentionsListTheme `toml:"mentions_list"`
}
)
func stringToAttrMask(s string) tcell.AttrMask {
switch s {
case "bold":
return tcell.AttrBold
case "blink":
return tcell.AttrBlink
case "reverse":
return tcell.AttrReverse
case "underline":
return tcell.AttrUnderline
case "dim":
return tcell.AttrDim
case "italic":
return tcell.AttrItalic
case "strikethrough":
return tcell.AttrStrikeThrough
default:
return tcell.AttrNone
}
}