diff options
Diffstat (limited to '')
-rw-r--r-- | c_exec.go | 19 | ||||
-rw-r--r-- | i_events.go | 28 | ||||
-rw-r--r-- | i_ui.go | 46 |
3 files changed, 54 insertions, 39 deletions
@@ -128,26 +128,23 @@ func c_format_rdp(host *HostNode) []string { return cmd_fmt } -func c_format_cmd(dir_id, host_id uint64, ldirs *DirsList) { +func c_format_cmd(host *HostNode) { var cmd_fmt []string - host := ldirs.sel(dir_id).lhost.sel(host_id) - if host == nil { - c_die("host id not found", nil) - } - if host.Protocol == 0 { + switch host.Protocol { + case 0: cmd_fmt = c_format_ssh(host) - } else if host.Protocol == 1 { + case 1: cmd_fmt = c_format_rdp(host) - } else if host.Protocol > 1 { + default: c_die("type not found", nil) } c_exec_cmd(cmd_fmt) } -func c_exec(dir_id, host_id uint64, ldirs *DirsList) { - if ldirs.head == nil { +func c_exec(host *HostNode) { + if host == nil { return } - c_format_cmd(dir_id, host_id, ldirs) + c_format_cmd(host) } diff --git a/i_events.go b/i_events.go index 6e3bdc5..7937f7e 100644 --- a/i_events.go +++ b/i_events.go @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_events.go - * Thu Dec 21 12:49:09 2023 + * Wed Dec 27 17:56:44 2023 * Joe * * events in the code @@ -54,7 +54,9 @@ import ( func i_reload_data(data *HardData) { data.ldirs = c_load_data_dir(data.data_dir, data.opts) - data.ui.sel_max, data.ui.count_dirs, data.ui.count_hosts = i_get_sel_max(data.ldirs) + data.ui.sel_max, + data.ui.count_dirs, + data.ui.count_hosts = i_get_sel_max(data.ldirs) } func i_delete_host(data *HardData) { @@ -90,27 +92,29 @@ func i_events(data *HardData) { os.Exit(0) } else if event.Rune() == 'j' || event.Key() == tcell.KeyDown { - if ui.sel < ui.sel_max - 1 { - ui.sel += 1 + if ui.sel.line < ui.sel_max - 1 { + ui.inc_sel(1) } } else if event.Rune() == 'k' || event.Key() == tcell.KeyUp { - if ui.sel > 0 { - ui.sel -= 1 + if ui.sel.line > 0 { + ui.inc_sel(-1) } } else if event.Rune() == 'g' { - ui.sel = 0 + ui.sel.line = 0 } else if event.Rune() == 'G' { - ui.sel = ui.sel_max - 1 + ui.sel.line = ui.sel_max - 1 } else if event.Rune() == 'D' && data.ldirs.head != nil && ui.sel_max != 0 { ui.mode = DELETE_MODE } else if event.Key() == tcell.KeyEnter { - ui.s.Fini() - c_exec(ui.sel, ui.sel, data.ldirs) - if data.opts.Loop == false { - os.Exit(0) + if ui.sel.host_ptr != nil { + ui.s.Fini() + c_exec(ui.sel.host_ptr) + if data.opts.Loop == false { + os.Exit(0) + } } if ui.s, err = tcell.NewScreen(); err != nil { c_die("view", err) @@ -58,14 +58,28 @@ type HardUI struct { s tcell.Screen list_start int mode uint8 - sel uint64 - sel_max uint64 + sel_max int count_dirs uint64 count_hosts uint64 def_style tcell.Style dir_style tcell.Style title_style tcell.Style dim [2]int + sel HardSelect +} + +type HardSelect struct { + line int + dirs_ptr *DirsNode + host_ptr *HostNode +} + +func (ui *HardUI) inc_sel(n ...int) { + sel := &ui.sel + if n[0] == 0 { + n[0] = 1 + } + sel.line += n[0] } func i_draw_text(s tcell.Screen, @@ -218,7 +232,7 @@ func i_draw_delete_box(ui HardUI, host *HostNode) { func i_host_panel_dirs(ui HardUI, opts HardOpts, dirs *DirsNode, line int) { style := ui.dir_style - if ui.sel == dirs.ID { + if &ui.sel.dirs_ptr == &dirs { style = style.Reverse(true) } text := "" @@ -248,7 +262,7 @@ func i_host_panel_dirs(ui HardUI, opts HardOpts, dirs *DirsNode, line int) { func i_host_panel_host(ui HardUI, opts HardOpts, dirs *DirsNode, host *HostNode, line int) { style := ui.def_style - if ui.sel == host.ID { + if &ui.sel.host_ptr == &host { style = style.Reverse(true) } text := "" @@ -301,7 +315,7 @@ func i_host_panel(ui HardUI, opts HardOpts, ldirs *DirsList) { i_draw_text(ui.s, 1, ui.dim[H] - 2, (ui.dim[W] / 3) - 1, ui.dim[H] - 2, ui.def_style, - " " + strconv.Itoa(int(ui.sel + 1)) + "/" + + " " + strconv.Itoa(int(ui.sel.line + 1)) + "/" + strconv.Itoa(int(ui.sel_max)) + " hosts ") } } @@ -320,7 +334,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { if lhost.head == nil { return } - host = lhost.sel(ui.sel) + host = ui.sel.host_ptr if host.Protocol == 0 { host_type = "SSH" } else if host.Protocol == 1 { @@ -483,10 +497,10 @@ func i_info_panel(ui HardUI, lhost *HostList) { } } -func i_get_sel_max(ldirs *DirsList) (uint64, uint64, uint64) { +func i_get_sel_max(ldirs *DirsList) (int, uint64, uint64) { count_dirs, count_hosts := ldirs.count() - return count_dirs + count_hosts, count_dirs, count_hosts + return int(count_dirs + count_hosts), count_dirs, count_hosts } func i_ui(data *HardData) { @@ -528,15 +542,15 @@ func i_ui(data *HardData) { } ui.s.Show() i_events(data) - if ui.sel >= ui.sel_max { - ui.sel = ui.sel_max - 1 - } else if ui.sel < 0 { - ui.sel = 0 + if ui.sel.line >= ui.sel_max { + ui.sel.line = ui.sel_max - 1 + } else if ui.sel.line < 0 { + ui.sel.line = 0 } - if int(ui.sel) > ui.list_start + ui.dim[H] - 4 { - ui.list_start = int(ui.sel + 1) - ui.dim[H] + 3 - } else if int(ui.sel) < ui.list_start { - ui.list_start = int(ui.sel) + if int(ui.sel.line) > ui.list_start + ui.dim[H] - 4 { + ui.list_start = int(ui.sel.line + 1) - ui.dim[H] + 3 + } else if int(ui.sel.line) < ui.list_start { + ui.list_start = int(ui.sel.line) } } } |