aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-10-17 14:40:21 +0200
committerJoe <rbo@gmx.us>2024-10-17 14:40:21 +0200
commit7df369c68ec77c68faf4153f51a283655c253b99 (patch)
treed21722bf45f14e48cfa0cf547e94b1b4833d8a59
parentwwip (diff)
downloadhardflip-7df369c68ec77c68faf4153f51a283655c253b99.tar.gz
hardflip-7df369c68ec77c68faf4153f51a283655c253b99.tar.bz2
hardflip-7df369c68ec77c68faf4153f51a283655c253b99.tar.xz
hardflip-7df369c68ec77c68faf4153f51a283655c253b99.tar.zst
hardflip-7df369c68ec77c68faf4153f51a283655c253b99.zip
wip
-rw-r--r--src/c_lfuzz.go66
-rw-r--r--src/e_keys.go19
-rw-r--r--src/i_host.go3
3 files changed, 69 insertions, 19 deletions
diff --git a/src/c_lfuzz.go b/src/c_lfuzz.go
index 4ce812b..419a5f4 100644
--- a/src/c_lfuzz.go
+++ b/src/c_lfuzz.go
@@ -65,19 +65,63 @@ type FuzzList struct {
draw *FuzzNode
}
-// adds an item node to the list
+// adds a fuzz node to the list
func (lfuzz *FuzzList) add_back(node *ItemsNode) {
- if litems.head == nil {
- litems.head = node
- litems.last = litems.head
- litems.curr = litems.head
- litems.draw = litems.head
+ name := ""
+ if node.is_dir() == false {
+ name = node.Host.Name
+ } else {
+ name = node.Dirs.Name
+ }
+ fuzz_node := &FuzzNode{
+ node,
+ name,
+ nil,
+ nil,
+ }
+ if lfuzz.head == nil {
+ lfuzz.head = fuzz_node
+ lfuzz.last = lfuzz.head
+ lfuzz.curr = lfuzz.head
+ lfuzz.draw = lfuzz.head
return
}
- last := litems.last
- node.ID = last.ID + 1
- node.prev = last
- last.next = node
- litems.last = last.next
+ last := lfuzz.last
+ fuzz_node.prev = last
+ last.next = fuzz_node
+ lfuzz.last = last.next
}
+// removes n fuzz node from the list
+func (lfuzz *FuzzList) del(item *FuzzNode) {
+ if lfuzz.head == nil {
+ return
+ }
+ if lfuzz.head == item {
+ lfuzz.head = lfuzz.head.next
+ if lfuzz.head == nil {
+ lfuzz.last, lfuzz.curr, lfuzz.draw = nil, nil, nil
+ return
+ }
+ lfuzz.head.prev = nil
+ lfuzz.curr, lfuzz.draw = lfuzz.head, lfuzz.head
+ return
+ }
+ if lfuzz.last == item {
+ lfuzz.last = lfuzz.last.prev
+ lfuzz.last.next = nil
+ lfuzz.curr = lfuzz.last
+ if lfuzz.draw == item {
+ lfuzz.draw = lfuzz.last
+ }
+ return
+ }
+ ptr := lfuzz.head
+ for ptr.next != nil && ptr.next != item {
+ ptr = ptr.next
+ }
+ if ptr.next == item {
+ ptr.next = ptr.next.next
+ ptr.next.prev = ptr
+ }
+}
diff --git a/src/e_keys.go b/src/e_keys.go
index 6c5ac09..29c789f 100644
--- a/src/e_keys.go
+++ b/src/e_keys.go
@@ -261,7 +261,7 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
} else if (event.Rune() == '/' ||
event.Key() == tcell.KeyCtrlF) &&
data.litems.curr != nil {
- data.lfuzz = data.litems
+ e_create_fuzz_list(data)
ui.mode = FUZZ_MODE
} else if event.Rune() == '?' {
ui.mode = HELP_MODE
@@ -937,17 +937,22 @@ func e_fuzz_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
return false
}
-func e_update_lfuzz(buff Buffer, lfuzz *ItemsList) {
+func e_create_fuzz_list(data *HardData) {
+ if data.litems.head == nil {
+ return
+ }
+ for ptr := data.litems.head; ptr != nil; ptr = ptr.next {
+ data.lfuzz.add_back(ptr)
+ }
+}
+
+func e_update_lfuzz(buff Buffer, lfuzz *FuzzList) {
if lfuzz.head == nil {
return
}
for ptr := lfuzz.head; ptr != nil; ptr = ptr.next {
var name_runes []rune
- if ptr.is_dir() == false {
- name_runes = []rune(ptr.Host.Name)
- } else {
- name_runes = []rune(ptr.Dirs.Name)
- }
+ name_runes = []rune(ptr.name)
var end_runes []rune
for _, buff_ptr := range buff.data {
for _, name_ptr := range name_runes {
diff --git a/src/i_host.go b/src/i_host.go
index 0f40394..b048d4d 100644
--- a/src/i_host.go
+++ b/src/i_host.go
@@ -148,11 +148,12 @@ func i_draw_host_panel(ui HardUI, icons bool,
}
func i_draw_host_panel_fuzzy(ui HardUI, icons bool,
- lfuzz *ItemsList, data *HardData) {
+ lfuzz *FuzzList, data *HardData) {
line := 1
if lfuzz == nil || lfuzz.head == nil {
return
}
+ // TODO: find a way
for ptr := lfuzz.draw; ptr != nil && line < ui.dim[H] - 2; ptr = ptr.next {
if ptr.is_dir() == false && ptr.Host != nil {
i_host_panel_host(ui,