|
@@ -1,6 +1,8 @@
|
|
|
package main
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "log"
|
|
|
|
|
+
|
|
|
"github.com/gdamore/tcell/v2"
|
|
"github.com/gdamore/tcell/v2"
|
|
|
"github.com/rivo/tview"
|
|
"github.com/rivo/tview"
|
|
|
)
|
|
)
|
|
@@ -14,35 +16,36 @@ func newMessageInput() *MessageInput {
|
|
|
InputField: tview.NewInputField(),
|
|
InputField: tview.NewInputField(),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mi.SetDoneFunc(mi.onDone)
|
|
|
|
|
|
|
+ mi.SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
|
|
|
|
|
+ mi.SetInputCapture(mi.onInputCapture)
|
|
|
|
|
|
|
|
mi.SetTitleAlign(tview.AlignLeft)
|
|
mi.SetTitleAlign(tview.AlignLeft)
|
|
|
- mi.SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor)
|
|
|
|
|
- mi.SetBorder(cfg.Theme.MessageInput.Border)
|
|
|
|
|
|
|
+
|
|
|
padding := cfg.Theme.MessageInput.BorderPadding
|
|
padding := cfg.Theme.MessageInput.BorderPadding
|
|
|
|
|
+ mi.SetBorder(cfg.Theme.MessageInput.Border)
|
|
|
mi.SetBorderPadding(padding[0], padding[1], padding[2], padding[3])
|
|
mi.SetBorderPadding(padding[0], padding[1], padding[2], padding[3])
|
|
|
|
|
|
|
|
return mi
|
|
return mi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (mi *MessageInput) onDone(key tcell.Key) {
|
|
|
|
|
- switch key {
|
|
|
|
|
- case tcell.KeyEnter:
|
|
|
|
|
- go mi.sendMessage()
|
|
|
|
|
- case tcell.KeyEscape:
|
|
|
|
|
- // Reset the message input.
|
|
|
|
|
- mi.SetText("")
|
|
|
|
|
|
|
+func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|
|
|
|
+ switch event.Name() {
|
|
|
|
|
+ case cfg.Keys.MessageInput.Send:
|
|
|
|
|
+ mi.sendAction()
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return event
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (mi *MessageInput) sendMessage() error {
|
|
|
|
|
|
|
+func (mi *MessageInput) sendAction() {
|
|
|
text := mi.GetText()
|
|
text := mi.GetText()
|
|
|
_, err := discordState.SendMessage(guildsTree.selectedChannel.ID, text)
|
|
_, err := discordState.SendMessage(guildsTree.selectedChannel.ID, text)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return err
|
|
|
|
|
|
|
+ log.Println(err)
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Reset the message input.
|
|
// Reset the message input.
|
|
|
mi.SetText("")
|
|
mi.SetText("")
|
|
|
- return nil
|
|
|
|
|
}
|
|
}
|