discordo/ui/textviews.go
rigormorrtiss 5d19c768fe feat: implement selectable messages (#38)
* feat: implement selectable messages

* style: shorten long lines

* feat: handle key down event for message select functionality

* feat: add handlers for top and bottom navigation

* style: shorten long lines

* docs: add 's' to singular verb

* docs: add missing period

* fix: if selectedChannel is not initialized, do not handle key event

* fix: prepend message to .Messages slice

* fix: if selectedChannel is nil, do not handle events

* feat: better default keybindings

* fix: use != comparison operator
2021-08-31 15:18:02 +04:00

28 lines
598 B
Go

package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// NewMessagesTextView creates and returns a new messages textview.
func NewMessagesTextView(
app *tview.Application,
onMessagesTextViewInputCapture func(*tcell.EventKey) *tcell.EventKey,
) *tview.TextView {
v := tview.NewTextView()
v.
SetRegions(true).
SetDynamicColors(true).
SetWordWrap(true).
ScrollToEnd().
SetChangedFunc(func() {
app.Draw()
}).
SetInputCapture(onMessagesTextViewInputCapture).
SetBorder(true).
SetBorderPadding(0, 0, 1, 0).
SetTitleAlign(tview.AlignLeft)
return v
}