Преглед изворни кода

Separate YAML dictionaries in their own files

ayn2op пре 3 година
родитељ
комит
92479ad5c0
3 измењених фајлова са 104 додато и 95 уклоњено
  1. 4 95
      config/config.go
  2. 55 0
      config/keys.go
  3. 45 0
      config/theme.go

+ 4 - 95
config/config.go

@@ -9,68 +9,14 @@ import (
 
 const Name = "discordo"
 
-type (
-	MessagesTextKeysConfig struct {
-		CopyContent string `yaml:"copy_content"`
-
-		Reply        string `yaml:"reply"`
-		ReplyMention string `yaml:"reply_mention"`
-		SelectReply  string `yaml:"select_reply"`
-
-		SelectPrevious string `yaml:"select_previous"`
-		SelectNext     string `yaml:"select_next"`
-		SelectFirst    string `yaml:"select_first"`
-		SelectLast     string `yaml:"select_last"`
-	}
-
-	MessageInputKeysConfig struct {
-		Send  string `yaml:"send"`
-		Paste string `yaml:"paste"`
-
-		LaunchEditor string `yaml:"launch_editor"`
-	}
-
-	KeysConfig struct {
-		Cancel string `yaml:"cancel"`
-
-		MessagesText MessagesTextKeysConfig `yaml:"messages_text"`
-		MessageInput MessageInputKeysConfig `yaml:"message_input"`
-	}
-)
-
-type (
-	GuildsTreeThemeConfig struct {
-		Graphics bool `yaml:"graphics"`
-	}
-
-	MessagesTextThemeConfig struct {
-		AuthorColor string `yaml:"author_color"`
-	}
-
-	MessageInputThemeConfig struct{}
-
-	ThemeConfig struct {
-		Border        bool   `yaml:"border"`
-		BorderColor   string `yaml:"border_color"`
-		BorderPadding [4]int `yaml:"border_padding,flow"`
-
-		TitleColor      string `yaml:"title_color"`
-		BackgroundColor string `yaml:"background_color"`
-
-		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"`
 	Editor        string `yaml:"editor"`
 
-	Keys  KeysConfig  `yaml:"keys"`
-	Theme ThemeConfig `yaml:"theme"`
+	Keys  Keys  `yaml:"keys"`
+	Theme Theme `yaml:"theme"`
 }
 
 func new() Config {
@@ -80,45 +26,8 @@ func new() Config {
 		MessagesLimit: 50,
 		Editor:        "default",
 
-		Keys: KeysConfig{
-			Cancel: "Esc",
-
-			MessagesText: MessagesTextKeysConfig{
-				CopyContent: "Rune[c]",
-
-				Reply:        "Rune[r]",
-				ReplyMention: "Rune[R]",
-				SelectReply:  "Rune[s]",
-
-				SelectPrevious: "Up",
-				SelectNext:     "Down",
-				SelectFirst:    "Home",
-				SelectLast:     "End",
-			},
-			MessageInput: MessageInputKeysConfig{
-				Send: "Enter",
-
-				Paste:        "Ctrl+V",
-				LaunchEditor: "Ctrl+E",
-			},
-		},
-
-		Theme: ThemeConfig{
-			Border:        true,
-			BorderColor:   "default",
-			BorderPadding: [...]int{0, 0, 1, 1},
-
-			TitleColor:      "default",
-			BackgroundColor: "default",
-
-			GuildsTree: GuildsTreeThemeConfig{
-				Graphics: true,
-			},
-			MessagesText: MessagesTextThemeConfig{
-				AuthorColor: "aqua",
-			},
-			MessageInput: MessageInputThemeConfig{},
-		},
+		Keys:  newKeys(),
+		Theme: newTheme(),
 	}
 }
 

+ 55 - 0
config/keys.go

@@ -0,0 +1,55 @@
+package config
+
+type (
+	MessagesTextKeys struct {
+		CopyContent string `yaml:"copy_content"`
+
+		Reply        string `yaml:"reply"`
+		ReplyMention string `yaml:"reply_mention"`
+		SelectReply  string `yaml:"select_reply"`
+
+		SelectPrevious string `yaml:"select_previous"`
+		SelectNext     string `yaml:"select_next"`
+		SelectFirst    string `yaml:"select_first"`
+		SelectLast     string `yaml:"select_last"`
+	}
+
+	MessageInputKeys struct {
+		Send  string `yaml:"send"`
+		Paste string `yaml:"paste"`
+
+		LaunchEditor string `yaml:"launch_editor"`
+	}
+)
+
+type Keys struct {
+	Cancel string `yaml:"cancel"`
+
+	MessagesText MessagesTextKeys `yaml:"messages_text"`
+	MessageInput MessageInputKeys `yaml:"message_input"`
+}
+
+func newKeys() Keys {
+	return Keys{
+		Cancel: "Esc",
+
+		MessagesText: MessagesTextKeys{
+			CopyContent: "Rune[c]",
+
+			Reply:        "Rune[r]",
+			ReplyMention: "Rune[R]",
+			SelectReply:  "Rune[s]",
+
+			SelectPrevious: "Up",
+			SelectNext:     "Down",
+			SelectFirst:    "Home",
+			SelectLast:     "End",
+		},
+		MessageInput: MessageInputKeys{
+			Send: "Enter",
+
+			Paste:        "Ctrl+V",
+			LaunchEditor: "Ctrl+E",
+		},
+	}
+}

+ 45 - 0
config/theme.go

@@ -0,0 +1,45 @@
+package config
+
+type (
+	GuildsTreeTheme struct {
+		Graphics bool `yaml:"graphics"`
+	}
+
+	MessagesTextTheme struct {
+		AuthorColor string `yaml:"author_color"`
+	}
+
+	MessageInputTheme struct{}
+)
+
+type Theme struct {
+	Border        bool   `yaml:"border"`
+	BorderColor   string `yaml:"border_color"`
+	BorderPadding [4]int `yaml:"border_padding,flow"`
+
+	TitleColor      string `yaml:"title_color"`
+	BackgroundColor string `yaml:"background_color"`
+
+	GuildsTree   GuildsTreeTheme   `yaml:"guilds_tree"`
+	MessagesText MessagesTextTheme `yaml:"messages_text"`
+	MessageInput MessageInputTheme `yaml:"message_input"`
+}
+
+func newTheme() Theme {
+	return Theme{
+		Border:        true,
+		BorderColor:   "default",
+		BorderPadding: [...]int{0, 0, 1, 1},
+
+		TitleColor:      "default",
+		BackgroundColor: "default",
+
+		GuildsTree: GuildsTreeTheme{
+			Graphics: true,
+		},
+		MessagesText: MessagesTextTheme{
+			AuthorColor: "aqua",
+		},
+		MessageInput: MessageInputTheme{},
+	}
+}