diff --git a/config.go b/config.go index 3b7cb21..33c34e8 100644 --- a/config.go +++ b/config.go @@ -12,62 +12,24 @@ const userAgent = "" + "AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/92.0.4515.131 Safari/537.36" -type keybindingsChannelsTree struct { - Focus string -} - -type keybindingsMessagesView struct { - Focus string - SelectPrevious string - SelectNext string - SelectFirst string - SelectLast string - Reply string - ReplyMention string -} - -type keybindingsMessageInputField struct { - Focus string -} - type keybindings struct { - ChannelsTree keybindingsChannelsTree - MessagesView keybindingsMessagesView - MessageInputField keybindingsMessageInputField -} + FocusChannelsTree string `toml:"focus_channels_tree"` + FocusMessagesView string `toml:"focus_messages_view"` + FocusMessageInputField string `toml:"focus_message_input_field"` -type themeBackground struct { - // Main background color for primitives. - Primitive string - // Background color for contrasting elements. - Contrast string - // Background color for even more contrasting elements. - MoreContrast string -} - -type themeText struct { - // Primary text. - Primary string - // Secondary text (e.g. labels). - Secondary string - // Tertiary text (e.g. subtitles, notes). - Tertiary string - // Text on primary-colored backgrounds. - Inverse string - // Secondary text on ContrastBackgroundColor-colored backgrounds. - ContrastSecondary string + SelectPreviousMessage string `toml:"select_previous_message"` + SelectNextMessage string `toml:"select_next_message"` + SelectFirstMessage string `toml:"select_first_message"` + SelectLastMessage string `toml:"select_last_message"` + ReplySelectedMessage string `toml:"reply_selected_message"` + MentionReplySelectedMessage string `toml:"mention_reply_selected_message"` } type theme struct { - // Box borders. - Border string - // Box titles. - Title string - // Graphics. - Graphics string - - Background themeBackground - Text themeText + Border string `toml:"border"` + Title string `toml:"title"` + Background string `toml:"background"` + Text string `toml:"text"` } type borders struct { @@ -93,14 +55,15 @@ type borders struct { } type config struct { - Token string - UserAgent string - Mouse bool - Notifications bool - GetMessagesLimit int - Theme theme - Keybindings keybindings - Borders borders + Token string `toml:"token"` + UserAgent string `toml:"user_agent"` + Mouse bool `toml:"mouse"` + Notifications bool `toml:"notifications"` + GetMessagesLimit int `toml:"get_messages_limit"` + + Theme theme `toml:"theme"` + Keybindings keybindings `toml:"keybindings"` + Borders borders `toml:"borders"` } func loadConfig() *config { @@ -124,38 +87,22 @@ func loadConfig() *config { c.UserAgent = userAgent c.GetMessagesLimit = 50 c.Theme = theme{ - Border: "white", - Title: "white", - Graphics: "white", - Background: themeBackground{ - Primitive: "black", - Contrast: "blue", - MoreContrast: "green", - }, - Text: themeText{ - Primary: "white", - Secondary: "yellow", - Tertiary: "green", - Inverse: "blue", - ContrastSecondary: "darkcyan", - }, + Border: "white", + Title: "cyan", + Background: "black", + Text: "white", } c.Keybindings = keybindings{ - ChannelsTree: keybindingsChannelsTree{ - Focus: "Alt+Left", - }, - MessagesView: keybindingsMessagesView{ - Focus: "Alt+Right", - SelectPrevious: "Up", - SelectNext: "Down", - SelectFirst: "Home", - SelectLast: "End", - Reply: "Rune[r]", - ReplyMention: "Rune[R]", - }, - MessageInputField: keybindingsMessageInputField{ - Focus: "Alt+Down", - }, + FocusChannelsTree: "Alt+Left", + FocusMessagesView: "Alt+Right", + FocusMessageInputField: "Alt+Down", + + SelectPreviousMessage: "Up", + SelectNextMessage: "Down", + SelectFirstMessage: "Home", + SelectLastMessage: "End", + ReplySelectedMessage: "Rune[r]", + MentionReplySelectedMessage: "Rune[R]", } c.Borders = tview.Borders diff --git a/main.go b/main.go index 78d0894..7b8a9ee 100644 --- a/main.go +++ b/main.go @@ -25,17 +25,16 @@ func main() { conf = loadConfig() tview.Borders = conf.Borders - tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(conf.Theme.Background.Primitive) - tview.Styles.ContrastBackgroundColor = tcell.GetColor(conf.Theme.Background.Contrast) - tview.Styles.MoreContrastBackgroundColor = tcell.GetColor(conf.Theme.Background.MoreContrast) + tview.Styles.PrimitiveBackgroundColor = tcell.GetColor(conf.Theme.Background) + tview.Styles.ContrastBackgroundColor = tcell.GetColor(conf.Theme.Background) + tview.Styles.MoreContrastBackgroundColor = tcell.GetColor(conf.Theme.Background) tview.Styles.BorderColor = tcell.GetColor(conf.Theme.Border) tview.Styles.TitleColor = tcell.GetColor(conf.Theme.Title) - tview.Styles.GraphicsColor = tcell.GetColor(conf.Theme.Graphics) - tview.Styles.PrimaryTextColor = tcell.GetColor(conf.Theme.Text.Primary) - tview.Styles.SecondaryTextColor = tcell.GetColor(conf.Theme.Text.Secondary) - tview.Styles.TertiaryTextColor = tcell.GetColor(conf.Theme.Text.Tertiary) - tview.Styles.InverseTextColor = tcell.GetColor(conf.Theme.Text.Inverse) - tview.Styles.ContrastSecondaryTextColor = tcell.GetColor(conf.Theme.Text.ContrastSecondary) + tview.Styles.PrimaryTextColor = tcell.GetColor(conf.Theme.Text) + tview.Styles.SecondaryTextColor = tcell.GetColor(conf.Theme.Text) + tview.Styles.TertiaryTextColor = tcell.GetColor(conf.Theme.Text) + tview.Styles.InverseTextColor = tcell.GetColor(conf.Theme.Text) + tview.Styles.ContrastSecondaryTextColor = tcell.GetColor(conf.Theme.Text) app = newApp() channelsTree = newChannelsTree() diff --git a/ui.go b/ui.go index d2aa6b3..9da5b76 100644 --- a/ui.go +++ b/ui.go @@ -25,13 +25,13 @@ func newApp() *tview.Application { func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey { switch e.Name() { - case conf.Keybindings.ChannelsTree.Focus: + case conf.Keybindings.FocusChannelsTree: app.SetFocus(channelsTree) return nil - case conf.Keybindings.MessagesView.Focus: + case conf.Keybindings.FocusMessagesView: app.SetFocus(messagesView) return nil - case conf.Keybindings.MessageInputField.Focus: + case conf.Keybindings.FocusMessageInputField: app.SetFocus(messageInputField) return nil } @@ -137,7 +137,7 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { } switch e.Name() { - case conf.Keybindings.MessagesView.SelectPrevious: + case conf.Keybindings.SelectPreviousMessage: if len(messagesView.GetHighlights()) == 0 { selectedMessage = len(ms) - 1 } else { @@ -151,7 +151,7 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { Highlight(ms[selectedMessage].ID). ScrollToHighlight() return nil - case conf.Keybindings.MessagesView.SelectNext: + case conf.Keybindings.SelectNextMessage: if len(messagesView.GetHighlights()) == 0 { selectedMessage = len(ms) - 1 } else { @@ -165,19 +165,19 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { Highlight(ms[selectedMessage].ID). ScrollToHighlight() return nil - case conf.Keybindings.MessagesView.SelectFirst: + case conf.Keybindings.SelectFirstMessage: selectedMessage = 0 messagesView. Highlight(ms[selectedMessage].ID). ScrollToHighlight() return nil - case conf.Keybindings.MessagesView.SelectLast: + case conf.Keybindings.SelectLastMessage: selectedMessage = len(ms) - 1 messagesView. Highlight(ms[selectedMessage].ID). ScrollToHighlight() return nil - case conf.Keybindings.MessagesView.Reply: + case conf.Keybindings.ReplySelectedMessage: hs := messagesView.GetHighlights() if len(hs) == 0 { return nil @@ -187,7 +187,7 @@ func onMessagesViewInputCapture(e *tcell.EventKey) *tcell.EventKey { messageInputField.SetTitle("Replying to " + m.Author.Username) app.SetFocus(messageInputField) return nil - case conf.Keybindings.MessagesView.ReplyMention: + case conf.Keybindings.MentionReplySelectedMessage: hs := messagesView.GetHighlights() if len(hs) == 0 { return nil @@ -217,11 +217,6 @@ func newMessageInputField() *tview.InputField { } func onMessageInputFieldInputCapture(e *tcell.EventKey) *tcell.EventKey { - // If the "Alt" modifier key is pressed, do not handle the event. - if e.Modifiers() == tcell.ModAlt { - return nil - } - switch e.Key() { case tcell.KeyEnter: if selectedChannel == nil {