diff options
author | Joe <rbo@gmx.us> | 2024-02-01 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-02-01 20:20:20 +0100 |
commit | 2601e660db5ffb7a57e2496c24f9bbb52a0158f3 (patch) | |
tree | 1b5144ee08df2f2066c039e43c4bafe8786421d9 /src/c_init.go | |
parent | useless changes (diff) | |
download | hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.gz hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.bz2 hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.xz hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.zst hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.zip |
conf
Diffstat (limited to 'src/c_init.go')
-rw-r--r-- | src/c_init.go | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/c_init.go b/src/c_init.go index e377053..f90a4ad 100644 --- a/src/c_init.go +++ b/src/c_init.go @@ -54,14 +54,16 @@ package main import ( "os" "path/filepath" + + "gopkg.in/yaml.v3" ) type HardOpts struct { - Icon bool - Loop bool - GPG string - Perc bool - Term string + Icon bool `yaml:"icons"` + Loop bool `yaml:"loop"` + GPG string `yaml:"gpg"` + Perc bool `yaml:"percent"` + Term string `yaml:"terminal"` } // this function recurses into the specified root directory in order to load @@ -107,12 +109,11 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, } func c_load_data_dir(dir string, opts HardOpts, - ui *HardUI) (*DirsList, []error) { + ui *HardUI, load_err *[]error) (*DirsList) { ldirs := DirsList{} - var load_err []error - c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui, &load_err) - return &ldirs, load_err + c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui, load_err) + return &ldirs } // fills litems sorting with dirs last @@ -139,21 +140,30 @@ func c_load_litems(ldirs *DirsList) *ItemsList { return &litems } -func c_write_options(dir string) { - // TODO: this +func c_write_options(file string, opts HardOpts, load_err *[]error) { + data, err := yaml.Marshal(opts) + if err != nil { + *load_err = append(*load_err, err) + return + } + err = os.WriteFile(file, data, 0644) + if err != nil { + *load_err = append(*load_err, err) + } } -func c_get_options(dir string) HardOpts { +func c_get_options(dir string, load_err *[]error) HardOpts { opts := HardOpts{} file := dir + "/" + CONF_FILE_NAME if _, err := os.Stat(file); os.IsNotExist(err) { - c_write_options(file) - return DEFAULT_OPS + c_write_options(file, DEFAULT_OPTS, load_err) + return DEFAULT_OPTS } opts, err := c_parse_opts(file) if err != nil { - // TODO: this + *load_err = append(*load_err, err) + return DEFAULT_OPTS } return opts } |