|
@@ -10,31 +10,28 @@ import (
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
type Config struct {
|
|
|
- Mouse bool `toml:"mouse"`
|
|
|
|
|
|
|
+ Mouse bool `toml:"mouse"`
|
|
|
|
|
+ MessagesLimit uint8 `toml:"messages_limit"`
|
|
|
|
|
+ Editor string `toml:"editor"`
|
|
|
|
|
|
|
|
Timestamps bool `toml:"timestamps"`
|
|
Timestamps bool `toml:"timestamps"`
|
|
|
TimestampsBeforeAuthor bool `toml:"timestamps_before_author"`
|
|
TimestampsBeforeAuthor bool `toml:"timestamps_before_author"`
|
|
|
TimestampsFormat string `toml:"timestamps_format"`
|
|
TimestampsFormat string `toml:"timestamps_format"`
|
|
|
|
|
|
|
|
- MessagesLimit uint8 `toml:"messages_limit"`
|
|
|
|
|
-
|
|
|
|
|
- Editor string `toml:"editor"`
|
|
|
|
|
-
|
|
|
|
|
Keys Keys `toml:"keys"`
|
|
Keys Keys `toml:"keys"`
|
|
|
Theme Theme `toml:"theme"`
|
|
Theme Theme `toml:"theme"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func DefaultConfig() Config {
|
|
|
|
|
- return Config{
|
|
|
|
|
- Mouse: true,
|
|
|
|
|
|
|
+func defaultConfig() *Config {
|
|
|
|
|
+ return &Config{
|
|
|
|
|
+ Mouse: true,
|
|
|
|
|
+ MessagesLimit: 50,
|
|
|
|
|
+ Editor: "default",
|
|
|
|
|
|
|
|
Timestamps: false,
|
|
Timestamps: false,
|
|
|
TimestampsBeforeAuthor: false,
|
|
TimestampsBeforeAuthor: false,
|
|
|
TimestampsFormat: time.Kitchen,
|
|
TimestampsFormat: time.Kitchen,
|
|
|
|
|
|
|
|
- MessagesLimit: 50,
|
|
|
|
|
- Editor: "default",
|
|
|
|
|
-
|
|
|
|
|
Keys: defaultKeys(),
|
|
Keys: defaultKeys(),
|
|
|
Theme: defaultTheme(),
|
|
Theme: defaultTheme(),
|
|
|
}
|
|
}
|
|
@@ -42,11 +39,10 @@ func DefaultConfig() Config {
|
|
|
|
|
|
|
|
// Reads the configuration file and parses it.
|
|
// Reads the configuration file and parses it.
|
|
|
func Load() (*Config, error) {
|
|
func Load() (*Config, error) {
|
|
|
- cfg := DefaultConfig()
|
|
|
|
|
path := filepath.Join(constants.ConfigDirPath, "config.toml")
|
|
path := filepath.Join(constants.ConfigDirPath, "config.toml")
|
|
|
f, err := os.Open(path)
|
|
f, err := os.Open(path)
|
|
|
if os.IsNotExist(err) {
|
|
if os.IsNotExist(err) {
|
|
|
- return &cfg, nil
|
|
|
|
|
|
|
+ return defaultConfig(), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -54,9 +50,10 @@ func Load() (*Config, error) {
|
|
|
}
|
|
}
|
|
|
defer f.Close()
|
|
defer f.Close()
|
|
|
|
|
|
|
|
|
|
+ var cfg *Config
|
|
|
if _, err := toml.NewDecoder(f).Decode(&cfg); err != nil {
|
|
if _, err := toml.NewDecoder(f).Decode(&cfg); err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return &cfg, nil
|
|
|
|
|
|
|
+ return cfg, nil
|
|
|
}
|
|
}
|