diff --git a/config.go b/config.go index 709c117..89466d0 100644 --- a/config.go +++ b/config.go @@ -9,35 +9,54 @@ import ( const name = "discordo" -type CommonThemeConfig struct { - Border bool `yaml:"border"` - BorderPadding [4]int `yaml:"border_padding,flow"` -} +type ( + CommonKeysConfig struct { + Cancel string `yaml:"cancel"` + } -type GuildsTreeThemeConfig struct { - CommonThemeConfig `yaml:",inline"` - Graphics bool `yaml:"graphics"` -} + MessagesTextKeysConfig struct { + CommonKeysConfig `yaml:",inline"` + Reply string `yaml:"reply"` + ReplyMention string `yaml:"reply_mention"` + } -type MessagesTextThemeConfig struct { - CommonThemeConfig `yaml:",inline"` -} + KeysConfig struct { + MessagesText MessagesTextKeysConfig `yaml:"messages_text"` + } +) -type MessageInputThemeConfig struct { - CommonThemeConfig `yaml:",inline"` -} +type ( + CommonThemeConfig struct { + Border bool `yaml:"border"` + BorderPadding [4]int `yaml:"border_padding,flow"` + } -type ThemeConfig struct { - GuildsTree GuildsTreeThemeConfig `yaml:"guilds_tree"` - MessagesText MessagesTextThemeConfig `yaml:"messages_text"` - MessageInput MessageInputThemeConfig `yaml:"message_input"` -} + GuildsTreeThemeConfig struct { + CommonThemeConfig `yaml:",inline"` + Graphics bool `yaml:"graphics"` + } + + MessagesTextThemeConfig struct { + CommonThemeConfig `yaml:",inline"` + } + + MessageInputThemeConfig struct { + CommonThemeConfig `yaml:",inline"` + } + + ThemeConfig struct { + GuildsTree GuildsTreeThemeConfig `yaml:"guilds_tree"` + MessagesText MessagesTextThemeConfig `yaml:"messages_text"` + MessageInput MessageInputThemeConfig `yaml:"message_input"` + } +) type Config struct { Mouse bool `yaml:"mouse"` MessagesLimit uint `yaml:"messages_limit"` Timestamps bool `yaml:"timestamps"` + Keys KeysConfig `yaml:"keys"` Theme ThemeConfig `yaml:"theme"` } @@ -52,25 +71,38 @@ func newConfig() (*Config, error) { return nil, err } - common := CommonThemeConfig{ + commonTheme := CommonThemeConfig{ Border: true, BorderPadding: [...]int{0, 0, 1, 1}, } + commonKeys := CommonKeysConfig{ + Cancel: "Esc", + } + c := Config{ Mouse: true, + Timestamps: false, MessagesLimit: 50, + Keys: KeysConfig{ + MessagesText: MessagesTextKeysConfig{ + CommonKeysConfig: commonKeys, + Reply: "Rune[r]", + ReplyMention: "Rune[R]", + }, + }, + Theme: ThemeConfig{ GuildsTree: GuildsTreeThemeConfig{ - CommonThemeConfig: common, + CommonThemeConfig: commonTheme, Graphics: true, }, MessagesText: MessagesTextThemeConfig{ - CommonThemeConfig: common, + CommonThemeConfig: commonTheme, }, MessageInput: MessageInputThemeConfig{ - CommonThemeConfig: common, + CommonThemeConfig: commonTheme, }, }, } diff --git a/message_input.go b/message_input.go index a25d4e8..0e5530f 100644 --- a/message_input.go +++ b/message_input.go @@ -16,6 +16,7 @@ func newMessageInput() *MessageInput { mi.SetDoneFunc(mi.onDone) + mi.SetTitleAlign(tview.AlignLeft) mi.SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor) mi.SetBorder(cfg.Theme.MessageInput.Border) padding := cfg.Theme.MessageInput.BorderPadding diff --git a/messages_text.go b/messages_text.go index 3e4c033..68208cd 100644 --- a/messages_text.go +++ b/messages_text.go @@ -6,6 +6,7 @@ import ( "time" "github.com/diamondburned/arikawa/v3/discord" + "github.com/gdamore/tcell/v2" "github.com/rivo/tview" ) @@ -22,10 +23,13 @@ func newMessagesText() *MessagesText { mt.SetDynamicColors(true) mt.SetRegions(true) + mt.SetToggleHighlights(true) mt.SetWordWrap(true) mt.ScrollToEnd() mt.SetHighlightedFunc(mt.onHighlighted) + mt.SetInputCapture(mt.onInputCapture) + mt.SetTitleAlign(tview.AlignLeft) mt.SetBorder(cfg.Theme.MessagesText.Border) padding := cfg.Theme.MessagesText.BorderPadding @@ -104,3 +108,37 @@ func (mt *MessagesText) onHighlighted(added, removed, remaining []string) { mt.selectedMessage = m } + +func (mt *MessagesText) onInputCapture(event *tcell.EventKey) *tcell.EventKey { + switch event.Name() { + case cfg.Keys.MessagesText.Reply: + mt.replyAction(false) + return nil + case cfg.Keys.MessagesText.ReplyMention: + mt.replyAction(true) + return nil + case cfg.Keys.MessagesText.Cancel: + // TODO + return nil + } + + return event +} + +func (mt *MessagesText) replyAction(mention bool) { + if mt.selectedMessage == nil { + return + } + + var title string + if mention { + title += "[@] Replying to " + } else { + title += "Replying to " + } + + title += mt.selectedMessage.Author.Tag() + messageInput.SetTitle(title) + + app.SetFocus(messageInput) +}