From d701e7d15ba07457aa41ab1d1d02ce2c565c7736 Mon Sep 17 00:00:00 2001 From: Ayyan Date: Thu, 26 Jun 2025 15:48:40 -0400 Subject: [PATCH] feat(config): add support for attributes (#567) --- internal/config/config.toml | 27 ++++++++++--------- internal/config/theme.go | 54 +++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 18 deletions(-) diff --git a/internal/config/config.toml b/internal/config/config.toml index e507cb8..de97d4e 100644 --- a/internal/config/config.toml +++ b/internal/config/config.toml @@ -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 diff --git a/internal/config/theme.go b/internal/config/theme.go index 611af46..3d3ee94 100644 --- a/internal/config/theme.go +++ b/internal/config/theme.go @@ -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 + } +}