messages.go 859 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. ) *tview.TextView {
  10. v := tview.NewTextView()
  11. v.
  12. SetRegions(true).
  13. SetDynamicColors(true).
  14. SetWordWrap(true).
  15. ScrollToEnd().
  16. SetChangedFunc(func() {
  17. app.Draw()
  18. }).
  19. SetBorder(true).
  20. SetBorderPadding(0, 0, 1, 0).
  21. SetTitleAlign(tview.AlignLeft)
  22. return v
  23. }
  24. // NewMessageInputField creates and returns a new message inputfield.
  25. func NewMessageInputField() *tview.InputField {
  26. i := tview.NewInputField()
  27. i.
  28. SetPlaceholder("Message...").
  29. SetPlaceholderTextColor(tcell.ColorWhite).
  30. SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
  31. SetBorder(true).
  32. SetBorderPadding(0, 0, 1, 0).
  33. SetTitleAlign(tview.AlignLeft)
  34. return i
  35. }