Explorar o código

feat(config): add link_color field

Closes #432
ayn2op hai 1 ano
pai
achega
e4d9a3fb0a
Modificáronse 4 ficheiros con 35 adicións e 63 borrados
  1. 1 52
      README.md
  2. 4 1
      cmd/messages_text.go
  3. 10 6
      internal/config/theme.go
  4. 20 4
      internal/markdown/renderer.go

+ 1 - 52
README.md

@@ -62,58 +62,7 @@ The configuration file allows you to configure and customize the behavior, keybi
 - Darwin: `$HOME/Library/Application Support/discordo/config.toml`
 - Darwin: `$HOME/Library/Application Support/discordo/config.toml`
 - Windows: `%AppData%/discordo/config.toml`
 - Windows: `%AppData%/discordo/config.toml`
 
 
-```toml
-mouse = true
-hide_blocked_users = true
-messages_limit = 50
-editor = "default"
-
-timestamps = false
-timestamps_before_author = false
-timestamps_format = "3:04PM"
-
-[keys]
-focus_guilds_tree = "Ctrl+G"
-focus_messages_text = "Ctrl+T"
-focus_message_input = "Ctrl+P"
-toggle_guild_tree = "Ctrl+B"
-select_previous = "Rune[k]"
-select_next = "Rune[j]"
-select_first = "Rune[g]"
-select_last = "Rune[G]"
-
-[keys.guilds_tree]
-select_current = "Enter"
-
-[keys.messages_text]
-select_reply = "Rune[s]"
-reply = "Rune[r]"
-reply_mention = "Rune[R]"
-delete = "Rune[d]"
-yank = "Rune[y]"
-open = "Rune[o]"
-
-[keys.message_input]
-send = "Enter"
-editor = "Ctrl+E"
-cancel = "Esc"
-
-[theme]
-border = true
-border_color = "default"
-border_padding = [0, 0, 1, 1]
-title_color = "default"
-background_color = "default"
-
-[theme.guilds_tree]
-auto_expand_folders = true
-graphics = true
-
-[theme.messages_text]
-author_color = "aqua"
-emoji_color = "green"
-reply_indicator = "╭ "
-```
+[The default configuration can be found here](./internal/config/config.go).
 
 
 ## Disclaimer
 ## Disclaimer
 
 

+ 4 - 1
cmd/messages_text.go

@@ -52,7 +52,10 @@ func newMessagesText() *MessagesText {
 	mt.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
 	mt.SetBorderColor(tcell.GetColor(cfg.Theme.BorderColor))
 	mt.SetBorderPadding(p[0], p[1], p[2], p[3])
 	mt.SetBorderPadding(p[0], p[1], p[2], p[3])
 
 
-	markdown.DefaultRenderer.AddOptions(renderer.WithOption("emojiColor", cfg.Theme.MessagesText.EmojiColor))
+	markdown.DefaultRenderer.AddOptions(
+		renderer.WithOption("emojiColor", cfg.Theme.MessagesText.EmojiColor),
+		renderer.WithOption("linkColor", cfg.Theme.MessagesText.LinkColor),
+	)
 
 
 	return mt
 	return mt
 }
 }

+ 10 - 6
internal/config/theme.go

@@ -24,10 +24,12 @@ type (
 	}
 	}
 
 
 	MessagesTextTheme struct {
 	MessagesTextTheme struct {
-		AuthorColor    string `toml:"author_color"`
-		ContentColor   string `toml:"content_color"`
-		EmojiColor     string `toml:"emoji_color"`
 		ReplyIndicator string `toml:"reply_indicator"`
 		ReplyIndicator string `toml:"reply_indicator"`
+
+		AuthorColor  string `toml:"author_color"`
+		ContentColor string `toml:"content_color"`
+		EmojiColor   string `toml:"emoji_color"`
+		LinkColor    string `toml:"link_color"`
 	}
 	}
 )
 )
 
 
@@ -48,10 +50,12 @@ func defaultTheme() Theme {
 			PrivateChannelColor: tview.Styles.PrimaryTextColor.String(),
 			PrivateChannelColor: tview.Styles.PrimaryTextColor.String(),
 		},
 		},
 		MessagesText: MessagesTextTheme{
 		MessagesText: MessagesTextTheme{
-			AuthorColor:    "aqua",
-			ContentColor:   tview.Styles.PrimaryTextColor.String(),
-			EmojiColor:     "green",
 			ReplyIndicator: string(tview.BoxDrawingsLightArcDownAndRight) + " ",
 			ReplyIndicator: string(tview.BoxDrawingsLightArcDownAndRight) + " ",
+
+			AuthorColor:  "aqua",
+			ContentColor: tview.Styles.PrimaryTextColor.String(),
+			EmojiColor:   "green",
+			LinkColor:    "blue",
 		},
 		},
 	}
 	}
 }
 }

+ 20 - 4
internal/markdown/renderer.go

@@ -34,6 +34,8 @@ func (r *renderer) Render(w io.Writer, source []byte, n ast.Node) error {
 		switch n := n.(type) {
 		switch n := n.(type) {
 		case *ast.Document:
 		case *ast.Document:
 		// noop
 		// noop
+		case *ast.Heading:
+			io.WriteString(w, "\n")
 		case *ast.FencedCodeBlock:
 		case *ast.FencedCodeBlock:
 			io.WriteString(w, "\n")
 			io.WriteString(w, "\n")
 
 
@@ -45,16 +47,30 @@ func (r *renderer) Render(w io.Writer, source []byte, n ast.Node) error {
 					w.Write(line.Value(source))
 					w.Write(line.Value(source))
 				}
 				}
 			}
 			}
+		case *ast.AutoLink:
+			if entering {
+				linkColor := r.config.Options["linkColor"].(string)
+				io.WriteString(w, "["+linkColor+"]")
+				w.Write(n.URL(source))
+			} else {
+				io.WriteString(w, "[-::]")
+			}
 		case *ast.Link:
 		case *ast.Link:
 			if entering {
 			if entering {
-				io.WriteString(w, fmt.Sprintf("[:::%s]", n.Destination))
+				linkColor := r.config.Options["linkColor"].(string)
+				io.WriteString(w, fmt.Sprintf("[%s:::%s]", linkColor, n.Destination))
 			} else {
 			} else {
-				io.WriteString(w, "[:::-]")
+				io.WriteString(w, "[-:::-]")
 			}
 			}
 		case *ast.Text:
 		case *ast.Text:
 			if entering {
 			if entering {
-				value := n.Segment.Value(source)
-				w.Write(value)
+				w.Write(n.Segment.Value(source))
+				switch {
+				case n.HardLineBreak():
+					io.WriteString(w, "\n\n")
+				case n.SoftLineBreak():
+					io.WriteString(w, "\n")
+				}
 			}
 			}
 
 
 		case *discordmd.Inline:
 		case *discordmd.Inline: