Răsfoiți Sursa

feat: color-coded & formatted emotes (#428)

Retropaint 1 an în urmă
părinte
comite
d9026d3dd8
4 a modificat fișierele cu 12 adăugiri și 6 ștergeri
  1. 1 0
      README.md
  2. 1 1
      cmd/messages_text.go
  3. 6 4
      internal/config/theme.go
  4. 4 1
      internal/markdown/markdown.go

+ 1 - 0
README.md

@@ -111,6 +111,7 @@ graphics = true
 
 [theme.messages_text]
 author_color = "aqua"
+emote_color = "green"
 reply_indicator = "╭ "
 ```
 

+ 1 - 1
cmd/messages_text.go

@@ -146,7 +146,7 @@ func (mt *MessagesText) createBody(w io.Writer, m discord.Message, isReply bool)
 	if isReply {
 		fmt.Fprint(w, "[::d]")
 	}
-	fmt.Fprint(w, markdown.Parse(tview.Escape(body)))
+	fmt.Fprint(w, markdown.Parse(tview.Escape(body), cfg.Theme.MessagesText.EmoteColor))
 	if isReply {
 		fmt.Fprint(w, "[::-]")
 	}

+ 6 - 4
internal/config/theme.go

@@ -21,8 +21,9 @@ type (
 	}
 
 	MessagesTextTheme struct {
-		AuthorColor    string `toml:"author_color"`
-		ReplyIndicator string `toml:"reply_indicator"`
+		AuthorColor     string `toml:"author_color"`
+		EmoteColor      string `toml:"emote_color"`
+		ReplyIndicator  string `toml:"reply_indicator"`
 	}
 )
 
@@ -40,8 +41,9 @@ func defaultTheme() Theme {
 			Graphics:          true,
 		},
 		MessagesText: MessagesTextTheme{
-			AuthorColor:    "aqua",
-			ReplyIndicator: string(tview.BoxDrawingsLightArcDownAndRight) + " ",
+			AuthorColor:        "aqua",
+			EmoteColor:         "green",
+			ReplyIndicator:     string(tview.BoxDrawingsLightArcDownAndRight) + " ",
 		},
 	}
 }

+ 4 - 1
internal/markdown/markdown.go

@@ -10,13 +10,16 @@ var (
 	underlineRe     = regexp.MustCompile(`(?ms)__(.*?)__`)
 	strikethroughRe = regexp.MustCompile(`(?ms)~~(.*?)~~`)
 	codeblockRe     = regexp.MustCompile("(?ms)`" + `([^` + "`" + `\n]+)` + "`")
+	emoteRe         = regexp.MustCompile(`<(:[a-zA-Z0-9]+:)[0-9]+>`)
 )
 
-func Parse(input string) string {
+func Parse(input string, emoteColor string) string {
 	input = boldRe.ReplaceAllString(input, "[::b]$1[::B]")
 	input = italicRe.ReplaceAllString(input, "[::i]$1[::I]")
 	input = underlineRe.ReplaceAllString(input, "[::u]$1[::U]")
 	input = strikethroughRe.ReplaceAllString(input, "[::s]$1[::S]")
 	input = codeblockRe.ReplaceAllString(input, "[::r]$1[::R]")
+	input = emoteRe.ReplaceAllString(input, "[" + emoteColor + "]$1[-:-:-]")
+
 	return input
 }