From fc2186ec5c8859589d9cb3cb0612135d24369cfe Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 23 Sep 2024 15:30:05 +0200 Subject: wip --- src/c_defs.go | 4 +++- src/e_keys.go | 19 +++++++++++++++---- src/i_ui.go | 12 ++++++++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/c_defs.go b/src/c_defs.go index f4cbcbf..b955f0c 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -83,7 +83,8 @@ const ( INSERT_MODE RENAME_MODE HELP_MODE - MODE_MAX = HELP_MODE + FUZZ_MODE + MODE_MAX = FUZZ_MODE ) const ( @@ -221,6 +222,7 @@ var HELP_NORMAL_KEYS = [][2]string{ {"e", "Edit selected host"}, {"c | C | A", "Rename selected item"}, {"", "Reload data and configuration"}, + {"/ | ", "Fuzzy search"}, {"?", "Display this help menu"}, {" | q", "Quit"}, } diff --git a/src/e_keys.go b/src/e_keys.go index e7c71c8..e64f727 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -76,10 +76,6 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { } else if event.Key() == tcell.KeyCtrlU || event.Key() == tcell.KeyPgUp { data.litems.inc(-(ui.dim[H] / 3)) - } else if event.Key() == tcell.KeyCtrlF { - // TODO: maybe keymap these - } else if event.Key() == tcell.KeyCtrlB { - // TODO: maybe keymap these } else if event.Rune() == '}' || event.Rune() == ']' { if next := data.litems.curr.next_dir(); next != nil { @@ -262,6 +258,10 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { } else { ui.buff.insert(data.litems.curr.Dirs.Name) } + } else if (event.Rune() == '/' || + event.Key() == tcell.KeyCtrlF) && + data.litems.curr != nil { + ui.mode = FUZZ_MODE } else if event.Rune() == '?' { ui.mode = HELP_MODE ui.help_scroll = 0 @@ -915,3 +915,14 @@ func e_help_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { } return false } + +func e_fuzz_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { + if event.Key() == tcell.KeyEscape || + event.Key() == tcell.KeyCtrlC { + ui.s.HideCursor() + ui.mode = NORMAL_MODE + ui.buff.empty() + return true + } + return false +} diff --git a/src/i_ui.go b/src/i_ui.go index dbbcbf9..f18c090 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -512,6 +512,15 @@ func i_prompt_insert(ui HardUI, curr *ItemsNode) { ui.buff.cursor, ui.dim[H] - 1) } +func i_prompt_fuzz(ui HardUI) { + prompt := "Search: " + i_draw_text(ui.s, + 1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[DEF_STYLE], prompt) + ui.s.ShowCursor(len(prompt) + 1 + + ui.buff.cursor, ui.dim[H] - 1) +} + func i_draw_remove_share(ui HardUI) { text := "Really remove this share?" @@ -819,6 +828,7 @@ func i_ui(data_dir string) { INSERT_MODE: e_insert_events, RENAME_MODE: e_rename_events, HELP_MODE: e_help_events, + FUZZ_MODE: e_fuzz_events, } for { data.ui.s.Clear() @@ -861,6 +871,8 @@ func i_ui(data_dir string) { i_prompt_insert(data.ui, data.litems.curr) case HELP_MODE: i_draw_help(&data.ui) + case FUZZ_MODE: + i_prompt_fuzz(data.ui) } if len(data.ui.match_buff) > 0 { i_draw_match_buff(data.ui) -- cgit v1.2.3