From f9ed9a7a1283289a76f3fbfc6c4e0215ebf2fda0 Mon Sep 17 00:00:00 2001 From: ayntgl Date: Fri, 25 Mar 2022 10:45:25 +0400 Subject: [PATCH] Add channel name and topic as MessagesTextView title on channel select --- ui/channels.go | 10 +++++++++- ui/messages.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ui/channels.go b/ui/channels.go index 599c4f8..b45efd4 100644 --- a/ui/channels.go +++ b/ui/channels.go @@ -2,6 +2,7 @@ package ui import ( "github.com/ayntgl/astatine" + "github.com/ayntgl/discordo/discord" "github.com/rivo/tview" ) @@ -30,7 +31,8 @@ func (ctv *ChannelsTreeView) onSelected(n *tview.TreeNode) { ctv.app.SelectedMessage = -1 ctv.app.MessagesTextView. Highlight(). - Clear() + Clear(). + SetTitle("") ctv.app.MessageInputField.SetText("") c, err := ctv.app.Session.State.Channel(n.GetReference().(string)) @@ -46,6 +48,12 @@ func (ctv *ChannelsTreeView) onSelected(n *tview.TreeNode) { ctv.app.SelectedChannel = c ctv.app.SetFocus(ctv.app.MessageInputField) + title := discord.ChannelToString(c) + if c.Topic != "" { + title += " - " + discord.ParseMarkdown(c.Topic) + } + ctv.app.MessagesTextView.SetTitle(title) + go func() { ms, err := ctv.app.Session.ChannelMessages(c.ID, ctv.app.Config.General.FetchMessagesLimit, "", "", "") if err != nil { diff --git a/ui/messages.go b/ui/messages.go index 6976d32..86c7fd0 100644 --- a/ui/messages.go +++ b/ui/messages.go @@ -37,6 +37,7 @@ func NewMessagesTextView(app *App) *MessagesTextView { mtv.SetChangedFunc(func() { mtv.app.Draw() }) + mtv.SetTitleAlign(tview.AlignLeft) mtv.SetBorder(true) mtv.SetBorderPadding(0, 0, 1, 1) mtv.SetInputCapture(mtv.onInputCapture)