diff options
Diffstat (limited to '')
-rw-r--r-- | src/c_hardflip.go | 3 | ||||
-rw-r--r-- | src/c_init.go | 23 | ||||
-rw-r--r-- | src/c_parse.go | 17 | ||||
-rw-r--r-- | src/i_events.go | 3 | ||||
-rw-r--r-- | src/i_ui.go | 49 |
5 files changed, 62 insertions, 33 deletions
diff --git a/src/c_hardflip.go b/src/c_hardflip.go index e4aec6c..538cb30 100644 --- a/src/c_hardflip.go +++ b/src/c_hardflip.go @@ -57,8 +57,9 @@ type HardData struct { ldirs *DirsList ui HardUI opts HardOpts - data_dir string folds map[*DirsNode]*ItemsList + data_dir string + load_err *[]error } func main() { diff --git a/src/c_init.go b/src/c_init.go index 6355d94..5d399e2 100644 --- a/src/c_init.go +++ b/src/c_init.go @@ -68,10 +68,11 @@ type HardOpts struct { func c_recurse_data_dir(dir, root string, opts HardOpts, ldirs *DirsList, name string, parent *DirsNode, depth uint16, - ui *HardUI) { + ui *HardUI, load_err *[]error) { files, err := os.ReadDir(root + dir) if err != nil { - c_die("could not read data directory", err) + *load_err = append(*load_err, err) + return } dir_node := DirsNode{ name, @@ -86,10 +87,13 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, filename := file.Name() if file.IsDir() == true { c_recurse_data_dir(dir + filename + "/", root, opts, ldirs, - file.Name(), &dir_node, depth + 1, ui) + file.Name(), &dir_node, depth + 1, ui, load_err) } else if filepath.Ext(filename) == ".yml" { - host_node := c_read_yaml_file(root + dir + filename) - if host_node == nil { + host_node, err := c_read_yaml_file(root + dir + filename, ui) + if err != nil { + *load_err = append(*load_err, err) + return + } else if host_node == nil { return } host_node.Filename = filename @@ -100,11 +104,12 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, } } -func c_load_data_dir(dir string, opts HardOpts, ui *HardUI) *DirsList { - ldirs := DirsList{} +func c_load_data_dir(dir string, opts HardOpts, ui *HardUI) (*DirsList, *[]error) { + ldirs := DirsList{} + var load_err []error - c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui) - return &ldirs + c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui, &load_err) + return &ldirs, &load_err } // fills litems sorting with dirs last diff --git a/src/c_parse.go b/src/c_parse.go index 61d4dfc..c26b4f5 100644 --- a/src/c_parse.go +++ b/src/c_parse.go @@ -57,22 +57,21 @@ import ( "gopkg.in/yaml.v3" ) -func c_read_yaml_file(file string) *HostNode { +func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { var host HostNode yaml_file, err := os.ReadFile(file) if err != nil { - // TODO: remove all c_dies with c_err_mode - c_die("error reading file " + file, err) + return nil, err } - if err = yaml.Unmarshal(yaml_file, &host); err != nil { - c_die("error reading yaml file " + file, err) + if err := yaml.Unmarshal(yaml_file, &host); err != nil { + return nil, err } if len(host.Name) == 0 { - return nil + return nil, nil } if len(host.Host) == 0 { - return nil + return nil, nil } if host.Protocol == 0 { if host.Port == 0 { @@ -103,10 +102,10 @@ func c_read_yaml_file(file string) *HostNode { host.Height = 1200 } } else if host.Protocol > 1 { - return nil + return nil, nil } if host.Quality > 2 { host.Quality = 2 } - return &host + return &host, nil } diff --git a/src/i_events.go b/src/i_events.go index 4e3baae..427f9c1 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -168,7 +168,7 @@ func i_fold_dir(data *HardData, item *ItemsNode) { func i_reload_data(data *HardData) { data.data_dir = c_get_data_dir() g_load_count = -1 - data.ldirs, data.litems = i_load_ui(data.data_dir, data.opts, &data.ui) + data.ldirs, data.litems, data.load_err = i_load_ui(data.data_dir, data.opts, &data.ui) // FIX: must input to start reloading for some reason data.folds = make(map[*DirsNode]*ItemsList) } @@ -344,6 +344,7 @@ func i_events(data *HardData) { if event.Rune() == 'q' || event.Key() == tcell.KeyEnter { ui.mode = NORMAL_MODE + data.load_err = nil } } } diff --git a/src/i_ui.go b/src/i_ui.go index 1c7f710..53bd056 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Fri Jan 19 19:23:24 2024 + * Tue Jan 23 14:21:09 2024 * Joe * * interfacing with the user @@ -52,6 +52,7 @@ package main import ( + "fmt" "os" "strconv" @@ -220,13 +221,28 @@ func i_draw_delete_msg(ui HardUI, item *ItemsNode) { ui.style[DEF_STYLE].Bold(true), file) } -func i_draw_error_msg(ui HardUI) { +func i_draw_load_error_msg(ui HardUI, load_err *[]error) { + lines := len(*load_err) + i_draw_msg(ui.s, lines, ui.style[BOX_STYLE], ui.dim, " Load time errors ") + left, right := 1, ui.dim[W] - 2 + for i, err := range *load_err { + err_str := fmt.Sprintf("%v", err) + i_draw_text(ui.s, left, i, right, i, + ui.style[ERR_STYLE], strconv.Itoa(i) + err_str) + } +} + +func i_draw_error_msg(ui HardUI, load_err *[]error) { + if len(*load_err) > 0 { + i_draw_load_error_msg(ui, load_err) + return + } lines := 2 if len(ui.err[ERROR_ERR]) == 0 { lines = 1 } - i_draw_msg(ui.s, lines, ui.style[BOX_STYLE], ui.dim, " Delete ") - left, right := i_left_right(len(ui.err[ERROR_MSG]), &ui) + i_draw_msg(ui.s, lines, ui.style[BOX_STYLE], ui.dim, " Error ") + left, right := 1, ui.dim[W] - 2 line := ui.dim[H] - 2 - 2 if len(ui.err[ERROR_ERR]) == 0 { line += 1 @@ -254,17 +270,16 @@ func i_draw_scrollhint(ui HardUI, litems *ItemsList) { if draw_id > 1 { ui.s.SetContent(0, 1, '▲', - nil, ui.style[DEF_STYLE]) + nil, ui.style[BOX_STYLE]) } if last - draw_id > h { ui.s.SetContent(0, ui.dim[H] - 3, '▼', - nil, ui.style[DEF_STYLE]) + nil, ui.style[BOX_STYLE]) return } } -// HACK: fuck global vars but do we have the choice really var g_load_count int = -1 func i_draw_load_ui(ui *HardUI) { @@ -301,12 +316,15 @@ func i_draw_load_ui(ui *HardUI) { func i_load_ui(data_dir string, opts HardOpts, - ui *HardUI) (*DirsList, *ItemsList) { + ui *HardUI) (*DirsList, *ItemsList, *[]error) { ui.mode = LOAD_MODE - ldirs := c_load_data_dir(data_dir, opts, ui) + ldirs, load_err := c_load_data_dir(data_dir, opts, ui) litems := c_load_litems(ldirs) ui.mode = NORMAL_MODE - return ldirs, litems + if len(*load_err) == 0 { + load_err = nil + } + return ldirs, litems, load_err } func i_ui(data_dir string, opts HardOpts) { @@ -341,16 +359,18 @@ func i_ui(data_dir string, opts HardOpts) { ui.style[SEL_STYLE] = tcell.StyleDefault. Background(tcell.ColorReset). Foreground(tcell.ColorBlue).Dim(true).Bold(true) + // TODO: sel_style ui.s.SetStyle(ui.style[DEF_STYLE]) ui.dim[W], ui.dim[H], _ = term.GetSize(0) - ldirs, litems := i_load_ui(data_dir, opts, &ui) + ldirs, litems, load_err := i_load_ui(data_dir, opts, &ui) data := HardData{ litems, ldirs, ui, opts, - data_dir, make(map[*DirsNode]*ItemsList), + data_dir, + load_err, } for { data.ui.s.Clear() @@ -358,6 +378,9 @@ func i_ui(data_dir string, opts HardOpts) { i_draw_host_panel(data.ui, data.opts.Icon, data.litems, &data) i_draw_info_panel(data.ui, data.opts.Perc, data.litems) i_draw_scrollhint(data.ui, data.litems) + if data.load_err != nil && len(*data.load_err) > 0 { + data.ui.mode = ERROR_MODE + } if data.litems.head == nil { i_draw_zhosts_box(data.ui) } @@ -365,7 +388,7 @@ func i_ui(data_dir string, opts HardOpts) { i_draw_delete_msg(data.ui, data.litems.curr) } if data.ui.mode == ERROR_MODE { - i_draw_error_msg(data.ui) + i_draw_error_msg(data.ui, data.load_err) } data.ui.s.Show() i_events(&data) |