From 28108920b5e4c6ad916b4c974319b14b3be27798 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 8 Jan 2024 20:20:20 +0100 Subject: factor --- c_hardflip.go | 36 ------------------------------------ c_ldirs.go | 12 ------------ i_events.go | 5 ++--- i_ui.go | 16 ++-------------- 4 files changed, 4 insertions(+), 65 deletions(-) diff --git a/c_hardflip.go b/c_hardflip.go index b040727..17712ae 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -74,41 +74,5 @@ func main() { opts, data_dir, } - - // for ptr = ldirs.head; ptr != nil ; ptr = ptr.next { - // spaces := "" - // for i := 0; i < int(ptr.Depth - 1) * 2; i++ { - // spaces += " " - // } - // if ptr.is_dir() == true { - // fmt.Print(spaces, "DIR ", ptr.ID, " ") - // } - // fmt.Println(ptr.Name) - // for ptr = ptr.lhost.head; ptr != nil; ptr = ptr.next { - // spaces := "" - // for i := 0; i < int(ptr.Parent.Depth - 1) * 2; i++ { - // spaces += " " - // } - // spaces += " " - // if ptr.is_dir() == false { - // fmt.Print(spaces, "HOST ", ptr.ID, " ") - // } - // fmt.Println(ptr.Name) - // } - // } - // for dir := ldirs.head; dir != nil ; dir = dir.next { - // for host := dir.lhost.head; host != nil; host = host.next { - // fmt.Println(host.ID, host.Name, "HOST") - // } - // } - // for item := litems.head; item != nil; item = item.next { - // if item.is_dir() == true { - // fmt.Println(item.ID, item.Dirs.Name) - // } else { - // fmt.Println(item.ID, item.Host.Name) - // } - // } - - // PERF: test performance over a large amount of hosts with litems i_ui(&data) } diff --git a/c_ldirs.go b/c_ldirs.go index aff93e4..af24c28 100644 --- a/c_ldirs.go +++ b/c_ldirs.go @@ -109,15 +109,3 @@ func (ldirs *DirsList) path(node *DirsNode) string { } return path } - -func (ldirs *DirsList) count() (int, int) { - curr := ldirs.head - var count_dirs int - var count_hosts int - - for count_dirs = 0; curr != nil; count_dirs++ { - count_hosts += curr.lhost.count() - curr = curr.next - } - return count_dirs, count_hosts -} diff --git a/i_events.go b/i_events.go index 1d8dd20..3406088 100644 --- a/i_events.go +++ b/i_events.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_events.go - * Mon Jan 08 13:56:06 2024 + * Mon Jan 08 16:40:17 2024 * Joe * * events in the code @@ -75,8 +75,7 @@ func i_list_follow_cursor(litems *ItemsList, ui *HardUI) { func i_reload_data(data *HardData) { data.ldirs = c_load_data_dir(data.data_dir, data.opts) data.litems = c_load_litems(data.ldirs) - data.ui.sel_max, data.ui.count_dirs, data.ui.count_hosts = - i_get_sel_max(data.ldirs) + data.ui.sel_max = data.litems.last.ID } func i_delete_host(data *HardData) { diff --git a/i_ui.go b/i_ui.go index f81e04c..2d5294e 100644 --- a/i_ui.go +++ b/i_ui.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Mon Jan 08 12:18:01 2024 + * Mon Jan 08 14:53:10 2024 * Joe * * interfacing with the user @@ -61,8 +61,6 @@ type HardUI struct { s tcell.Screen mode uint8 sel_max int - count_dirs int - count_hosts int def_style tcell.Style dir_style tcell.Style title_style tcell.Style @@ -321,7 +319,6 @@ func i_info_panel(ui HardUI, lhost *HostList) { if lhost.head == nil { return } - // HACK: litems instead of this mess // host = lhost.sel(ui.sel_id) host_type = host.protocol_str() // name, type @@ -481,20 +478,11 @@ func i_info_panel(ui HardUI, lhost *HostList) { } } -func i_get_sel_max(ldirs *DirsList) (int, int, int) { - count_dirs, count_hosts := ldirs.count() - - count_dirs -= 1 - return count_dirs + count_hosts, count_dirs, count_hosts -} - func i_ui(data *HardData) { // TODO: replace everything ui with litems var err error ui := &data.ui - // TODO: get better counts - // NOTE: put this in c_load_data and also produce better code - ui.sel_max, ui.count_dirs, ui.count_hosts = i_get_sel_max(data.ldirs) + ui.sel_max = data.litems.last.ID ui.s, err = tcell.NewScreen() if err != nil { -- cgit v1.2.3