diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_defs.go | 2 | ||||
-rw-r--r-- | src/c_hardflip.go | 3 | ||||
-rw-r--r-- | src/i_events.go | 19 | ||||
-rw-r--r-- | src/i_insert.go | 67 | ||||
-rw-r--r-- | src/i_ui.go | 46 |
5 files changed, 128 insertions, 9 deletions
diff --git a/src/c_defs.go b/src/c_defs.go index 8fa69e6..f7f5efb 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_defs.go - * Tue Feb 13 17:59:26 2024 + * Wed Feb 21 19:40:07 2024 * Joe * * constants diff --git a/src/c_hardflip.go b/src/c_hardflip.go index 72a8f2e..5b4761f 100644 --- a/src/c_hardflip.go +++ b/src/c_hardflip.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_hardflip.go - * Thu Feb 01 14:53:19 2024 + * Wed Feb 21 19:38:57 2024 * Joe * * the main @@ -61,6 +61,7 @@ type HardData struct { data_dir string load_err []error keys [][2]string + insert *HostNode } func main() { diff --git a/src/i_events.go b/src/i_events.go index 3767fa9..7bbda68 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -494,14 +494,33 @@ func i_events(data *HardData) { case INSERT_MODE: if event.Key() == tcell.KeyEscape || event.Key() == tcell.KeyCtrlC { + ui.s.HideCursor() data.ui.mode = NORMAL_MODE + data.insert = nil + ui.buff = "" + } else if event.Key() == tcell.KeyEnter { + if ui.buff == "" { + ui.s.HideCursor() + data.ui.mode = NORMAL_MODE + data.insert = nil + ui.buff = "" + break + } + ui.s.HideCursor() + data.insert = &HostNode{} + data.insert.Name = ui.buff + ui.buff = "" + } else { + i_readline(event, data) } + // TODO: reset data.insert to nil on validate case MKDIR_MODE: if event.Key() == tcell.KeyEscape || event.Key() == tcell.KeyCtrlC { ui.s.HideCursor() ui.buff = "" ui.mode = NORMAL_MODE + data.insert = nil } else if event.Key() == tcell.KeyEnter { i_mkdir(data, ui) ui.s.HideCursor() diff --git a/src/i_insert.go b/src/i_insert.go new file mode 100644 index 0000000..c3b2dfc --- /dev/null +++ b/src/i_insert.go @@ -0,0 +1,67 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * 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/i_insert.go + * Wed Feb 21 19:41:56 2024 + * Joe + * + * insert a new host + */ + +package main + +func i_draw_insert_panel(ui HardUI, in *HostNode) { + if len(in.Name) == 0 { + return + } + win := Quad{ + ui.dim[W] / 8, + ui.dim[H] / 8, + ui.dim[W] - ui.dim[W] / 8, + ui.dim[H] - ui.dim[H] / 8, + } + i_draw_box(ui.s, win.L, win.T, win.R, win.B, + ui.style[STYLE_BOX], ui.style[STYLE_HEAD], + " Insert - " + in.Name + " ", true) +} diff --git a/src/i_ui.go b/src/i_ui.go index 0edcc62..0c9f14c 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Tue Jan 23 18:11:28 2024 + * Wed Feb 21 19:42:11 2024 * Joe * * interfacing with the user @@ -69,6 +69,10 @@ type HardUI struct { buff string } +type Quad struct { + L, R, T, B int +} + func i_left_right(text_len int, ui *HardUI) (int, int) { left := (ui.dim[W] / 2) - text_len / 2 right := ui.dim[W] - 1 @@ -323,7 +327,7 @@ func i_prompt_confirm_gpg(ui HardUI, opts HardOpts) { ui.style[STYLE_DEF], opts.GPG) } -func i_draw_mkdir(ui HardUI, curr *ItemsNode) { +func i_prompt_mkdir(ui HardUI, curr *ItemsNode) { path := "/" if curr != nil { if curr.is_dir() == true { @@ -346,6 +350,29 @@ func i_draw_mkdir(ui HardUI, curr *ItemsNode) { ui.s.ShowCursor(len(prompt) + 1 + len(path) + len(ui.buff), ui.dim[H] - 1) } +func i_prompt_insert(ui HardUI, curr *ItemsNode) { + path := "/" + if curr != nil { + if curr.is_dir() == true { + path = curr.Dirs.path() + } else { + path = curr.Host.Parent.path() + } + } + path = path[1:] + prompt := "name: " + i_draw_text(ui.s, + 1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[STYLE_DEF], prompt) + i_draw_text(ui.s, len(prompt) + 1, + ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[STYLE_DEF], path) + i_draw_text(ui.s, len(prompt) + 1 + len(path), + ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[STYLE_DEF].Bold(true), ui.buff) + ui.s.ShowCursor(len(prompt) + 1 + len(path) + len(ui.buff), ui.dim[H] - 1) +} + func i_draw_zhosts_box(ui HardUI) { i_draw_msg(ui.s, 1, ui.style[STYLE_BOX], ui.dim, " No hosts ") text := "Hosts list empty. Add hosts/folders by pressing (a/m)" @@ -547,6 +574,7 @@ func i_ui(data_dir string) { data_dir, load_err, [][2]string{}, + nil, } if data.opts.GPG == DEFAULT_OPTS.GPG && data.litems.head == nil { data.ui.mode = WELCOME_MODE @@ -573,12 +601,16 @@ func i_ui(data_dir string) { } if data.ui.mode == DELETE_MODE { i_draw_delete_msg(data.ui, data.litems.curr) - } - if data.ui.mode == ERROR_MODE { + } else if data.ui.mode == ERROR_MODE { i_draw_error_msg(data.ui, data.load_err) - } - if data.ui.mode == MKDIR_MODE { - i_draw_mkdir(data.ui, data.litems.curr) + } else if data.ui.mode == MKDIR_MODE { + i_prompt_mkdir(data.ui, data.litems.curr) + } else if data.ui.mode == INSERT_MODE { + if data.insert == nil { + i_prompt_insert(data.ui, data.litems.curr) + } else { + i_draw_insert_panel(data.ui, data.insert) + } } data.ui.s.Show() i_events(&data) |