Merge branch 'main' into add-nix

This commit is contained in:
Emanuel Johnson Godin 2025-05-26 20:09:32 +02:00 • committed by GitHub
commit 7edb2bcd23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 130 additions and 98 deletions

View file

@ -211,15 +211,15 @@ func (gt *GuildsTree) onSelected(n *tview.TreeNode) {
return
}
sort.Slice(cs, func(a, b int) bool {
msgID := func(ch discord.Channel) discord.MessageID {
if ch.LastMessageID.IsValid() {
return ch.LastMessageID
}
return discord.MessageID(ch.ID)
}
return msgID(cs[a]) > msgID(cs[b])
})
sort.Slice(cs, func(a, b int) bool {
msgID := func(ch discord.Channel) discord.MessageID {
if ch.LastMessageID.IsValid() {
return ch.LastMessageID
}
return discord.MessageID(ch.ID)
}
return msgID(cs[a]) > msgID(cs[b])
})
for _, c := range cs {
gt.createChannelNode(n, c)

View file

@ -58,7 +58,7 @@ type (
ShowNicknames bool `toml:"show_user_nicks"`
ShowUsernameColors bool `toml:"show_user_colors"`
ReplyIndicator string `toml:"reply_indicator"`
ReplyIndicator string `toml:"reply_indicator"`
ForwardedIndicator string `toml:"forwarded_indicator"`
AuthorColor string `toml:"author_color"`

View file

@ -33,101 +33,133 @@ func (r *renderer) Render(w io.Writer, source []byte, n ast.Node) error {
case *ast.Document:
// noop
case *ast.Heading:
io.WriteString(w, "\n")
case *ast.FencedCodeBlock:
io.WriteString(w, "\n")
if entering {
// body
for i := range n.Lines().Len() {
line := n.Lines().At(i)
io.WriteString(w, "| ")
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:
if entering {
linkColor := r.config.Options["linkColor"].(string)
io.WriteString(w, fmt.Sprintf("[%s:::%s]", linkColor, n.Destination))
} else {
io.WriteString(w, "[-:::-]")
}
r.renderHeading(w)
case *ast.Text:
if entering {
w.Write(n.Segment.Value(source))
switch {
case n.HardLineBreak():
io.WriteString(w, "\n\n")
case n.SoftLineBreak():
io.WriteString(w, "\n")
}
}
r.renderText(w, n, entering, source)
case *ast.FencedCodeBlock:
r.renderFencedCodeBlock(w, n, entering, source)
case *ast.AutoLink:
r.renderAutoLink(w, n, entering, source)
case *ast.Link:
r.renderLink(w, n, entering)
case *discordmd.Inline:
if entering {
switch n.Attr {
case discordmd.AttrBold:
io.WriteString(w, "[::b]")
case discordmd.AttrItalics:
io.WriteString(w, "[::i]")
case discordmd.AttrUnderline:
io.WriteString(w, "[::u]")
case discordmd.AttrStrikethrough:
io.WriteString(w, "[::s]")
case discordmd.AttrMonospace:
io.WriteString(w, "[::r]")
}
} else {
switch n.Attr {
case discordmd.AttrBold:
io.WriteString(w, "[::B]")
case discordmd.AttrItalics:
io.WriteString(w, "[::I]")
case discordmd.AttrUnderline:
io.WriteString(w, "[::U]")
case discordmd.AttrStrikethrough:
io.WriteString(w, "[::S]")
case discordmd.AttrMonospace:
io.WriteString(w, "[::R]")
}
}
r.renderInline(w, n, entering)
case *discordmd.Mention:
if entering {
io.WriteString(w, "[::b]")
switch {
case n.Channel != nil:
io.WriteString(w, "#"+n.Channel.Name)
case n.GuildUser != nil:
username := n.GuildUser.DisplayOrUsername()
if r.config.Options["showNicknames"].(bool) && n.GuildUser.Member != nil && n.GuildUser.Member.Nick != "" {
username = n.GuildUser.Member.Nick
}
io.WriteString(w, "@"+username)
case n.GuildRole != nil:
io.WriteString(w, "@"+n.GuildRole.Name)
}
} else {
io.WriteString(w, "[::B]")
}
r.renderMention(w, n, entering)
case *discordmd.Emoji:
if entering {
emojiColor := r.config.Options["emojiColor"].(string)
io.WriteString(w, "["+emojiColor+"]")
io.WriteString(w, ":"+n.Name+":")
} else {
io.WriteString(w, "[-]")
}
r.renderEmoji(w, n, entering)
}
return ast.WalkContinue, nil
})
}
func (r *renderer) renderHeading(w io.Writer) {
io.WriteString(w, "\n")
}
func (r *renderer) renderFencedCodeBlock(w io.Writer, n *ast.FencedCodeBlock, entering bool, source []byte) {
io.WriteString(w, "\n")
if entering {
// body
for i := range n.Lines().Len() {
line := n.Lines().At(i)
io.WriteString(w, "| ")
w.Write(line.Value(source))
}
}
}
func (r *renderer) renderAutoLink(w io.Writer, n *ast.AutoLink, entering bool, source []byte) {
if entering {
linkColor := r.config.Options["linkColor"].(string)
io.WriteString(w, "["+linkColor+"]")
w.Write(n.URL(source))
} else {
io.WriteString(w, "[-::]")
}
}
func (r *renderer) renderLink(w io.Writer, n *ast.Link, entering bool) {
if entering {
linkColor := r.config.Options["linkColor"].(string)
io.WriteString(w, fmt.Sprintf("[%s:::%s]", linkColor, n.Destination))
} else {
io.WriteString(w, "[-:::-]")
}
}
func (r *renderer) renderText(w io.Writer, n *ast.Text, entering bool, source []byte) {
if entering {
w.Write(n.Segment.Value(source))
switch {
case n.HardLineBreak():
io.WriteString(w, "\n\n")
case n.SoftLineBreak():
io.WriteString(w, "\n")
}
}
}
func (r *renderer) renderInline(w io.Writer, n *discordmd.Inline, entering bool) {
if entering {
switch n.Attr {
case discordmd.AttrBold:
io.WriteString(w, "[::b]")
case discordmd.AttrItalics:
io.WriteString(w, "[::i]")
case discordmd.AttrUnderline:
io.WriteString(w, "[::u]")
case discordmd.AttrStrikethrough:
io.WriteString(w, "[::s]")
case discordmd.AttrMonospace:
io.WriteString(w, "[::r]")
}
} else {
switch n.Attr {
case discordmd.AttrBold:
io.WriteString(w, "[::B]")
case discordmd.AttrItalics:
io.WriteString(w, "[::I]")
case discordmd.AttrUnderline:
io.WriteString(w, "[::U]")
case discordmd.AttrStrikethrough:
io.WriteString(w, "[::S]")
case discordmd.AttrMonospace:
io.WriteString(w, "[::R]")
}
}
}
func (r *renderer) renderMention(w io.Writer, n *discordmd.Mention, entering bool) {
if entering {
io.WriteString(w, "[::b]")
switch {
case n.Channel != nil:
io.WriteString(w, "#"+n.Channel.Name)
case n.GuildUser != nil:
username := n.GuildUser.DisplayOrUsername()
if r.config.Options["showNicknames"].(bool) && n.GuildUser.Member != nil && n.GuildUser.Member.Nick != "" {
username = n.GuildUser.Member.Nick
}
io.WriteString(w, "@"+username)
case n.GuildRole != nil:
io.WriteString(w, "@"+n.GuildRole.Name)
}
} else {
io.WriteString(w, "[::B]")
}
}
func (r *renderer) renderEmoji(w io.Writer, n *discordmd.Emoji, entering bool) {
if entering {
emojiColor := r.config.Options["emojiColor"].(string)
io.WriteString(w, "["+emojiColor+"]")
io.WriteString(w, ":"+n.Name+":")
} else {
io.WriteString(w, "[-]")
}
}