discordo/ui/inputfields.go
rigormorrtiss e2b144d3a6 Add clipboard support (#21)
* Add clipboard support

* Add "Clipboard" heading to "Getting Started" sect.
2021-08-08 22:31:49 +04:00

32 lines
919 B
Go

package ui
import (
"github.com/atotto/clipboard"
"github.com/gdamore/tcell/v2"
"github.com/rigormorrtiss/discordo/util"
"github.com/rivo/tview"
)
func NewMessageInputField(onMessageInputFieldDone func(key tcell.Key), theme *util.Theme) *tview.InputField {
messageInputField := tview.NewInputField()
messageInputField.
SetPlaceholder("Message...").
SetFieldWidth(0).
SetDoneFunc(onMessageInputFieldDone).
SetFieldBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
SetPlaceholderTextColor(tcell.GetColor(theme.InputFieldPlaceholderForeground)).
SetBackgroundColor(tcell.GetColor(theme.InputFieldBackground)).
SetBorder(true).
SetBorderPadding(0, 0, 1, 1).
SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlV {
text, _ := clipboard.ReadAll()
messageInputField.SetText(text)
}
return event
})
return messageInputField
}