aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-02-01 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-02-01 20:20:20 +0100
commit2601e660db5ffb7a57e2496c24f9bbb52a0158f3 (patch)
tree1b5144ee08df2f2066c039e43c4bafe8786421d9
parentuseless changes (diff)
downloadhardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.gz
hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.bz2
hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.xz
hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.tar.zst
hardflip-2601e660db5ffb7a57e2496c24f9bbb52a0158f3.zip
conf
-rw-r--r--src/c_defs.go4
-rw-r--r--src/c_hardflip.go12
-rw-r--r--src/c_init.go40
-rw-r--r--src/c_lhosts.go1
-rw-r--r--src/c_parse.go6
-rw-r--r--src/c_utils.go19
-rw-r--r--src/i_events.go5
-rw-r--r--src/i_ui.go23
8 files changed, 59 insertions, 51 deletions
diff --git a/src/c_defs.go b/src/c_defs.go
index da3ab77..2fd8c6a 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -95,10 +95,10 @@ var (
DIRS_ICONS = [2]string{" ", " "}
)
-var DEFAULT_OPS = HardOpts{
+var DEFAULT_OPTS = HardOpts{
true,
true,
- "",
+ "6FF3AD08C158D2E163B77CFA0EAB41FC2D9F762A",
false,
"",
}
diff --git a/src/c_hardflip.go b/src/c_hardflip.go
index e4eec84..68e4f10 100644
--- a/src/c_hardflip.go
+++ b/src/c_hardflip.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_hardflip.go
- * Wed Jan 31 15:23:27 2024
+ * Thu Feb 01 14:53:19 2024
* Joe
*
* the main
@@ -63,14 +63,6 @@ type HardData struct {
}
func main() {
- c_get_options(c_get_conf_dir(nil))
data_dir := c_get_data_dir(nil)
- opts := HardOpts{
- true,
- true,
- "6FF3AD08C158D2E163B77CFA0EAB41FC2D9F762A",
- false,
- "",
- }
- i_ui(data_dir, opts)
+ i_ui(data_dir)
}
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
}
diff --git a/src/c_lhosts.go b/src/c_lhosts.go
index 654da13..e0ad58c 100644
--- a/src/c_lhosts.go
+++ b/src/c_lhosts.go
@@ -72,6 +72,7 @@ type HostNode struct {
Height uint16 `yaml:"height"`
Dynamic bool `yaml:"dynamic"`
Note string `yaml:"note"`
+ // TODO: rdp drive
Filename string
Parent *DirsNode
next *HostNode
diff --git a/src/c_parse.go b/src/c_parse.go
index 53249cf..a032381 100644
--- a/src/c_parse.go
+++ b/src/c_parse.go
@@ -52,8 +52,9 @@
package main
import (
- "os"
"errors"
+ "fmt"
+ "os"
"gopkg.in/yaml.v3"
)
@@ -65,7 +66,7 @@ func c_parse_opts(file string) (HardOpts, error) {
if err != nil {
return opts, err
}
- err = yaml.Unmarshal(yaml_file, opts)
+ err = yaml.Unmarshal(yaml_file, &opts)
return opts, err
}
@@ -77,6 +78,7 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) {
return nil, err
}
if err := yaml.Unmarshal(yaml_file, &host); err != nil {
+ err = errors.New(fmt.Sprintf("%s: %v", file, err))
return nil, err
}
if len(host.Name) == 0 {
diff --git a/src/c_utils.go b/src/c_utils.go
index 7ec70c0..3b94cc1 100644
--- a/src/c_utils.go
+++ b/src/c_utils.go
@@ -52,6 +52,7 @@
package main
import (
+ "errors"
"fmt"
"os"
"os/exec"
@@ -62,15 +63,13 @@ import (
// not exist
// the first path being checked is $XDG_CONFIG_HOME then $HOME/.config
// it returns the full data directory path
-func c_get_conf_dir(ui *HardUI) string {
+func c_get_conf_dir(load_err *[]error) string {
var ptr string
var home string
if home = os.Getenv("HOME"); len(home) == 0 {
- if ui == nil {
- c_die("env variable HOME not defined", nil)
- }
- c_error_mode("env variable HOME not defined", nil, ui)
+ *load_err = append(*load_err,
+ errors.New("env variable HOME not defined"))
return ""
}
xdg_home := os.Getenv("XDG_CONFIG_HOME")
@@ -83,16 +82,10 @@ func c_get_conf_dir(ui *HardUI) string {
ptr += "/" + CONF_DIR_NAME
if _, err := os.Stat(ptr); os.IsNotExist(err) {
if err := os.MkdirAll(ptr, os.ModePerm); err != nil {
- if ui == nil {
- c_die("could not create path " + ptr, err)
- }
- c_error_mode("could not create path" + ptr, err, ui)
+ *load_err = append(*load_err, err)
}
} else if err != nil {
- if ui == nil {
- c_die("could read path " + ptr, err)
- }
- c_error_mode("could read path" + ptr, err, ui)
+ *load_err = append(*load_err, err)
return ""
}
return ptr
diff --git a/src/i_events.go b/src/i_events.go
index 4a003de..974de32 100644
--- a/src/i_events.go
+++ b/src/i_events.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_events.go
- * Wed Jan 31 15:23:23 2024
+ * Wed Jan 31 18:17:20 2024
* Joe
*
* events in the code
@@ -172,8 +172,9 @@ func i_reload_data(data *HardData) {
}
g_load_count = -1
data.ldirs, data.litems, data.load_err = i_load_ui(data.data_dir, data.opts,
- &data.ui)
+ &data.ui, &data.load_err)
data.folds = make(map[*DirsNode]*ItemsList)
+ // TODO: reload conf
}
func i_delete_dir(data *HardData) error {
diff --git a/src/i_ui.go b/src/i_ui.go
index 69563e0..7d25d93 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -321,21 +321,23 @@ func i_draw_load_ui(ui *HardUI) {
func i_load_ui(data_dir string,
opts HardOpts,
- ui *HardUI) (*DirsList, *ItemsList, []error) {
+ ui *HardUI,
+ load_err *[]error) (*DirsList, *ItemsList, []error) {
ui.mode = LOAD_MODE
- ldirs, load_err := c_load_data_dir(data_dir, opts, ui)
+ ldirs := c_load_data_dir(data_dir, opts, ui, load_err)
litems := c_load_litems(ldirs)
if ui.mode != ERROR_MODE {
ui.mode = NORMAL_MODE
}
- if len(load_err) == 0 {
- load_err = nil
+ if len(*load_err) == 0 {
+ *load_err = nil
}
- return ldirs, litems, load_err
+ return ldirs, litems, *load_err
}
-func i_ui(data_dir string, opts HardOpts) {
+func i_ui(data_dir string) {
ui := HardUI{}
+ opts := HardOpts{}
var err error
ui.s, err = tcell.NewScreen()
@@ -368,7 +370,14 @@ func i_ui(data_dir string, opts HardOpts) {
Foreground(tcell.ColorBlue).Dim(true)
ui.s.SetStyle(ui.style[STYLE_DEF])
ui.dim[W], ui.dim[H], _ = term.GetSize(0)
- ldirs, litems, load_err := i_load_ui(data_dir, opts, &ui)
+ var load_err []error
+ conf_dir := c_get_conf_dir(&load_err)
+ if conf_dir == "" {
+ opts = DEFAULT_OPTS
+ } else {
+ opts = c_get_options(conf_dir, &load_err)
+ }
+ ldirs, litems, load_err := i_load_ui(data_dir, opts, &ui, &load_err)
data := HardData{
litems,
ldirs,