From 36da88715d7ffc30a4fcf3ef27bbbb88d30b02a8 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 20 Jan 2025 17:00:47 +0100 Subject: okok --- src/c_hardflip.go | 1 - src/c_lfuzz.go | 127 ------------------------------------------------------ src/e_keys.go | 53 ++++++++--------------- src/i_host.go | 61 +++++++++++++------------- src/i_ui.go | 1 - 5 files changed, 47 insertions(+), 196 deletions(-) delete mode 100644 src/c_lfuzz.go diff --git a/src/c_hardflip.go b/src/c_hardflip.go index 8911f20..d2e4c12 100644 --- a/src/c_hardflip.go +++ b/src/c_hardflip.go @@ -68,7 +68,6 @@ 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 deleted file mode 100644 index 419a5f4..0000000 --- a/src/c_lfuzz.go +++ /dev/null @@ -1,127 +0,0 @@ -/* - * ======================== - * ===== =============== - * ====== ================ - * ====== ================ - * ====== ==== ==== == - * ====== === == = = - * ====== === = == = - * = === === = == ==== - * = === === = == = = - * == ===== ==== == - * ======================== - * - * 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 a fuzz node to the list -func (lfuzz *FuzzList) add_back(node *ItemsNode) { - 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 := 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 f539a65..6d020cb 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -262,7 +262,6 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { } else if (event.Rune() == '/' || event.Key() == tcell.KeyCtrlF) && data.litems.curr != nil { - e_create_fuzz_list(data) ui.mode = FUZZ_MODE } else if event.Rune() == '?' { ui.mode = HELP_MODE @@ -922,50 +921,34 @@ 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_create_fuzz_list(data *HardData) { - if data.litems.head == nil { - return - } - data.lfuzz = &FuzzList{} - 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 - name_runes = []rune(ptr.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) - } - } -} +// func e_update_lfuzz(buff Buffer) { +// for ptr := lfuzz.head; ptr != nil; ptr = ptr.next { +// var name_runes []rune +// name_runes = []rune(ptr.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 72f9564..7d3fd57 100644 --- a/src/i_host.go +++ b/src/i_host.go @@ -117,12 +117,15 @@ func i_draw_host_panel(ui HardUI, icons bool, if litems == nil || litems.head == nil { return } - if ui.mode == FUZZ_MODE && data.lfuzz != nil { - i_draw_host_panel_fuzzy(ui, icons, data.lfuzz, data) - // TODO: draw fuzz list - return - } + // 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 { + if ui.mode == FUZZ_MODE && i_fuzz_check(ptr, &ui) == false { + continue + } if ptr.is_dir() == false && ptr.Host != nil { i_host_panel_host(ui, icons, @@ -147,35 +150,29 @@ func i_draw_host_panel(ui HardUI, icons bool, } } -func i_draw_host_panel_fuzzy(ui HardUI, icons bool, - lfuzz *FuzzList, data *HardData) { - line := 1 - if lfuzz == nil || lfuzz.head == nil { - return +func i_fuzz_check(ptr *ItemsNode, ui *HardUI) bool { + name := "" + var name_runes []rune + var end_runes []rune + + if len(ui.buff.data) == 0 { + return true } - // TODO: find a way - for ptr := lfuzz.draw; ptr != nil && line < ui.dim[H] - 2; ptr = ptr.next { - item := ptr.ptr - if item.is_dir() == false && item.Host != nil { - i_host_panel_host(ui, - icons, - 0, - item.Host, - lfuzz.curr.ptr.Host, - data.yank, - line) - line++ - } else if item.Dirs != nil { - var dir_icon uint8 - if data.folds[item.Dirs] != nil { - dir_icon = 1 + if ptr.is_dir() == false && ptr.Host != nil { + name = ptr.Host.Name + } else if ptr.Dirs != nil { + name = ptr.Dirs.Name + } + name_runes = []rune(name) + for _, buff_ptr := range ui.buff.data { + for _, name_ptr := range name_runes { + if buff_ptr == name_ptr { + end_runes = append(end_runes, buff_ptr) } - i_host_panel_dirs(ui, icons, dir_icon, - 0, - item.Dirs, - lfuzz.curr.ptr.Dirs, - line) - line++ } } + if len(end_runes) == 0 { + return false + } + return true } diff --git a/src/i_ui.go b/src/i_ui.go index 209156d..0ffa945 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -815,7 +815,6 @@ 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 -- cgit v1.2.3