aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_hardflip.go1
-rw-r--r--src/c_lfuzz.go83
-rw-r--r--src/e_keys.go37
-rw-r--r--src/i_host.go40
-rw-r--r--src/i_ui.go4
5 files changed, 162 insertions, 3 deletions
diff --git a/src/c_hardflip.go b/src/c_hardflip.go
index 6c67305..02aadee 100644
--- a/src/c_hardflip.go
+++ b/src/c_hardflip.go
@@ -68,6 +68,7 @@ type HardData struct {
keys [][2]string
insert *HostNode
yank *ItemsNode
+ lfuzz *FuzzList
}
func main() {
diff --git a/src/c_lfuzz.go b/src/c_lfuzz.go
new file mode 100644
index 0000000..4ce812b
--- /dev/null
+++ b/src/c_lfuzz.go
@@ -0,0 +1,83 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023-2024, Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the organization nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * hardflip: src/c_lfuzz.go
+ * Thu, 17 Oct 2024 13:22:18 +0200
+ * Joe
+ *
+ * fuzz hard
+ */
+
+package main
+
+type FuzzNode struct {
+ ptr *ItemsNode
+ name string
+ prev *FuzzNode
+ next *FuzzNode
+}
+
+type FuzzList struct {
+ head *FuzzNode
+ last *FuzzNode
+ curr *FuzzNode
+ draw *FuzzNode
+}
+
+// adds an item 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
+ return
+ }
+ last := litems.last
+ node.ID = last.ID + 1
+ node.prev = last
+ last.next = node
+ litems.last = last.next
+}
+
diff --git a/src/e_keys.go b/src/e_keys.go
index 484feea..6c5ac09 100644
--- a/src/e_keys.go
+++ b/src/e_keys.go
@@ -261,6 +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
ui.mode = FUZZ_MODE
} else if event.Rune() == '?' {
ui.mode = HELP_MODE
@@ -920,8 +921,44 @@ func e_fuzz_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
ui.s.HideCursor()
ui.mode = NORMAL_MODE
ui.buff.empty()
+ data.lfuzz = nil
return true
+ } else if event.Key() == tcell.KeyEnter {
+ // TODO: select fuzzed item
+ ui.s.HideCursor()
+ ui.mode = NORMAL_MODE
+ ui.buff.empty()
+ data.lfuzz = nil
+ } else {
+ e_readline(event, &ui.buff, ui, data.home_dir)
+ e_update_lfuzz(ui.buff, data.lfuzz)
}
// TODO: here
return false
}
+
+func e_update_lfuzz(buff Buffer, lfuzz *ItemsList) {
+ 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)
+ }
+ var end_runes []rune
+ for _, buff_ptr := range buff.data {
+ for _, name_ptr := range name_runes {
+ if buff_ptr == name_ptr {
+ end_runes = append(end_runes, buff_ptr)
+ continue
+ }
+ }
+ }
+ if len(end_runes) == 0 {
+ lfuzz.del(ptr)
+ }
+ }
+}
diff --git a/src/i_host.go b/src/i_host.go
index f697ed2..0f40394 100644
--- a/src/i_host.go
+++ b/src/i_host.go
@@ -51,7 +51,7 @@
package main
-func i_host_panel_dirs(ui HardUI, icons bool, dir_icon uint8,
+func i_host_panel_dirs(ui HardUI, icons bool, dir_icon uint8, depth uint16,
dir *DirsNode, curr *DirsNode, line int) {
style := ui.style[DIR_STYLE]
if dir == curr {
@@ -59,7 +59,7 @@ func i_host_panel_dirs(ui HardUI, icons bool, dir_icon uint8,
style = style.Reverse(true)
}
text := " "
- for i := 0; i < int(dir.Depth) - 2; i++ {
+ for i := 0; i < int(depth) - 2; i++ {
text += " "
}
if icons == true {
@@ -117,7 +117,9 @@ func i_draw_host_panel(ui HardUI, icons bool,
if litems == nil || litems.head == nil {
return
}
- if ui.mode == FUZZ_MODE {
+ if ui.mode == FUZZ_MODE && data.lfuzz != nil {
+ i_draw_host_panel_fuzzy(ui, icons, data.lfuzz, data)
+ // TODO: draw fuzz list
return
}
for ptr := litems.draw; ptr != nil && line < ui.dim[H] - 2; ptr = ptr.next {
@@ -136,6 +138,7 @@ func i_draw_host_panel(ui HardUI, icons bool,
dir_icon = 1
}
i_host_panel_dirs(ui, icons, dir_icon,
+ ptr.Dirs.Depth,
ptr.Dirs,
litems.curr.Dirs,
line)
@@ -143,3 +146,34 @@ func i_draw_host_panel(ui HardUI, icons bool,
}
}
}
+
+func i_draw_host_panel_fuzzy(ui HardUI, icons bool,
+ lfuzz *ItemsList, data *HardData) {
+ line := 1
+ if lfuzz == nil || lfuzz.head == nil {
+ return
+ }
+ 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,
+ icons,
+ 0,
+ ptr.Host,
+ lfuzz.curr.Host,
+ data.yank,
+ line)
+ line++
+ } else if ptr.Dirs != nil {
+ var dir_icon uint8
+ if data.folds[ptr.Dirs] != nil {
+ dir_icon = 1
+ }
+ i_host_panel_dirs(ui, icons, dir_icon,
+ 0,
+ ptr.Dirs,
+ lfuzz.curr.Dirs,
+ line)
+ line++
+ }
+ }
+}
diff --git a/src/i_ui.go b/src/i_ui.go
index f18c090..209156d 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -517,6 +517,9 @@ func i_prompt_fuzz(ui HardUI) {
i_draw_text(ui.s,
1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1,
ui.style[DEF_STYLE], prompt)
+ i_draw_text(ui.s, len(prompt) + 1,
+ ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1,
+ ui.style[DEF_STYLE].Bold(true), ui.buff.str())
ui.s.ShowCursor(len(prompt) + 1 +
ui.buff.cursor, ui.dim[H] - 1)
}
@@ -812,6 +815,7 @@ func i_ui(data_dir string) {
[][2]string{},
nil,
nil,
+ nil,
}
if data.opts.GPG == DEFAULT_OPTS.GPG && data.litems.head == nil {
data.ui.mode = WELCOME_MODE