Render attachments
This commit is contained in:
parent
6bc5b62964
commit
d0b9a6dd29
4 changed files with 22 additions and 6 deletions
|
|
@ -89,6 +89,14 @@ func (gt *GuildsTree) channelToString(c discord.Channel) string {
|
|||
}
|
||||
|
||||
func (gt *GuildsTree) onSelected(n *tview.TreeNode) {
|
||||
gt.selectedChannel = nil
|
||||
|
||||
messagesText.selectedMessage = nil
|
||||
messagesText.Highlight()
|
||||
|
||||
messageInput.SetTitle("")
|
||||
messageInput.SetText("")
|
||||
|
||||
if len(n.GetChildren()) != 0 {
|
||||
n.SetExpanded(!n.IsExpanded())
|
||||
return
|
||||
|
|
|
|||
10
main.go
10
main.go
|
|
@ -35,16 +35,16 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
discordState = newState(token)
|
||||
if err = discordState.Open(context.Background()); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Initialize UI
|
||||
guildsTree = newGuildsTree()
|
||||
messagesText = newMessagesText()
|
||||
messageInput = newMessageInput()
|
||||
|
||||
discordState = newState(token)
|
||||
if err = discordState.Open(context.Background()); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
right := tview.NewFlex()
|
||||
right.SetDirection(tview.FlexRow)
|
||||
right.AddItem(messagesText, 0, 1, false)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ func newMessageInput() *MessageInput {
|
|||
|
||||
mi.SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
|
||||
mi.SetInputCapture(mi.onInputCapture)
|
||||
|
||||
mi.SetTitleAlign(tview.AlignLeft)
|
||||
|
||||
padding := cfg.Theme.MessageInput.BorderPadding
|
||||
|
|
|
|||
|
|
@ -69,6 +69,9 @@ func (mt *MessagesText) newMessage(m *discord.Message) error {
|
|||
// Content
|
||||
mt.newContent(m)
|
||||
|
||||
// Attachments
|
||||
mt.newAttachments(m)
|
||||
|
||||
// Tags with no region ID ([""]) don't start new regions. They can therefore be used to mark the end of a region.
|
||||
fmt.Fprint(mt, `[""]`)
|
||||
}
|
||||
|
|
@ -89,6 +92,12 @@ func (mt *MessagesText) newContent(m *discord.Message) {
|
|||
fmt.Fprint(mt, tview.Escape(m.Content))
|
||||
}
|
||||
|
||||
func (mt *MessagesText) newAttachments(m *discord.Message) {
|
||||
for _, a := range m.Attachments {
|
||||
fmt.Fprintf(mt, "\n[%s]: %s", a.Filename, a.URL)
|
||||
}
|
||||
}
|
||||
|
||||
func (mt *MessagesText) onHighlighted(added, removed, remaining []string) {
|
||||
if len(added) == 0 {
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue