diff options
author | Joe <rbo@gmx.us> | 2024-01-18 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-18 20:20:20 +0100 |
commit | bfc6e7a122d7cb9686823af6516a450f18222c28 (patch) | |
tree | 848aa48dc07d7a19f4a9602c5d2900916f853c00 | |
parent | go (diff) | |
download | hardflip-bfc6e7a122d7cb9686823af6516a450f18222c28.tar.gz hardflip-bfc6e7a122d7cb9686823af6516a450f18222c28.tar.bz2 hardflip-bfc6e7a122d7cb9686823af6516a450f18222c28.tar.xz hardflip-bfc6e7a122d7cb9686823af6516a450f18222c28.tar.zst hardflip-bfc6e7a122d7cb9686823af6516a450f18222c28.zip |
nobody will every see this
Diffstat (limited to '')
-rw-r--r-- | ROADMAP.md | 1 | ||||
-rw-r--r-- | c_defs.go | 4 | ||||
-rw-r--r-- | c_hardflip.go | 12 | ||||
-rw-r--r-- | c_init.go | 29 | ||||
-rw-r--r-- | i_events.go | 2 | ||||
-rw-r--r-- | i_ui.go | 47 |
6 files changed, 65 insertions, 30 deletions
@@ -8,6 +8,7 @@ ## v0.2 +- [ ] load scr - [ ] err msg ## v0.3 @@ -63,8 +63,7 @@ const ( [x](m)kdir - [x](s)earch - [x](?) help` - DELETE_KEYS_HINTS = ` -(q)uit - + DELETE_KEYS_HINTS = `(q)uit - (y)es - (n)o` ) @@ -72,6 +71,7 @@ const ( const ( NORMAL_MODE = 0 DELETE_MODE = 1 + LOAD_MODE = 2 ) var ( diff --git a/c_hardflip.go b/c_hardflip.go index 0ec601a..e4aec6c 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -64,15 +64,5 @@ type HardData struct { func main() { data_dir := c_get_data_dir() opts := HardOpts{true, true, false, ""} - ldirs := c_load_data_dir(data_dir, opts) - litems := c_load_litems(ldirs) - data := HardData{ - litems, - ldirs, - HardUI{}, - opts, - data_dir, - make(map[*DirsNode]*ItemsList), - } - i_ui(&data) + i_ui(data_dir, opts) } @@ -52,6 +52,7 @@ package main import ( + "strconv" "os" "path/filepath" ) @@ -63,11 +64,15 @@ type HardOpts struct { Term string } +// HACK: fuck global vars +var count int = 0 + // this function recurses into the specified root directory in order to load // every yaml file into memory func c_recurse_data_dir(dir, root string, opts HardOpts, ldirs *DirsList, - name string, parent *DirsNode, depth uint16) { + name string, parent *DirsNode, depth uint16, + ui *HardUI) { files, err := os.ReadDir(root + dir) if err != nil { c_die("could not read data directory", err) @@ -84,7 +89,7 @@ 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) + file.Name(), &dir_node, depth + 1, ui) } else if filepath.Ext(filename) == ".yml" { host_node := c_read_yaml_file(root + dir + filename) if host_node == nil { @@ -93,14 +98,30 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, host_node.Filename = filename host_node.Parent = &dir_node dir_node.lhost.add_back(host_node) + ui.s.Clear() + count += 1 + text := "Loading " + strconv.Itoa(count) + " hosts" + text_len := len(text) / 2 + i_draw_box(ui.s, + (ui.dim[W] / 2) - (text_len + 2), + (ui.dim[H] / 2) - 2, + (ui.dim[W] / 2) + (text_len + 2), + (ui.dim[H] / 2) + 2, " Loading hosts ", false) + i_draw_text(ui.s, + (ui.dim[W] / 2) - text_len, + (ui.dim[H] / 2), + (ui.dim[W] / 2) + text_len, + (ui.dim[H] / 2), + ui.def_style, text) + ui.s.Show() } } } -func c_load_data_dir(dir string, opts HardOpts) *DirsList { +func c_load_data_dir(dir string, opts HardOpts, ui *HardUI) *DirsList { ldirs := DirsList{} - c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1) + c_recurse_data_dir("", dir + "/", opts, &ldirs, "", nil, 1, ui) return &ldirs } diff --git a/i_events.go b/i_events.go index 9bc52ab..d799824 100644 --- a/i_events.go +++ b/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() - data.ldirs = c_load_data_dir(data.data_dir, data.opts) + data.ldirs = c_load_data_dir(data.data_dir, data.opts, &data.ui) data.litems = c_load_litems(data.ldirs) data.folds = make(map[*DirsNode]*ItemsList) } @@ -55,6 +55,7 @@ import ( "strconv" "github.com/gdamore/tcell/v2" + "golang.org/x/term" ) type HardUI struct { @@ -118,7 +119,7 @@ func i_draw_box(s tcell.Screen, x1, y1, x2, y2 int, title string, fill bool) { } } } - i_draw_text(s, x1 + 1, y1, x2 - 1, y2 - 1, style, title) + i_draw_text(s, x1 + 1, y1, x2 - 1, y1, style, title) } func i_bottom_text(ui HardUI) { @@ -161,6 +162,7 @@ func i_draw_zhosts_box(ui HardUI) { func i_draw_delete_box(ui HardUI, item *ItemsNode) { var text string var file string + if item.is_dir() == true { text = "Really delete this directory and all of its content?" file = item.Dirs.path() @@ -511,7 +513,6 @@ func i_info_panel(ui HardUI, percent bool, litems *ItemsList) { ui.dim[H] - 2, ui.def_style, text) - i_draw_text(ui.s, 0, ui.dim[H] - 2, len(text), ui.dim[H] - 2, ui.def_style, text) } else { text := " 0 hosts " i_draw_text(ui.s, @@ -555,9 +556,20 @@ func i_scrollhint(ui HardUI, litems *ItemsList) { } } -func i_ui(data *HardData) { +func i_load_ui(data_dir string, + opts HardOpts, + ui *HardUI) (*DirsList, *ItemsList) { + ui.s.Clear() + ldirs := c_load_data_dir(data_dir, opts, ui) + litems := c_load_litems(ldirs) + ui.s.Show() + ui.mode = NORMAL_MODE + return ldirs, litems +} + +func i_ui(data_dir string, opts HardOpts) { + ui := HardUI{} var err error - ui := &data.ui ui.s, err = tcell.NewScreen() if err != nil { @@ -576,19 +588,30 @@ func i_ui(data *HardData) { Background(tcell.ColorReset). Foreground(tcell.ColorBlue).Dim(true).Bold(true) ui.s.SetStyle(ui.def_style) + ui.dim[W], ui.dim[H], _ = term.GetSize(0) + ui.mode = LOAD_MODE + ldirs, litems := i_load_ui(data_dir, opts, &ui) + data := HardData{ + litems, + ldirs, + ui, + opts, + data_dir, + make(map[*DirsNode]*ItemsList), + } for { - ui.s.Clear() - i_bottom_text(*ui) - i_host_panel(data.ui, data.opts.Icon, data.litems, data) + data.ui.s.Clear() + i_bottom_text(data.ui) + i_host_panel(data.ui, data.opts.Icon, data.litems, &data) i_info_panel(data.ui, data.opts.Perc, data.litems) i_scrollhint(data.ui, data.litems) if data.litems.head == nil { - i_draw_zhosts_box(*ui) + i_draw_zhosts_box(data.ui) } - if ui.mode == DELETE_MODE { - i_draw_delete_box(*ui, data.litems.curr) + if data.ui.mode == DELETE_MODE { + i_draw_delete_box(data.ui, data.litems.curr) } - ui.s.Show() - i_events(data) + data.ui.s.Show() + i_events(&data) } } |