aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-01-10 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-01-10 20:20:20 +0100
commit9e3247465a6a246f4de17b0337ef1578e1c6e2be (patch)
tree50de717d746270288a23193769d17efde492b38a
parentgood (diff)
downloadhardflip-9e3247465a6a246f4de17b0337ef1578e1c6e2be.tar.gz
hardflip-9e3247465a6a246f4de17b0337ef1578e1c6e2be.tar.bz2
hardflip-9e3247465a6a246f4de17b0337ef1578e1c6e2be.tar.xz
hardflip-9e3247465a6a246f4de17b0337ef1578e1c6e2be.tar.zst
hardflip-9e3247465a6a246f4de17b0337ef1578e1c6e2be.zip
sick
-rw-r--r--c_ldirs.go8
-rw-r--r--i_events.go39
-rw-r--r--i_ui.go2
3 files changed, 37 insertions, 12 deletions
diff --git a/c_ldirs.go b/c_ldirs.go
index 96381fd..906e368 100644
--- a/c_ldirs.go
+++ b/c_ldirs.go
@@ -120,12 +120,16 @@ func (dir *DirsNode) count_hosts() int {
}
// return the number of hosts and subfolders of the dir
-func (dir *DirsNode) count_elements() int {
+func (dir *DirsNode) count_elements(skip_folds bool) int {
items := 0
items += dir.count_hosts()
for ptr := dir.next; ptr != nil && ptr.Depth > dir.Depth; ptr = ptr.next {
- items += ptr.count_hosts() + 1
+ if skip_folds == true && ptr.Folded == true {
+ items += 1
+ } else {
+ items += ptr.count_hosts() + 1
+ }
}
return items
}
diff --git a/i_events.go b/i_events.go
index 587aefa..cdfb5e5 100644
--- a/i_events.go
+++ b/i_events.go
@@ -92,16 +92,38 @@ func i_list_follow_cursor(litems *ItemsList, ui *HardUI) {
// }
}
-func i_fold_dir(data *HardData, item *ItemsNode) {
+func i_unfold_dir(data *HardData, item *ItemsNode) {
if item == nil {
return
}
- litems := data.litems
+ fold := data.folds[item]
+ if fold == nil {
+ return
+ }
+ after := item.next
+ item.next = fold.head
+ fold.head.prev = item
+ fold.last.next = after
+ if after != nil {
+ after.prev = fold.last
+ } else {
+ data.litems.last = fold.last
+ }
+ delete(data.folds, item)
+ for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next {
+ ptr.next.ID = ptr.ID + 1
+ }
+}
+
+func i_fold_dir(data *HardData, item *ItemsNode) {
+ if item == nil || item.Dirs == nil {
+ return
+ }
folds := data.folds
folded_start := item.next
folded_start.prev = nil
folded_end := item
- for i := 0; i < item.Dirs.count_elements() && folded_end != nil; i++ {
+ for i := 0; i < item.Dirs.count_elements(true) && folded_end != nil; i++ {
folded_end = folded_end.next
}
after := folded_end.next
@@ -113,14 +135,14 @@ func i_fold_dir(data *HardData, item *ItemsNode) {
nil,
}
item.next = after
- if after == nil {
- litems.last = item
- } else {
+ if after != nil {
after.prev = item
+ } else {
+ data.litems.last = item
}
folds[item] = &tmp
- for ptr := litems.head; ptr.next != nil; ptr = ptr.next {
+ for ptr := data.litems.head; ptr.next != nil; ptr = ptr.next {
ptr.next.ID = ptr.ID + 1
}
}
@@ -225,10 +247,11 @@ func i_events(data *HardData) {
} else {
if data.litems.curr.Dirs.Folded == false {
data.litems.curr.Dirs.Folded = true
+ i_fold_dir(data, data.litems.curr)
} else {
data.litems.curr.Dirs.Folded = false
+ i_unfold_dir(data, data.litems.curr)
}
- i_fold_dir(data, data.litems.curr)
}
} else if event.Rune() == ' ' {
if data.litems.curr == nil ||
diff --git a/i_ui.go b/i_ui.go
index 2fc0cc1..1f49dd5 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -52,8 +52,6 @@
package main
import (
- // "fmt"
- // "os"
"strconv"
"github.com/gdamore/tcell/v2"