diff options
Diffstat (limited to '')
-rw-r--r-- | c_exec.go | 11 | ||||
-rw-r--r-- | c_hardflip.go | 5 | ||||
-rw-r--r-- | c_init.go | 4 | ||||
-rw-r--r-- | i_events.go | 39 | ||||
-rw-r--r-- | i_ui.go | 153 |
5 files changed, 113 insertions, 99 deletions
@@ -128,11 +128,10 @@ func c_format_rdp(host *HostNode) []string { return cmd_fmt } -func c_format_cmd(id uint64, lhost *HostList) { - host := lhost.head +func c_format_cmd(dir_id, host_id uint64, ldirs *DirsList) { var cmd_fmt []string + host := ldirs.sel(dir_id).lhost.sel(host_id) - host = lhost.sel(id) if host == nil { c_die("host id not found", nil) } @@ -146,9 +145,9 @@ func c_format_cmd(id uint64, lhost *HostList) { c_exec_cmd(cmd_fmt) } -func c_exec(id uint64, lhost *HostList) { - if lhost.head == nil { +func c_exec(dir_id, host_id uint64, ldirs *DirsList) { + if ldirs.head == nil { return } - c_format_cmd(id, lhost) + c_format_cmd(dir_id, host_id, ldirs) } diff --git a/c_hardflip.go b/c_hardflip.go index f7585b4..f0c663f 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -57,11 +57,12 @@ type HardData struct { func main() { data_dir := c_get_data_dir() - ldirs := c_load_data_dir(data_dir) + opts := HardOpts{true, true, false} + ldirs := c_load_data_dir(data_dir, opts) data := HardData{ ldirs, HardUI{}, - HardOpts{true, true, false}, + opts, data_dir, } // dir := data.ldirs.head @@ -94,11 +94,11 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, ldirs *DirsList, } } -func c_load_data_dir(dir string) *DirsList { +func c_load_data_dir(dir string, opts HardOpts) *DirsList { ldirs := DirsList{} var id uint64 id = 0 - c_recurse_data_dir("", data.opts, dir + "/", &ldirs, &id, "", nil, 1) + c_recurse_data_dir("", dir + "/", opts, &ldirs, &id, "", nil, 1) return &ldirs } diff --git a/i_events.go b/i_events.go index 5c5a45c..6e3bdc5 100644 --- a/i_events.go +++ b/i_events.go @@ -53,25 +53,24 @@ import ( ) func i_reload_data(data *HardData) { - data.lhost, _ = c_load_data_dir(data.data_dir) - l := data.lhost - data.ui.sel_max = l.count() + 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) } func i_delete_host(data *HardData) { - ui := &data.ui - host := data.lhost.sel(data.ui.sel) - file_path := data.data_dir + "/" + host.Folder + host.Filename - - if err := os.Remove(file_path); err != nil { - c_die("can't remove " + file_path, err) - } - data.lhost.del(data.ui.sel) - data.lhost.reset_id() - ui.sel_max = data.lhost.count() - if ui.sel >= ui.sel_max { - ui.sel = ui.sel_max - 1 - } +// ui := &data.ui +// host := data.lhost.sel(data.ui.sel) +// file_path := data.data_dir + "/" + host.Folder + host.Filename +// +// if err := os.Remove(file_path); err != nil { +// c_die("can't remove " + file_path, err) +// } +// data.lhost.del(data.ui.sel) +// data.lhost.reset_id() +// ui.sel_max = data.lhost.count() +// if ui.sel >= ui.sel_max { +// ui.sel = ui.sel_max - 1 +// } } // screen events such as keypresses @@ -103,12 +102,14 @@ func i_events(data *HardData) { ui.sel = 0 } else if event.Rune() == 'G' { ui.sel = ui.sel_max - 1 - } else if event.Rune() == 'D' && data.lhost.head != nil { + } 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, data.lhost) - if data.opts.loop == false { + c_exec(ui.sel, ui.sel, data.ldirs) + if data.opts.Loop == false { os.Exit(0) } if ui.s, err = tcell.NewScreen(); err != nil { @@ -60,6 +60,8 @@ type HardUI struct { mode uint8 sel uint64 sel_max uint64 + count_dirs uint64 + count_hosts uint64 def_style tcell.Style title_style tcell.Style dim [2]int @@ -151,80 +153,86 @@ func i_draw_zhosts_box(ui HardUI) { } func i_draw_delete_box(ui HardUI, host *HostNode) { - text := "Really delete this host?" - file := host.Folder + host.Filename - max_len := len(text) - - if max_len < len(file) { - max_len = len(file) - } - left, right := - (ui.dim[W] / 2) - (max_len / 2) - 5, - (ui.dim[W] / 2) + (max_len / 2) + 5 - if left < ui.dim[W] / 8 { - left = ui.dim[W] / 8 - } - if right > ui.dim[W] - ui.dim[W] / 8 - 1 { - right = ui.dim[W] - ui.dim[W] / 8 - 1 - } - top, bot := - (ui.dim[H] / 2) - 4, - (ui.dim[H] / 2) + 3 - i_draw_box(ui.s, left, top, right, bot, "", true) - left = (ui.dim[W] / 2) - (len(text) / 2) - if left < (ui.dim[W] / 8) + 1 { - left = (ui.dim[W] / 8) + 1 - } - top = ui.dim[H] / 2 - 2 - i_draw_text(ui.s, - left, top, right, top, - ui.def_style, text) - left = (ui.dim[W] / 2) - (len(file) / 2) - if left < (ui.dim[W] / 8) + 1 { - left = (ui.dim[W] / 8) + 1 - } - top += 1 - i_draw_text(ui.s, - left, top, right, top, - ui.def_style.Bold(true), file) - left = right - 11 - if left < (ui.dim[W] / 8) + 1 { - left = (ui.dim[W] / 8) + 1 - } - top = ui.dim[H] / 2 + 1 - i_draw_text(ui.s, - left, top, right, top, - ui.def_style.Bold(true).Underline(true), "y") - i_draw_text(ui.s, - left + 1, top, right, top, - ui.def_style, "es | ") - i_draw_text(ui.s, - left + 6, top, right, top, - ui.def_style.Bold(true).Underline(true), "n") - i_draw_text(ui.s, - left + 7, top, right, top, - ui.def_style, "o") + // text := "Really delete this host?" + // file := host.Folder + host.Filename + // max_len := len(text) + // + // if max_len < len(file) { + // max_len = len(file) + // } + // left, right := + // (ui.dim[W] / 2) - (max_len / 2) - 5, + // (ui.dim[W] / 2) + (max_len / 2) + 5 + // if left < ui.dim[W] / 8 { + // left = ui.dim[W] / 8 + // } + // if right > ui.dim[W] - ui.dim[W] / 8 - 1 { + // right = ui.dim[W] - ui.dim[W] / 8 - 1 + // } + // top, bot := + // (ui.dim[H] / 2) - 4, + // (ui.dim[H] / 2) + 3 + // i_draw_box(ui.s, left, top, right, bot, "", true) + // left = (ui.dim[W] / 2) - (len(text) / 2) + // if left < (ui.dim[W] / 8) + 1 { + // left = (ui.dim[W] / 8) + 1 + // } + // top = ui.dim[H] / 2 - 2 + // i_draw_text(ui.s, + // left, top, right, top, + // ui.def_style, text) + // left = (ui.dim[W] / 2) - (len(file) / 2) + // if left < (ui.dim[W] / 8) + 1 { + // left = (ui.dim[W] / 8) + 1 + // } + // top += 1 + // i_draw_text(ui.s, + // left, top, right, top, + // ui.def_style.Bold(true), file) + // left = right - 11 + // if left < (ui.dim[W] / 8) + 1 { + // left = (ui.dim[W] / 8) + 1 + // } + // top = ui.dim[H] / 2 + 1 + // i_draw_text(ui.s, + // left, top, right, top, + // ui.def_style.Bold(true).Underline(true), "y") + // i_draw_text(ui.s, + // left + 1, top, right, top, + // ui.def_style, "es | ") + // i_draw_text(ui.s, + // left + 6, top, right, top, + // ui.def_style.Bold(true).Underline(true), "n") + // i_draw_text(ui.s, + // left + 7, top, right, top, + // ui.def_style, "o") } func i_host_panel(ui HardUI, opts HardOpts, ldirs *DirsList) { i_draw_box(ui.s, 0, 0, ui.dim[W] / 3, ui.dim[H] - 2, " Hosts ", false) - host := lhost.head - icons := [2]string{" ", " "} - for i := 0; i < ui.list_start && host.next != nil; i++ { - host = host.next + // host := lhost.head + dirs := ldirs.head + // prot_icons := [2]string{" ", " "} + dirs_icons := [2]string{" ", " "} + for i := 0; i < ui.list_start && dirs.next != nil; i++ { + dirs = dirs.next } - for line := 1; line < ui.dim[H] - 2 && host != nil; line++ { + for line := 1; line < ui.dim[H] - 2 && dirs != nil; line++ { style := ui.def_style - if ui.sel == host.ID { + if ui.sel == dirs.ID { style = ui.def_style.Reverse(true) } text := "" - if opts.icon == true { - text = icons[host.Type] + if opts.Icon == true { + var fold_var uint8 + if dirs.Folded == true { + fold_var = 1 + } + text = dirs_icons[fold_var] } - text += host.Folder + host.Name + text += dirs.Name spaces := "" for i := 0; i < (ui.dim[W] / 3) - len(text) + 1; i++ { spaces += " " @@ -233,7 +241,7 @@ func i_host_panel(ui HardUI, opts HardOpts, ldirs *DirsList) { i_draw_text(ui.s, 1, line, ui.dim[W] / 3, line, style, text) - host = host.next + dirs = dirs.next } if ui.sel_max == 0 { i_draw_text(ui.s, @@ -300,7 +308,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { ui.def_style, strconv.Itoa(int(host.Port))) curr_line += 1 // RDP shit - if host.Type == 1 { + if host.Protocol == 1 { if len(host.Domain) > 0 { i_draw_text(ui.s, (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line, @@ -329,7 +337,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { ui.def_style, "***") curr_line += 1 } - if host.Type == 0 && len(host.Priv) > 0 { + if host.Protocol == 0 && len(host.Priv) > 0 { i_draw_text(ui.s, (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line, ui.title_style, "Privkey: ") @@ -340,7 +348,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { } curr_line += 1 // jump - if host.Type == 0 && len(host.Jump) > 0 { + if host.Protocol == 0 && len(host.Jump) > 0 { i_draw_text(ui.s, (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line, ui.title_style, "Jump settings: ") @@ -375,7 +383,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { ui.def_style, "***") curr_line += 1 } - if host.Type == 0 && len(host.JumpPriv) > 0 { + if host.Protocol == 0 && len(host.JumpPriv) > 0 { i_draw_text(ui.s, (ui.dim[W] / 3) + 5, curr_line, ui.dim[W] - 2, curr_line, ui.title_style, "Privkey: ") @@ -387,7 +395,7 @@ func i_info_panel(ui HardUI, lhost *HostList) { curr_line += 1 } // RDP shit - if host.Type == 1 { + if host.Protocol == 1 { qual := [3]string{"Low", "Medium", "High"} i_draw_text(ui.s, (ui.dim[W] / 3) + 4, curr_line, ui.dim[W] - 2, curr_line, @@ -426,12 +434,17 @@ func i_info_panel(ui HardUI, lhost *HostList) { } } +func i_get_sel_max(ldirs *DirsList) (uint64, uint64, uint64) { + count_dirs, count_hosts := ldirs.count() + + return count_dirs + count_hosts, count_dirs, count_hosts +} + func i_ui(data *HardData) { var err error ui := &data.ui ui.s, err = tcell.NewScreen() - count_dirs, count_hosts := data.ldirs.count() - ui.sel_max = count_dirs + count_hosts + ui.sel_max, ui.count_dirs, ui.count_hosts = i_get_sel_max(data.ldirs) if err != nil { c_die("view", err) |