keybindings
This commit is contained in:
parent
433f9feb58
commit
8caad25ba5
4 changed files with 77 additions and 72 deletions
82
config.go
82
config.go
|
|
@ -10,15 +10,10 @@ import (
|
|||
const name = "discordo"
|
||||
|
||||
type (
|
||||
CommonKeysConfig struct {
|
||||
Cancel string `yaml:"cancel"`
|
||||
}
|
||||
|
||||
MessagesTextKeysConfig struct {
|
||||
CommonKeysConfig `yaml:",inline"`
|
||||
|
||||
Reply string `yaml:"reply"`
|
||||
ReplyMention string `yaml:"reply_mention"`
|
||||
SelectReply string `yaml:"select_reply"`
|
||||
|
||||
SelectPrevious string `yaml:"select_previous"`
|
||||
SelectNext string `yaml:"select_next"`
|
||||
|
|
@ -27,44 +22,36 @@ type (
|
|||
}
|
||||
|
||||
MessageInputKeysConfig struct {
|
||||
CommonKeysConfig `yaml:",inline"`
|
||||
|
||||
Send string `yaml:"send"`
|
||||
LaunchEditor string `yaml:"launch_editor"`
|
||||
}
|
||||
|
||||
KeysConfig struct {
|
||||
Cancel string `yaml:"cancel"`
|
||||
|
||||
MessagesText MessagesTextKeysConfig `yaml:"messages_text"`
|
||||
MessageInput MessageInputKeysConfig `yaml:"message_input"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
CommonThemeConfig struct {
|
||||
GuildsTreeThemeConfig struct {
|
||||
Graphics bool `yaml:"graphics"`
|
||||
}
|
||||
|
||||
MessagesTextThemeConfig struct {
|
||||
AuthorColor string `yaml:"author_color"`
|
||||
}
|
||||
|
||||
MessageInputThemeConfig struct{}
|
||||
|
||||
ThemeConfig struct {
|
||||
Border bool `yaml:"border"`
|
||||
BorderPadding [4]int `yaml:"border_padding,flow"`
|
||||
|
||||
TitleColor string `yaml:"title_color"`
|
||||
BackgroundColor string `yaml:"background_color"`
|
||||
}
|
||||
|
||||
GuildsTreeThemeConfig struct {
|
||||
CommonThemeConfig `yaml:",inline"`
|
||||
|
||||
Graphics bool `yaml:"graphics"`
|
||||
}
|
||||
|
||||
MessagesTextThemeConfig struct {
|
||||
CommonThemeConfig `yaml:",inline"`
|
||||
|
||||
AuthorColor string `yaml:"author_color"`
|
||||
}
|
||||
|
||||
MessageInputThemeConfig struct {
|
||||
CommonThemeConfig `yaml:",inline"`
|
||||
}
|
||||
|
||||
ThemeConfig struct {
|
||||
GuildsTree GuildsTreeThemeConfig `yaml:"guilds_tree"`
|
||||
MessagesText MessagesTextThemeConfig `yaml:"messages_text"`
|
||||
MessageInput MessageInputThemeConfig `yaml:"message_input"`
|
||||
|
|
@ -93,18 +80,6 @@ func newConfig() (*Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
commonTheme := CommonThemeConfig{
|
||||
Border: true,
|
||||
BorderPadding: [...]int{0, 0, 1, 1},
|
||||
|
||||
TitleColor: "default",
|
||||
BackgroundColor: "default",
|
||||
}
|
||||
|
||||
commonKeys := CommonKeysConfig{
|
||||
Cancel: "Esc",
|
||||
}
|
||||
|
||||
c := Config{
|
||||
Mouse: true,
|
||||
Timestamps: false,
|
||||
|
|
@ -112,10 +87,12 @@ func newConfig() (*Config, error) {
|
|||
Editor: "default",
|
||||
|
||||
Keys: KeysConfig{
|
||||
Cancel: "Esc",
|
||||
|
||||
MessagesText: MessagesTextKeysConfig{
|
||||
CommonKeysConfig: commonKeys,
|
||||
Reply: "Rune[r]",
|
||||
ReplyMention: "Rune[R]",
|
||||
Reply: "Rune[r]",
|
||||
ReplyMention: "Rune[R]",
|
||||
SelectReply: "Rune[s]",
|
||||
|
||||
SelectPrevious: "Up",
|
||||
SelectNext: "Down",
|
||||
|
|
@ -123,24 +100,25 @@ func newConfig() (*Config, error) {
|
|||
SelectLast: "End",
|
||||
},
|
||||
MessageInput: MessageInputKeysConfig{
|
||||
CommonKeysConfig: commonKeys,
|
||||
Send: "Enter",
|
||||
LaunchEditor: "Ctrl+E",
|
||||
Send: "Enter",
|
||||
LaunchEditor: "Ctrl+E",
|
||||
},
|
||||
},
|
||||
|
||||
Theme: ThemeConfig{
|
||||
Border: true,
|
||||
BorderPadding: [...]int{0, 0, 1, 1},
|
||||
|
||||
TitleColor: "default",
|
||||
BackgroundColor: "default",
|
||||
|
||||
GuildsTree: GuildsTreeThemeConfig{
|
||||
CommonThemeConfig: commonTheme,
|
||||
Graphics: true,
|
||||
Graphics: true,
|
||||
},
|
||||
MessagesText: MessagesTextThemeConfig{
|
||||
CommonThemeConfig: commonTheme,
|
||||
AuthorColor: "aqua",
|
||||
},
|
||||
MessageInput: MessageInputThemeConfig{
|
||||
CommonThemeConfig: commonTheme,
|
||||
AuthorColor: "aqua",
|
||||
},
|
||||
MessageInput: MessageInputThemeConfig{},
|
||||
},
|
||||
}
|
||||
path = filepath.Join(path, "config.yml")
|
||||
|
|
|
|||
|
|
@ -29,15 +29,15 @@ func newGuildsTree() *GuildsTree {
|
|||
gt.SetTopLevel(1)
|
||||
gt.SetSelectedFunc(gt.onSelected)
|
||||
|
||||
gt.SetBackgroundColor(tcell.GetColor(config.Theme.GuildsTree.BackgroundColor))
|
||||
gt.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
|
||||
|
||||
gt.SetTitle("Guilds")
|
||||
gt.SetTitleColor(tcell.GetColor(config.Theme.GuildsTree.TitleColor))
|
||||
gt.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
|
||||
gt.SetTitleAlign(tview.AlignLeft)
|
||||
|
||||
padding := config.Theme.GuildsTree.BorderPadding
|
||||
gt.SetBorder(config.Theme.GuildsTree.Border)
|
||||
gt.SetBorderPadding(padding[0], padding[1], padding[2], padding[3])
|
||||
p := config.Theme.BorderPadding
|
||||
gt.SetBorder(config.Theme.Border)
|
||||
gt.SetBorderPadding(p[0], p[1], p[2], p[3])
|
||||
|
||||
return gt
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,15 +23,15 @@ func newMessageInput() *MessageInput {
|
|||
}
|
||||
|
||||
mi.SetInputCapture(mi.onInputCapture)
|
||||
mi.SetFieldBackgroundColor(tcell.GetColor(config.Theme.MessageInput.BackgroundColor))
|
||||
mi.SetBackgroundColor(tcell.GetColor(config.Theme.MessageInput.BackgroundColor))
|
||||
mi.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
|
||||
mi.SetFieldBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
|
||||
|
||||
mi.SetTitleColor(tcell.GetColor(config.Theme.MessageInput.TitleColor))
|
||||
mi.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
|
||||
mi.SetTitleAlign(tview.AlignLeft)
|
||||
|
||||
padding := config.Theme.MessageInput.BorderPadding
|
||||
mi.SetBorder(config.Theme.MessageInput.Border)
|
||||
mi.SetBorderPadding(padding[0], padding[1], padding[2], padding[3])
|
||||
p := config.Theme.BorderPadding
|
||||
mi.SetBorder(config.Theme.Border)
|
||||
mi.SetBorderPadding(p[0], p[1], p[2], p[3])
|
||||
|
||||
return mi
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ func (mi *MessageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
case config.Keys.MessageInput.LaunchEditor:
|
||||
messageInput.launchEditorAction()
|
||||
return nil
|
||||
case config.Keys.MessageInput.Cancel:
|
||||
case config.Keys.Cancel:
|
||||
mi.reset()
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,15 +36,15 @@ func newMessagesText() *MessagesText {
|
|||
app.Draw()
|
||||
})
|
||||
|
||||
mt.SetBackgroundColor(tcell.GetColor(config.Theme.MessagesText.BackgroundColor))
|
||||
mt.SetBackgroundColor(tcell.GetColor(config.Theme.BackgroundColor))
|
||||
|
||||
mt.SetTitle("Messages")
|
||||
mt.SetTitleColor(tcell.GetColor(config.Theme.MessagesText.TitleColor))
|
||||
mt.SetTitleColor(tcell.GetColor(config.Theme.TitleColor))
|
||||
mt.SetTitleAlign(tview.AlignLeft)
|
||||
|
||||
padding := config.Theme.MessagesText.BorderPadding
|
||||
mt.SetBorder(config.Theme.MessagesText.Border)
|
||||
mt.SetBorderPadding(padding[0], padding[1], padding[2], padding[3])
|
||||
p := config.Theme.BorderPadding
|
||||
mt.SetBorder(config.Theme.Border)
|
||||
mt.SetBorderPadding(p[0], p[1], p[2], p[3])
|
||||
|
||||
return mt
|
||||
}
|
||||
|
|
@ -74,10 +74,10 @@ func (mt *MessagesText) createMessage(m *discord.Message) error {
|
|||
mt.buf.WriteByte('[')
|
||||
mt.buf.WriteString(config.Theme.MessagesText.AuthorColor)
|
||||
mt.buf.WriteByte(']')
|
||||
mt.buf.WriteString(m.Author.Username)
|
||||
mt.buf.WriteString(m.ReferencedMessage.Author.Username)
|
||||
mt.buf.WriteString("[-] ")
|
||||
|
||||
mt.buf.WriteString(discordmd.Parse(tview.Escape(m.Content)))
|
||||
mt.buf.WriteString(discordmd.Parse(tview.Escape(m.ReferencedMessage.Content)))
|
||||
mt.buf.WriteString("[::-]\n")
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,10 @@ func (mt *MessagesText) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
case config.Keys.MessagesText.SelectLast:
|
||||
mt.selectLastAction()
|
||||
return nil
|
||||
case config.Keys.MessagesText.Cancel:
|
||||
case config.Keys.MessagesText.SelectReply:
|
||||
mt.selectReplyAction()
|
||||
return nil
|
||||
case config.Keys.Cancel:
|
||||
guildsTree.selectedChannel = nil
|
||||
|
||||
messagesText.reset()
|
||||
|
|
@ -241,3 +244,27 @@ func (mt *MessagesText) selectLastAction() {
|
|||
mt.Highlight(ms[mt.selectedMessage].ID.String())
|
||||
mt.ScrollToHighlight()
|
||||
}
|
||||
|
||||
func (mt *MessagesText) selectReplyAction() {
|
||||
if mt.selectedMessage == -1 {
|
||||
return
|
||||
}
|
||||
|
||||
ms, err := discordState.Cabinet.Messages(guildsTree.selectedChannel.ID)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
ref := ms[mt.selectedMessage].ReferencedMessage
|
||||
if ref != nil {
|
||||
for i, m := range ms {
|
||||
if ref.ID == m.ID {
|
||||
mt.selectedMessage = i
|
||||
}
|
||||
}
|
||||
|
||||
mt.Highlight(ms[mt.selectedMessage].ID.String())
|
||||
mt.ScrollToHighlight()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue