inputfields.go 883 B

1234567891011121314151617181920212223242526272829303132
  1. package ui
  2. import (
  3. "github.com/atotto/clipboard"
  4. "github.com/gdamore/tcell/v2"
  5. "github.com/rigormorrtiss/discordo/util"
  6. "github.com/rivo/tview"
  7. )
  8. func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key), theme *util.Theme) *tview.InputField {
  9. messageInputField := tview.NewInputField()
  10. messageInputField.
  11. SetPlaceholder("Message...").
  12. SetFieldWidth(0).
  13. SetDoneFunc(onMessageInputFieldDone).
  14. SetFieldBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
  15. SetBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
  16. SetBorder(true).
  17. SetBorderPadding(0, 0, 1, 1).
  18. SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
  19. if event.Key() == tcell.KeyCtrlV {
  20. text, _ := clipboard.ReadAll()
  21. text = messageInputField.GetText() + text
  22. messageInputField.SetText(text)
  23. }
  24. return event
  25. })
  26. return messageInputField
  27. }