textviews.go 598 B

12345678910111213141516171819202122232425262728
  1. package ui
  2. import (
  3. "github.com/gdamore/tcell/v2"
  4. "github.com/rivo/tview"
  5. )
  6. // NewMessagesTextView creates and returns a new messages textview.
  7. func NewMessagesTextView(
  8. app *tview.Application,
  9. onMessagesTextViewInputCapture func(*tcell.EventKey) *tcell.EventKey,
  10. ) *tview.TextView {
  11. v := tview.NewTextView()
  12. v.
  13. SetRegions(true).
  14. SetDynamicColors(true).
  15. SetWordWrap(true).
  16. ScrollToEnd().
  17. SetChangedFunc(func() {
  18. app.Draw()
  19. }).
  20. SetInputCapture(onMessagesTextViewInputCapture).
  21. SetBorder(true).
  22. SetBorderPadding(0, 0, 1, 0).
  23. SetTitleAlign(tview.AlignLeft)
  24. return v
  25. }