Quellcode durchsuchen

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

Ayyan vor 10 Monaten
Ursprung
Commit
d701e7d15b
2 geänderte Dateien mit 63 neuen und 18 gelöschten Zeilen
  1. 14 13
      internal/config/config.toml
  2. 49 5
      internal/config/theme.go

+ 14 - 13
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

+ 49 - 5
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
+	}
+}