| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- package config
- import (
- "github.com/BurntSushi/toml"
- "github.com/ayn2op/tview/keybind"
- )
- type Keybind struct {
- keybind.Keybind
- }
- var _ toml.Unmarshaler = (*Keybind)(nil)
- func (k *Keybind) UnmarshalTOML(value any) error {
- switch value := value.(type) {
- case string:
- k.SetKeys(value)
- case []any:
- keys := make([]string, 0, len(value))
- for _, key := range value {
- if key, ok := key.(string); ok {
- keys = append(keys, key)
- }
- }
- k.SetKeys(keys...)
- }
- // Keep displayed help key aligned with configured key(s).
- if keys := k.Keys(); len(keys) > 0 {
- k.SetHelp(keys[0], k.Help().Desc)
- }
- return nil
- }
- func newKeybind(key, desc string) Keybind {
- return Keybind{
- Keybind: keybind.NewKeybind(
- keybind.WithKeys(key),
- keybind.WithHelp(key, desc),
- ),
- }
- }
- type NavigationKeybinds struct {
- Up Keybind `toml:"up"`
- Down Keybind `toml:"down"`
- Top Keybind `toml:"top"`
- Bottom Keybind `toml:"bottom"`
- }
- type ScrollKeybinds struct {
- ScrollUp Keybind `toml:"scroll_up"`
- ScrollDown Keybind `toml:"scroll_down"`
- ScrollTop Keybind `toml:"scroll_top"`
- ScrollBottom Keybind `toml:"scroll_bottom"`
- }
- type SelectionKeybinds struct {
- SelectUp Keybind `toml:"select_up"`
- SelectDown Keybind `toml:"select_down"`
- SelectTop Keybind `toml:"select_top"`
- SelectBottom Keybind `toml:"select_bottom"`
- }
- type PickerKeybinds struct {
- NavigationKeybinds
- Select Keybind `toml:"select"`
- Cancel Keybind `toml:"cancel"`
- }
- type GuildsTreeKeybinds struct {
- NavigationKeybinds
- SelectCurrent Keybind `toml:"select_current"`
- YankID Keybind `toml:"yank_id"`
- CollapseParentNode Keybind `toml:"collapse_parent_node"`
- MoveToParentNode Keybind `toml:"move_to_parent_node"`
- ArrowUp Keybind `toml:"arrow_up"`
- ArrowDown Keybind `toml:"arrow_down"`
- ArrowLeft Keybind `toml:"arrow_left"`
- ArrowRight Keybind `toml:"arrow_right"`
- }
- type MessagesListKeybinds struct {
- SelectionKeybinds
- ScrollKeybinds
- SelectReply Keybind `toml:"select_reply"`
- Reply Keybind `toml:"reply"`
- ReplyMention Keybind `toml:"reply_mention"`
- Cancel Keybind `toml:"cancel"`
- Edit Keybind `toml:"edit"`
- Delete Keybind `toml:"delete"`
- DeleteConfirm Keybind `toml:"delete_confirm"`
- Open Keybind `toml:"open"`
- SaveImage Keybind `toml:"save_image"`
- UserInfo Keybind `toml:"user_info"`
- Search Keybind `toml:"search"`
- OpenThread Keybind `toml:"open_thread"`
- ToggleTimestamps Keybind `toml:"toggle_timestamps"`
- ToggleReplies Keybind `toml:"toggle_replies"`
- AddReaction Keybind `toml:"add_reaction"`
- ArrowUp Keybind `toml:"arrow_up"`
- ArrowDown Keybind `toml:"arrow_down"`
- ArrowLeft Keybind `toml:"arrow_left"`
- ArrowRight Keybind `toml:"arrow_right"`
- YankContent Keybind `toml:"yank_content"`
- YankURL Keybind `toml:"yank_url"`
- YankID Keybind `toml:"yank_id"`
- }
- type MessageInputKeybinds struct {
- Paste Keybind `toml:"paste"`
- Send Keybind `toml:"send"`
- Cancel Keybind `toml:"cancel"`
- TabComplete Keybind `toml:"tab_complete"`
- Undo Keybind `toml:"undo"`
- OpenEditor Keybind `toml:"open_editor"`
- OpenFilePicker Keybind `toml:"open_file_picker"`
- }
- type MentionsListKeybinds struct {
- NavigationKeybinds
- }
- type Keybinds struct {
- ToggleGuildsTree Keybind `toml:"toggle_guilds_tree"`
- ToggleChannelsPicker Keybind `toml:"toggle_channels_picker"`
- ToggleHelp Keybind `toml:"toggle_help"`
- EditConfig Keybind `toml:"edit_config"`
- Suspend Keybind `toml:"suspend"`
- AttachFile Keybind `toml:"attach_file"`
- FocusGuildsTree Keybind `toml:"focus_guilds_tree"`
- FocusMessagesList Keybind `toml:"focus_messages_list"`
- FocusMessageInput Keybind `toml:"focus_message_input"`
- FocusPrevious Keybind `toml:"focus_previous"`
- FocusNext Keybind `toml:"focus_next"`
- Picker PickerKeybinds `toml:"picker"`
- GuildsTree GuildsTreeKeybinds `toml:"guilds_tree"`
- MessagesList MessagesListKeybinds `toml:"messages_list"`
- MessageInput MessageInputKeybinds `toml:"message_input"`
- MentionsList MentionsListKeybinds `toml:"mentions_list"`
- CommandMode Keybind `toml:"command_mode"`
- Logout Keybind `toml:"logout"`
- Quit Keybind `toml:"quit"`
- }
- func defaultPickerKeybinds() PickerKeybinds {
- return PickerKeybinds{
- NavigationKeybinds: NavigationKeybinds{
- Up: newKeybind("ctrl+p", "up"),
- Down: newKeybind("ctrl+n", "down"),
- Top: newKeybind("home", "top"),
- Bottom: newKeybind("end", "bottom"),
- },
- Cancel: newKeybind("esc", "cancel"),
- Select: newKeybind("enter", "sel"),
- }
- }
- func defaultNavigationKeybinds() NavigationKeybinds {
- return NavigationKeybinds{
- Up: newKeybind("k", "up"),
- Down: newKeybind("j", "down"),
- Top: newKeybind("g", "top"),
- Bottom: newKeybind("G", "bottom"),
- }
- }
- func defaultGuildsTreeKeybinds() GuildsTreeKeybinds {
- return GuildsTreeKeybinds{
- NavigationKeybinds: defaultNavigationKeybinds(),
- SelectCurrent: newKeybind("enter", "sel"),
- YankID: newKeybind("C", "copy id"),
- CollapseParentNode: newKeybind("-", "collapse"),
- MoveToParentNode: newKeybind("p", "parent"),
- ArrowUp: newKeybind("up", "up"),
- ArrowDown: newKeybind("down", "down"),
- ArrowLeft: newKeybind("left", "left"),
- ArrowRight: newKeybind("right", "right"),
- }
- }
- func defaultMessagesListKeybinds() MessagesListKeybinds {
- return MessagesListKeybinds{
- SelectionKeybinds: SelectionKeybinds{
- SelectUp: newKeybind("k", "up"),
- SelectDown: newKeybind("j", "down"),
- SelectTop: newKeybind("g", "top"),
- SelectBottom: newKeybind("G", "bottom"),
- },
- ScrollKeybinds: ScrollKeybinds{
- ScrollUp: newKeybind("K", "scroll up"),
- ScrollDown: newKeybind("J", "scroll down"),
- ScrollTop: newKeybind("home", "scroll top"),
- ScrollBottom: newKeybind("end", "scroll bottom"),
- },
- SelectReply: newKeybind("s", "sel reply"),
- Reply: newKeybind("r", "reply"),
- ReplyMention: newKeybind("R", "@reply"),
- Cancel: newKeybind("esc", "cancel"),
- Edit: newKeybind("e", "edit"),
- Delete: newKeybind("D", "force delete"),
- DeleteConfirm: newKeybind(
- "d",
- "delete",
- ),
- Open: newKeybind("o", "open"),
- SaveImage: newKeybind("S", "save image"),
- UserInfo: newKeybind("w", "who"),
- Search: newKeybind("/", "search"),
- OpenThread: newKeybind("T", "thread"),
- ToggleTimestamps: newKeybind("t", "timestamps"),
- ToggleReplies: newKeybind("Z", "collapse replies"),
- AddReaction: newKeybind("e", "react"),
- ArrowUp: newKeybind("up", "up"),
- ArrowDown: newKeybind("down", "down"),
- ArrowLeft: newKeybind("left", "left"),
- ArrowRight: newKeybind("right", "right"),
- YankContent: newKeybind("y", "copy text"),
- YankURL: newKeybind("u", "copy url"),
- YankID: newKeybind("C", "copy id"),
- }
- }
- func defaultMessageInputKeybinds() MessageInputKeybinds {
- return MessageInputKeybinds{
- Paste: newKeybind("ctrl+v", "paste"),
- Send: newKeybind("enter", "send"),
- Cancel: newKeybind("esc", "cancel"),
- TabComplete: newKeybind("tab", "complete"),
- Undo: newKeybind("ctrl+u", "undo"),
- OpenEditor: newKeybind("ctrl+e", "editor"),
- OpenFilePicker: newKeybind("ctrl+\\", "attach"),
- }
- }
- func defaultMentionsListKeybinds() MentionsListKeybinds {
- return MentionsListKeybinds{
- NavigationKeybinds: NavigationKeybinds{
- Up: newKeybind("ctrl+p", "up"),
- Down: newKeybind("ctrl+n", "down"),
- Top: newKeybind("home", "top"),
- Bottom: newKeybind("end", "bottom"),
- },
- }
- }
- func defaultKeybinds() Keybinds {
- return Keybinds{
- ToggleGuildsTree: newKeybind("H", "toggle guilds"),
- ToggleChannelsPicker: newKeybind("c", "channels picker"),
- ToggleHelp: newKeybind("?", "help"),
- EditConfig: newKeybind("E", "edit config"),
- Suspend: newKeybind("ctrl+z", "suspend"),
- AttachFile: newKeybind("I", "attach file"),
- FocusGuildsTree: newKeybind("ctrl+g", "guilds"),
- FocusMessagesList: newKeybind("ctrl+t", "messages"),
- FocusMessageInput: newKeybind("i", "input"),
- FocusPrevious: newKeybind("h", "focus prev"),
- FocusNext: newKeybind("l", "focus next"),
- CommandMode: newKeybind(":", "command"),
- Logout: newKeybind("ctrl+d", "logout"),
- Quit: newKeybind("ctrl+c", "quit"),
- Picker: defaultPickerKeybinds(),
- GuildsTree: defaultGuildsTreeKeybinds(),
- MessagesList: defaultMessagesListKeybinds(),
- MessageInput: defaultMessageInputKeybinds(),
- MentionsList: defaultMentionsListKeybinds(),
- }
- }
|