diff options
-rw-r--r-- | c_litems.go | 7 | ||||
-rw-r--r-- | i_events.go | 44 | ||||
-rw-r--r-- | i_ui.go | 26 |
3 files changed, 56 insertions, 21 deletions
diff --git a/c_litems.go b/c_litems.go index e1fef34..5e8a1a9 100644 --- a/c_litems.go +++ b/c_litems.go @@ -88,14 +88,11 @@ func (litems *ItemsList) del(item *ItemsNode) { if litems.head == item { litems.head = litems.head.next if litems.head == nil { - litems.last = nil - litems.curr = nil - litems.draw_start = nil + litems.last, litems.curr, litems.draw_start = nil, nil, nil return } litems.head.prev = nil - litems.curr = litems.head - litems.draw_start = litems.head + litems.curr, litems.draw_start = litems.head, litems.head for ptr := litems.head; ptr != nil; ptr = ptr.next { ptr.ID -= 1 } diff --git a/i_events.go b/i_events.go index 4da2b3d..900bc19 100644 --- a/i_events.go +++ b/i_events.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_events.go - * Tue Jan 09 12:00:50 2024 + * Tue Jan 09 15:14:14 2024 * Joe * * events in the code @@ -52,21 +52,37 @@ package main import ( + "fmt" "os" "github.com/gdamore/tcell/v2" "golang.org/x/term" ) +func i_update_folded_count(dir *DirsNode, ui *HardUI) { + delta := 0 + delta += dir.count_hosts() + for ptr := dir.next; ptr.Depth > dir.Depth && ptr != nil; ptr = ptr.next { + delta += ptr.count_hosts() + 1 + } + if dir.Folded == false { + delta *= -1 + } + ui.folded_count += delta + fmt.Println(">>>>> COUNT:", ui.folded_count) +} + func i_list_follow_cursor(litems *ItemsList, ui *HardUI) { - if litems.draw_start == nil { + if litems.draw_start == nil || litems.curr == nil { return } - for litems.draw_start.ID < litems.curr.ID - (ui.dim[H] - 4) && + virt_id := litems.curr.ID - (ui.dim[H] - 4) - ui.folded_count + for litems.draw_start.ID < virt_id && litems.draw_start.next != nil { litems.draw_start = litems.draw_start.next + } - for litems.curr.ID < litems.draw_start.ID && + for litems.draw_start.ID > litems.curr.ID && litems.draw_start.prev != nil { litems.draw_start = litems.draw_start.prev } @@ -133,9 +149,9 @@ func i_events(data *HardData) { event.Key() == tcell.KeyUp { data.litems.inc(-1) } else if event.Key() == tcell.KeyCtrlD { - data.litems.inc(+1000 + (ui.dim[H] / 3)) + data.litems.inc(+(ui.dim[H] / 3)) } else if event.Key() == tcell.KeyCtrlU { - data.litems.inc(-1000 - (ui.dim[H] / 3)) + data.litems.inc(-(ui.dim[H] / 3)) } else if event.Rune() == 'g' { data.litems.curr = data.litems.head data.litems.draw_start = data.litems.head @@ -147,7 +163,7 @@ func i_events(data *HardData) { ui.mode = DELETE_MODE } else if event.Key() == tcell.KeyEnter { if data.litems.curr == nil { - return + break } else if data.litems.curr.is_dir() == false { ui.s.Fini() c_exec(data.litems.curr.Host) @@ -169,8 +185,18 @@ func i_events(data *HardData) { data.litems.curr.Dirs.Folded = false } } - } - if event.Key() == tcell.KeyCtrlR { + } else if event.Rune() == ' ' { + if data.litems.curr == nil || + data.litems.curr.is_dir() == false { + break + } + if data.litems.curr.Dirs.Folded == false { + data.litems.curr.Dirs.Folded = true + } else { + data.litems.curr.Dirs.Folded = false + } + i_update_folded_count(data.litems.curr.Dirs, ui) + } else if event.Key() == tcell.KeyCtrlR { i_reload_data(data) } i_list_follow_cursor(data.litems, ui) @@ -58,13 +58,14 @@ import ( ) type HardUI struct { - s tcell.Screen - mode uint8 - sel_max int - def_style tcell.Style - dir_style tcell.Style - title_style tcell.Style - dim [2]int + s tcell.Screen + mode uint8 + sel_max int + def_style tcell.Style + dir_style tcell.Style + title_style tcell.Style + folded_count int + dim [2]int } func i_draw_text(s tcell.Screen, @@ -293,12 +294,22 @@ func i_host_panel(ui HardUI, icons bool, litems *ItemsList) { ptr.Host, litems.curr.Host, line) + // FIX: === delete this after fix + i_draw_text(ui.s, + 1, line, ui.dim[W] / 3, line, + ui.def_style, strconv.Itoa(ptr.ID)) + // FIX: === line++ } else if ptr.Dirs != nil { i_host_panel_dirs(ui, icons, ptr.Dirs, litems.curr.Dirs, line) + // FIX: === delete this after fix + i_draw_text(ui.s, + 1, line, ui.dim[W] / 3, line, + ui.def_style, strconv.Itoa(ptr.ID)) + // FIX: === line++ } } @@ -314,6 +325,7 @@ func i_host_panel(ui HardUI, icons bool, litems *ItemsList) { ui.def_style, " 0 hosts ") } + // FIX: bug on draw_start with folded folders } func i_info_panel_dirs(ui HardUI, dir *DirsNode) { |