diff options
author | Joe <rbo@gmx.us> | 2024-05-16 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-05-16 20:20:20 +0200 |
commit | c545dd21171200889053694804eae6ca839379a2 (patch) | |
tree | 9295f4df134839a2a7a468a994a8b096b6dc89d0 /src | |
parent | v0.7 (diff) | |
download | hardflip-c545dd21171200889053694804eae6ca839379a2.tar.gz hardflip-c545dd21171200889053694804eae6ca839379a2.tar.bz2 hardflip-c545dd21171200889053694804eae6ca839379a2.tar.xz hardflip-c545dd21171200889053694804eae6ca839379a2.tar.zst hardflip-c545dd21171200889053694804eae6ca839379a2.zip |
prompt ssh ok
Diffstat (limited to 'src')
-rw-r--r-- | src/c_defs.go | 8 | ||||
-rw-r--r-- | src/c_exec.go | 4 | ||||
-rw-r--r-- | src/c_init.go | 5 | ||||
-rw-r--r-- | src/e_keys.go | 21 | ||||
-rw-r--r-- | src/i_ui.go | 78 |
5 files changed, 82 insertions, 34 deletions
diff --git a/src/c_defs.go b/src/c_defs.go index e6fcf79..5d24337 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -86,6 +86,13 @@ const ( ) const ( + WELCOME_GPG = iota + WELCOME_CONFIRM_GPG + WELCOME_SSH + WELCOME_END +) + +const ( W = 0 H = 1 ) @@ -234,5 +241,6 @@ var DEFAULT_OPTS = HardOpts{ false, "", "", + "", } diff --git a/src/c_exec.go b/src/c_exec.go index eb711cd..4913ff4 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -210,7 +210,7 @@ func c_format_cmd(host *HostNode, opts HardOpts, if len(gpg) > 0 && gpg != "plain" && len(host.Pass) > 0 { i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " GnuPG ") text := "decryption using gpg..." - left, right := i_left_right(len(text), ui) + left, right := i_left_right(len(text), *ui) i_draw_text(ui.s, left, ui.dim[H] - 3, right, ui.dim[H] - 3, ui.style[DEF_STYLE], text) ui.s.Show() @@ -297,7 +297,7 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { } else { i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " Exec ") text := "running command..." - left, right := i_left_right(len(text), ui) + left, right := i_left_right(len(text), *ui) i_draw_text(ui.s, left, ui.dim[H] - 3, right, ui.dim[H] - 3, ui.style[DEF_STYLE], text) ui.s.Show() diff --git a/src/c_init.go b/src/c_init.go index a24e3d4..3faca8e 100644 --- a/src/c_init.go +++ b/src/c_init.go @@ -64,6 +64,7 @@ type HardOpts struct { GPG string `yaml:"gpg"` Perc bool `yaml:"percent"` Term string `yaml:"terminal"` + DefSSH string `yaml:"default_ssh_priv"` file string } @@ -86,7 +87,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, nil, } ldirs.add_back(&dir_node) - i_draw_load_ui(ui, opts) + i_draw_load_ui(ui) for _, file := range files { filename := file.Name() if file.IsDir() == true { @@ -104,7 +105,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, } dir_node.lhost.add_back(host_node) } - i_draw_load_ui(ui, opts) + i_draw_load_ui(ui) } } } diff --git a/src/e_keys.go b/src/e_keys.go index bc30053..8094dd1 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -294,20 +294,33 @@ func e_welcome_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { ui.s.Fini() os.Exit(0) } - if len(data.opts.GPG) == 0 { + switch ui.welcome_screen { + case WELCOME_GPG: if event.Rune() < '1' || event.Rune() > '9' { return true } else { data.opts.GPG = data.keys[event.Rune() - 48 - 1][0] ui.s.HideCursor() + ui.welcome_screen += 1 } - } else { + case WELCOME_CONFIRM_GPG: if event.Rune() == 'y' { - ui.mode = NORMAL_MODE - c_write_options(data.opts.file, data.opts, &data.load_err) + ui.welcome_screen += 1 } else if event.Rune() == 'n' { data.opts.GPG = "" + ui.welcome_screen -= 1 + } + case WELCOME_SSH: + if event.Key() == tcell.KeyEnter { + data.opts.DefSSH = ui.buff.str() + ui.welcome_screen += 1 + ui.s.HideCursor() + ui.buff.empty() + } else { + e_readline(event, &ui.buff, ui, data.home_dir) } + case WELCOME_END: + return false } return false } diff --git a/src/i_ui.go b/src/i_ui.go index c0f6c29..5036589 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -83,6 +83,7 @@ type HardUI struct { insert_butt bool help_scroll int help_end bool + welcome_screen int } type Quad struct { @@ -107,7 +108,7 @@ func (buffer *Buffer)len() int { return len(buffer.data) } -func i_left_right(text_len int, ui *HardUI) (int, 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 if left < 1 { @@ -204,8 +205,7 @@ func i_draw_msg(s tcell.Screen, lines int, box_style tcell.Style, box_style, title) } -func i_draw_bottom_text(ui HardUI, opts HardOpts, - insert *HostNode, insert_err []error) { +func i_draw_bottom_text(ui HardUI, insert *HostNode, insert_err []error) { text := "" if len(ui.msg_buff) > 0 { @@ -221,9 +221,7 @@ func i_draw_bottom_text(ui HardUI, opts HardOpts, case ERROR_MODE: text = ERROR_KEYS_HINTS case WELCOME_MODE: - if len(opts.GPG) == 0 { - text = "" - } else { + if ui.welcome_screen == WELCOME_CONFIRM_GPG { text = CONFIRM_KEYS_HINTS } case INSERT_MODE: @@ -275,8 +273,8 @@ func i_draw_welcome_box(ui HardUI) { if len(VERSION_NAME) > 0 { text += " - " + VERSION_NAME } - l, r := ui.dim[W] / 2 - len(text) / 2 + 7, - ui.dim[W] / 2 + len(text) / 2 + 1 + 7 + l, r := ui.dim[W] / 2 + 4, + ui.dim[W] - 2 if l < l_max { l = l_max }; if r > r_max { r = r_max } i_draw_text(ui.s, l, line, r, line, ui.style[DEF_STYLE], text) if line += 2; line > b_max { return } @@ -361,21 +359,42 @@ func i_prompt_confirm_gpg(ui HardUI, opts HardOpts) { if opts.GPG == "plain" { i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " Confirm plaintext ") text := "Really use plaintext to store passwords?" - l, r := i_left_right(len(text), &ui) + l, r := i_left_right(len(text), ui) i_draw_text(ui.s, l, ui.dim[H] - 3, r, ui.dim[H] - 3, ui.style[DEF_STYLE], text) return } i_draw_msg(ui.s, 2, ui.style[BOX_STYLE], ui.dim, " Confirm GnuPG key ") text := "Really use this gpg key?" - l, r := i_left_right(len(text), &ui) + l, r := i_left_right(len(text), ui) i_draw_text(ui.s, l, ui.dim[H] - 4, r, ui.dim[H] - 4, ui.style[DEF_STYLE], text) - l, r = i_left_right(len(opts.GPG), &ui) + l, r = i_left_right(len(opts.GPG), ui) i_draw_text(ui.s, l, ui.dim[H] - 3, r, ui.dim[H] - 3, ui.style[DEF_STYLE], opts.GPG) } +func i_prompt_def_sshkey(ui HardUI, home_dir string) { + i_draw_msg(ui.s, 4, ui.style[BOX_STYLE], ui.dim, " Default SSH key ") + text := "Please enter here a path for your most used SSH key" + l, r := i_left_right(len(text), ui) + i_draw_text(ui.s, l, ui.dim[H] - 6, r, ui.dim[H] - 6, + ui.style[DEF_STYLE],text) + text = "It will be entered by default when adding SSH hosts" + l, r = i_left_right(len(text), ui) + i_draw_text(ui.s, l, ui.dim[H] - 5, r, ui.dim[H] - 5, + ui.style[DEF_STYLE],text) + text = "This can save some time" + l, r = i_left_right(len(text), ui) + i_draw_text(ui.s, l, ui.dim[H] - 4, r, ui.dim[H] - 4, + ui.style[DEF_STYLE],text) + text = "Leave empty if you don't want to set a default key" + l, r = i_left_right(len(text), ui) + i_draw_text(ui.s, l, ui.dim[H] - 3, r, ui.dim[H] - 3, + ui.style[DEF_STYLE],text) + i_prompt_generic(ui, "SSH private key: ", false, home_dir) +} + func i_prompt_mkdir(ui HardUI, curr *ItemsNode) { path := "/" if curr != nil { @@ -499,7 +518,7 @@ func i_draw_remove_share(ui HardUI) { text := "Really remove this share?" i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " Remove share ") - left, right := i_left_right(len(text), &ui) + left, right := i_left_right(len(text), ui) line := ui.dim[H] - 2 - 1 i_draw_text(ui.s, left, line, right, line, ui.style[DEF_STYLE], text) } @@ -507,7 +526,7 @@ func i_draw_remove_share(ui HardUI) { func i_draw_zhosts_box(ui HardUI) { i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " No hosts ") text := "Hosts list empty. Add hosts/folders by pressing (a/m)" - left, right := i_left_right(len(text), &ui) + left, right := i_left_right(len(text), ui) i_draw_text(ui.s, left, ui.dim[H] - 2 - 1, right, ui.dim[H] - 2 - 1, ui.style[DEF_STYLE], text) } @@ -525,10 +544,10 @@ func i_draw_delete_msg(ui HardUI, item *ItemsNode) { } file = file[1:] i_draw_msg(ui.s, 2, ui.style[BOX_STYLE], ui.dim, " Delete ") - left, right := i_left_right(len(text), &ui) + left, right := i_left_right(len(text), ui) line := ui.dim[H] - 2 - 2 i_draw_text(ui.s, left, line, right, line, ui.style[DEF_STYLE], text) - left, right = i_left_right(len(file), &ui) + left, right = i_left_right(len(file), ui) line += 1 i_draw_text(ui.s, left, line, right, line, @@ -622,7 +641,7 @@ func i_draw_match_buff(ui HardUI) { var g_load_count int = -1 -func i_draw_load_ui(ui *HardUI, opts HardOpts) { +func i_draw_load_ui(ui *HardUI) { g_load_count += 1 if g_load_count % 1000 != 0 { return @@ -635,10 +654,10 @@ func i_draw_load_ui(ui *HardUI, opts HardOpts) { } i_draw_text(ui.s, 1, ui.dim[H] - 1, ui.dim[W], ui.dim[H] - 1, ui.style[BOT_STYLE], text) - i_draw_bottom_text(*ui, opts, nil, nil) + i_draw_bottom_text(*ui, nil, nil) i_draw_msg(ui.s, 1, ui.style[BOX_STYLE], ui.dim, " Loading ") text = "Loading " + strconv.Itoa(g_load_count) + " hosts" - left, right := i_left_right(len(text), ui) + left, right := i_left_right(len(text), *ui) i_draw_text(ui.s, left, ui.dim[H] - 2 - 1, right, ui.dim[H] - 2 - 1, ui.style[DEF_STYLE], text) @@ -761,24 +780,31 @@ func i_ui(data_dir string) { } for { data.ui.s.Clear() - i_draw_bottom_text(data.ui, data.opts, data.insert, data.insert_err) + i_draw_bottom_text(data.ui, data.insert, data.insert_err) i_draw_host_panel(data.ui, data.opts.Icon, data.litems, &data) i_draw_info_panel(data.ui, data.opts.Perc, data.litems) i_draw_scrollhint(data.ui, data.litems) if data.load_err != nil && len(data.load_err) > 0 { data.ui.mode = ERROR_MODE } - if data.ui.mode == WELCOME_MODE { + switch data.ui.mode { + case WELCOME_MODE: i_draw_welcome_box(data.ui) - if len(data.opts.GPG) == 0 { + switch data.ui.welcome_screen { + case WELCOME_GPG: i_prompt_gpg(data.ui, data.keys) - } else { + case WELCOME_CONFIRM_GPG: i_prompt_confirm_gpg(data.ui, data.opts) + case WELCOME_SSH: + i_prompt_def_sshkey(data.ui, data.home_dir) + default: + c_write_options(data.opts.file, data.opts, &data.load_err) + data.ui.mode = NORMAL_MODE + } + case NORMAL_MODE: + if data.litems.head == nil { + i_draw_zhosts_box(data.ui) } - } else if data.litems.head == nil { - i_draw_zhosts_box(data.ui) - } - switch data.ui.mode { case DELETE_MODE: i_draw_delete_msg(data.ui, data.litems.curr) case ERROR_MODE: |