messages.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package ui
  2. import (
  3. "github.com/gdamore/tcell/v2"
  4. "github.com/rivo/tview"
  5. )
  6. // NewMessagesView creates and returns a new messages textview.
  7. func NewMessagesView(
  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. }
  26. // NewMessageInputField creates and returns a new message inputfield.
  27. func NewMessageInputField(
  28. onMessageInputFieldInputCapture func(*tcell.EventKey) *tcell.EventKey,
  29. ) *tview.InputField {
  30. i := tview.NewInputField()
  31. i.
  32. SetPlaceholder("Message...").
  33. SetPlaceholderTextColor(tcell.ColorWhite).
  34. SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
  35. SetInputCapture(onMessageInputFieldInputCapture).
  36. SetBorder(true).
  37. SetBorderPadding(0, 0, 1, 0).
  38. SetTitleAlign(tview.AlignLeft)
  39. return i
  40. }