diff options
-rw-r--r-- | c_ldirs.go | 12 | ||||
-rw-r--r-- | c_litems.go | 24 | ||||
-rw-r--r-- | i_events.go | 187 | ||||
-rw-r--r-- | i_ui.go | 4 |
4 files changed, 147 insertions, 80 deletions
@@ -146,18 +146,6 @@ func (dir *DirsNode) path() string { return path } -// returns the next directory in line with the same or lower depth -func (dir *DirsNode) get_next_level(folds map[*DirsNode]*ItemsList) *DirsNode { - if dir == nil { - return nil - } - ptr := dir.next - for ptr != nil && ptr.Depth > dir.Depth { - ptr = ptr.next - } - return ptr -} - // returns the number of hosts of the dir func (dir *DirsNode) count_hosts() int { if dir.lhost.head == nil || dir.lhost.last == nil { diff --git a/c_litems.go b/c_litems.go index 33a3840..031432d 100644 --- a/c_litems.go +++ b/c_litems.go @@ -166,3 +166,27 @@ func (litems *ItemsList) inc(jump int) { } litems.curr = new_item } + +// returns the next directory in line with the same or lower depth +func (item *ItemsNode) get_next_level() *ItemsNode { + if item == nil || item.Dirs == nil { + return nil + } + dir := item.Dirs + ptr := dir.next + for ptr != nil && ptr.Depth > dir.Depth { + ptr = ptr.next + } + item_ptr := item + for item_ptr != nil { + if item_ptr.is_dir() == false { + continue + } + if item_ptr.Dirs == ptr { + break + } + item_ptr = item_ptr.next + } + return item_ptr +} + diff --git a/i_events.go b/i_events.go index 9666adc..9dfa43b 100644 --- a/i_events.go +++ b/i_events.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_events.go - * Thu Jan 11 12:22:12 2024 + * Mon Jan 15 11:40:10 2024 * Joe * * events in the code @@ -52,6 +52,7 @@ package main import ( + // "fmt" "fmt" "os" @@ -74,6 +75,13 @@ func i_list_follow_cursor(litems *ItemsList, ui *HardUI) { } } +func i_set_unfold(data *HardData, item *ItemsNode) { + delete(data.folds, item.Dirs) + for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { + ptr.next.ID = ptr.ID + 1 + } +} + func i_unfold_dir(data *HardData, item *ItemsNode) { if item == nil || item.Dirs == nil { return @@ -82,20 +90,42 @@ func i_unfold_dir(data *HardData, item *ItemsNode) { if fold == nil { return } - after := item.next - item.next = fold.head - if fold.head != nil { - fold.head.prev = item + // after := item.next + start, end := fold.head, fold.last + // last empty dir + if start == nil && end == nil { + i_set_unfold(data, item) + return } - if fold.last != nil { - fold.last.next = after + // single empty dir + if start == item && end == end { + i_set_unfold(data, item) + return } - if after != nil { - after.prev = fold.last - } else { - data.litems.last = fold.last + // item.next = fold.head + // if fold.head != nil { + // fold.head.prev = item + // } + // if fold.last != nil { + // fold.last.next = after + // } + // if after != nil { + // after.prev = fold.last + // } else { + // data.litems.last = fold.last + // } +} + +func i_set_fold(data *HardData, curr, start, end *ItemsNode) { + folds := data.folds + tmp := ItemsList{ + start, + end, + nil, + nil, } - delete(data.folds, item.Dirs) + + folds[curr.Dirs] = &tmp for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { ptr.next.ID = ptr.ID + 1 } @@ -105,66 +135,91 @@ func i_fold_dir(data *HardData, item *ItemsNode) { if item == nil || item.Dirs == nil { return } - var folded_start, folded_end, after *ItemsNode - folds := data.folds - folded_start = item.next - if folded_start != nil { - folded_start.prev = nil - folded_end = item - } else { - folded_end = nil - } - // for i := 0; - // folded_end != nil && i < item.Dirs.count_elements(true, data.folds); - // i++ { - // folded_end = folded_end.next - // } - next_dir := item.Dirs.get_next_level(data.folds) - ptr := item - for next_dir != nil && ptr != nil && ptr.Dirs != next_dir { - ptr = ptr.next + // var start, end, after *ItemsNode + var start, end *ItemsNode + start = item.next + // last dir + empty + if start == nil { + i_set_fold(data, item, nil, nil) + return } - if ptr == item && ptr.next != nil { - ptr = ptr.next - // FIX: fix your crap + // empty dir + if start.Dirs != nil && start.Dirs.Depth <= item.Dirs.Depth { + i_set_fold(data, item, item, item) + return } - if ptr == nil { - folded_end = nil - after = nil - data.ui.s.Fini() - fmt.Println("ptr:", ptr) - os.Exit(0) - } else if ptr == item { - folded_end = nil - after = nil + // non-empty dir + start.prev = nil + end = start + next_dir := item.get_next_level() data.ui.s.Fini() - fmt.Println("this is the end") + fmt.Println("qwe") os.Exit(0) - } else { - folded_end = ptr.prev - // data.ui.s.Fini() - // fmt.Println("ptr.Dirs.Name:", ptr.Host.Name, "\nfolded_end:", folded_end) - // os.Exit(0) - after = folded_end.next - folded_end.next = nil - } - tmp := ItemsList{ - folded_start, - folded_end, - nil, - nil, - } - item.next = after - if after != nil { - after.prev = item - } else { - data.litems.last = item + // this is the end + if next_dir == nil { + return } + // this is not the end + end = next_dir.prev + item.next = next_dir + i_set_fold(data, item, start, end) - folds[item.Dirs] = &tmp - for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next { - ptr.next.ID = ptr.ID + 1 - } + + // item.next = after + // if after != nil { + // after.prev = item + // } else { + // data.litems.last = item + // } + // folds := data.folds + // folded_start = item.next + // if folded_start != nil { + // folded_start.prev = nil + // folded_end = item + // } else { + // folded_end = nil + // } + // next_dir := item.Dirs.get_next_level(data.folds) + // ptr := item + // for next_dir != nil && ptr != nil && ptr.Dirs != next_dir { + // ptr = ptr.next + // } + // if ptr == item && ptr.next != nil { + // ptr = ptr.next + // // FIX: fix your crap + // } + // if ptr == nil { + // folded_end = nil + // after = nil + // data.ui.s.Fini() + // fmt.Println("ptr:", ptr) + // os.Exit(0) + // } else if ptr == item { + // folded_end = nil + // after = nil + // data.ui.s.Fini() + // fmt.Println("this is the end") + // os.Exit(0) + // } else { + // folded_end = ptr.prev + // // data.ui.s.Fini() + // // fmt.Println("ptr.Dirs.Name:", ptr.Host.Name, "\nfolded_end:", folded_end) + // // os.Exit(0) + // after = folded_end.next + // folded_end.next = nil + // } + // tmp := ItemsList{ + // folded_start, + // folded_end, + // nil, + // nil, + // } + // item.next = after + // if after != nil { + // after.prev = item + // } else { + // data.litems.last = item + // } } func i_reload_data(data *HardData) { @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Thu Jan 11 12:22:06 2024 + * Mon Jan 15 11:40:18 2024 * Joe * * interfacing with the user @@ -235,7 +235,7 @@ func i_host_panel_dirs(ui HardUI, icons bool, dir_icon uint8, } text := "" for i := 0; i < int(dir.Depth) - 2; i++ { - text += " " + text += " " } if icons == true { text += DIRS_ICONS[dir_icon] |