aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_ldirs.go60
-rw-r--r--c_litems.go2
-rw-r--r--i_events.go23
-rw-r--r--i_ui.go5
4 files changed, 54 insertions, 36 deletions
diff --git a/c_ldirs.go b/c_ldirs.go
index 1a4157c..3de40e5 100644
--- a/c_ldirs.go
+++ b/c_ldirs.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_ldirs.go
- * Tue Jan 09 12:06:44 2024
+ * Thu Jan 11 18:35:31 2024
* Joe
*
* the directories linked list
@@ -51,8 +51,6 @@
package main
-import "fmt"
-
type DirsNode struct {
ID int
Name string
@@ -148,6 +146,18 @@ 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 {
@@ -155,24 +165,28 @@ func (dir *DirsNode) count_hosts() int {
}
return dir.lhost.last.ID + 1
}
-
// return the number of hosts and subfolders of the dir
-func (dir *DirsNode) count_elements(skip_folds bool,
- folds map[*DirsNode]*ItemsList) int {
- items := 0
-
- items += dir.count_hosts()
- for ptr := dir.next; ptr != nil && ptr.Depth > dir.Depth; ptr = ptr.next {
- if lfold := folds[ptr]; skip_folds == true && lfold != nil {
- count := lfold.last.ID - lfold.head.ID
- fmt.Println(count)
- // FIX: here
- for i := 1; ptr != nil && i < count; i++ {
- ptr = ptr.next
- }
- } else {
- items += ptr.count_hosts() + 1
- }
- }
- return items
-}
+// func (item *ItemsNode) count_elements(skip_folds bool,
+// folds map[*DirsNode]*ItemsList) (*ItemsNode, int) {
+// if item.is_dir() == false || item.Dirs == nil {
+// return nil, 0
+// }
+// items := 0
+//
+// items += item.Dirs.count_hosts()
+// for ptr := item; ptr != nil; ptr = ptr.next {
+// ptr.Dirs.Depth > item.Dirs.Depth
+// }
+// for ptr := dir.next; ptr != nil && ptr.Depth > dir.Depth; ptr = ptr.next {
+// if lfold := folds[ptr]; skip_folds == true && lfold != nil {
+// count := lfold.last.ID - lfold.head.ID
+// for i := 0; ptr != nil && i < count; i++ {
+// ptr = ptr.next
+// }
+// } else {
+// items += ptr.count_hosts() + 1
+// }
+// }
+// return items
+// // FIX: this needs fixin
+// }
diff --git a/c_litems.go b/c_litems.go
index 76fd116..33a3840 100644
--- a/c_litems.go
+++ b/c_litems.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_litems.go
- * Wed Jan 10 16:36:44 2024
+ * Thu Jan 11 18:37:44 2024
* Joe
*
* the dir and hosts linked list
diff --git a/i_events.go b/i_events.go
index cc31ff7..be7f039 100644
--- a/i_events.go
+++ b/i_events.go
@@ -113,10 +113,20 @@ func i_fold_dir(data *HardData, item *ItemsNode) {
} else {
folded_end = nil
}
- for i := 0;
- folded_end != nil && i < item.Dirs.count_elements(false, data.folds);
- i++ {
- folded_end = folded_end.next
+ // 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
+ }
+ if ptr == item {
+ folded_end = nil
+ } else {
+ folded_end = ptr.prev
}
if folded_end != nil {
after = folded_end.next
@@ -162,7 +172,8 @@ func i_delete_dir(data *HardData) {
// c_die("can't remove " + dir_path, err)
// }
tmp := data.litems.curr.prev
- count := data.litems.curr.Dirs.count_elements(false, data.folds) + 1
+ // count := data.litems.curr.Dirs.count_elements(false, data.folds) + 1
+ count := 0
data.ldirs.del(data.litems.curr.Dirs)
for i := 0; data.litems.curr != nil && i < count; i++ {
data.litems.del(data.litems.curr)
@@ -274,8 +285,6 @@ func i_events(data *HardData) {
} else if data.litems.curr.Dirs != nil &&
data.folds[data.litems.curr.Dirs] == nil {
i_fold_dir(data, data.litems.curr)
- ui.s.Fini()
- os.Exit(0)
} else {
i_unfold_dir(data, data.litems.curr)
}
diff --git a/i_ui.go b/i_ui.go
index fbbcc80..0a014a6 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -299,11 +299,6 @@ func i_host_panel(ui HardUI, icons bool, litems *ItemsList, data *HardData) {
ptr.Dirs,
litems.curr.Dirs,
line)
- // FIX: === delete this
- i_draw_text(ui.s,
- ui.dim[W] / 3 - 2, line, ui.dim[W] / 3, line,
- ui.def_style, strconv.Itoa(ptr.Dirs.count_elements(true, data.folds)))
- // FIX: ===
line++
}
}