diff options
author | Joe <rbo@gmx.us> | 2024-04-15 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-04-15 20:20:20 +0200 |
commit | 066c457a15182adec0d1eee5e2c2b620e0d23a3e (patch) | |
tree | 3d6565405b16e718e01c6b21bfcf2eb97206e37b | |
parent | coool (diff) | |
download | hardflip-066c457a15182adec0d1eee5e2c2b620e0d23a3e.tar.gz hardflip-066c457a15182adec0d1eee5e2c2b620e0d23a3e.tar.bz2 hardflip-066c457a15182adec0d1eee5e2c2b620e0d23a3e.tar.xz hardflip-066c457a15182adec0d1eee5e2c2b620e0d23a3e.tar.zst hardflip-066c457a15182adec0d1eee5e2c2b620e0d23a3e.zip |
progress
-rw-r--r-- | src/c_defs.go | 1 | ||||
-rw-r--r-- | src/c_lhosts.go | 1 | ||||
-rw-r--r-- | src/i_events.go | 82 | ||||
-rw-r--r-- | src/i_insert.go | 173 | ||||
-rw-r--r-- | src/i_ui.go | 33 |
5 files changed, 208 insertions, 82 deletions
diff --git a/src/c_defs.go b/src/c_defs.go index 12ccc90..4d185b5 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -130,6 +130,7 @@ const ( INS_RDP_SCREENSIZE INS_RDP_DYNAMIC INS_RDP_QUALITY + INS_RDP_DRIVE // TODO: here INS_RDP_OK ) diff --git a/src/c_lhosts.go b/src/c_lhosts.go index 04595e8..cb2279a 100644 --- a/src/c_lhosts.go +++ b/src/c_lhosts.go @@ -96,6 +96,7 @@ type HostNode struct { Silent bool `yaml:"silent,omitempty"` Shell []string `yaml:"shell,omitempty"` Stack StackSettings `yaml:"openstack,omitempty"` + drive_keys []string filename string parent *DirsNode next *HostNode diff --git a/src/i_events.go b/src/i_events.go index 6468588..9d40333 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -280,15 +280,15 @@ func i_delete_host(data *HardData) error { return nil } -func i_readline(event *tcell.EventKey, data *HardData) { - if len(data.ui.buff) > 0 && +func i_readline(event *tcell.EventKey, buffer *string) { + if len(*buffer) > 0 && (event.Key() == tcell.KeyBackspace || event.Key() == tcell.KeyBackspace2) { - data.ui.buff = data.ui.buff[:len(data.ui.buff) - 1] + *buffer = (*buffer)[:len(*buffer) - 1] } else if event.Key() == tcell.KeyCtrlU { - data.ui.buff = "" + *buffer = "" } else if event.Rune() >= 32 && event.Rune() <= 126 { - data.ui.buff += string(event.Rune()) + *buffer += string(event.Rune()) } } @@ -318,6 +318,13 @@ func i_mkdir(data *HardData, ui *HardUI) { } } +func i_set_drive_keys(data *HardData) { + data.insert.drive_keys = nil + for key := range data.insert.Drive { + data.insert.drive_keys = append(data.insert.drive_keys, key) + } +} + func i_set_protocol_defaults(data *HardData, in *HostNode) { switch in.Protocol { case PROTOCOL_SSH: @@ -329,7 +336,13 @@ func i_set_protocol_defaults(data *HardData, in *HostNode) { in.Width = 1600 in.Height = 1200 in.Dynamic = true - data.ui.insert_sel_max = INS_RDP_OK + data.insert.Drive = map[string]string{ // WARN: this is a test + "qwe": "a", + "asd": "aaaa", + "zxc": "aaaaaaaaaaaaaaaaaaaaaaaaaaaa", + } + i_set_drive_keys(data) + data.ui.insert_sel_max = INS_RDP_OK + len(data.insert.Drive) case PROTOCOL_CMD: in.Shell = []string{"/bin/sh", "-c"} data.ui.insert_sel_max = 2 @@ -539,6 +552,7 @@ func i_events(data *HardData) { } ui.s.HideCursor() data.insert = &HostNode{} + data.insert.Protocol = 1 // WARN: tests only, remove this i_set_protocol_defaults(data, data.insert) data.insert.Name = ui.buff ui.buff = "" @@ -548,7 +562,7 @@ func i_events(data *HardData) { data.insert.parent = data.ldirs.head } } else { - i_readline(event, data) + i_readline(event, &data.ui.buff) } } else if data.insert != nil { if data.insert_err != nil { @@ -605,6 +619,13 @@ func i_events(data *HardData) { break } data.ui.insert_sel_ok = true + if len(data.insert.Drive) > 0 && + data.ui.insert_sel >= INS_RDP_DRIVE && + data.ui.insert_sel < INS_RDP_DRIVE + + len(data.insert.Drive) { + // TODO: here + data.ui.insert_sel_ok = false + } switch data.ui.insert_sel { case INS_SSH_HOST, INS_RDP_HOST: @@ -635,8 +656,9 @@ func i_events(data *HardData) { case INS_RDP_SCREENSIZE: break case INS_RDP_DYNAMIC: break case INS_RDP_QUALITY: break + case INS_RDP_DRIVE + len(data.insert.Drive): break case INS_SSH_OK, - INS_RDP_OK: + INS_RDP_OK + len(data.insert.Drive): data.ui.insert_sel_ok = false i_insert_check_ok(data, data.insert) if data.insert_err != nil { @@ -650,6 +672,7 @@ func i_events(data *HardData) { event.Key() == tcell.KeyCtrlC { data.ui.insert_sel_ok = false ui.buff = "" + ui.drives_buff = "" ui.s.HideCursor() } switch data.ui.insert_sel { @@ -761,7 +784,46 @@ func i_events(data *HardData) { ui.buff = "" ui.s.HideCursor() } else { - i_readline(event, data) + i_readline(event, &data.ui.buff) + } + case INS_RDP_DRIVE + len(data.insert.Drive): + if len(data.ui.drives_buff) == 0 { + if event.Key() == tcell.KeyEnter { + if len(ui.buff) == 0 { + data.ui.insert_sel_ok = false + data.ui.drives_buff = "" + ui.buff = "" + ui.s.HideCursor() + break + } + data.ui.drives_buff = ui.buff + ui.buff = "" + } else { + i_readline(event, &data.ui.buff) + } + } else { + if event.Key() == tcell.KeyEnter { + if len(ui.buff) == 0 { + data.ui.insert_sel_ok = false + data.ui.drives_buff = "" + ui.buff = "" + ui.s.HideCursor() + break + } + data.ui.insert_sel_ok = false + if len(data.insert.Drive) == 0 { + data.insert.Drive = make(map[string]string) + } + data.insert.Drive[ui.drives_buff] = ui.buff + i_set_drive_keys(data) + data.ui.insert_sel_max = INS_RDP_OK + + len(data.insert.Drive) + ui.drives_buff = "" + ui.buff = "" + ui.s.HideCursor() + } else { + i_readline(event, &data.ui.buff) + } } } } @@ -779,7 +841,7 @@ func i_events(data *HardData) { ui.mode = NORMAL_MODE ui.buff = "" } else { - i_readline(event, data) + i_readline(event, &data.ui.buff) } } } diff --git a/src/i_insert.go b/src/i_insert.go index f51cffd..637f01f 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -219,7 +219,7 @@ func i_insert_check_ok(data *HardData, in *HostNode) { } func i_draw_tick_box(ui HardUI, line int, dim Quad, label string, content bool, - id, selected int, red bool) { + id, selected int) { tbox_style := ui.style[DEF_STYLE].Background(tcell.ColorBlack).Dim(true) if id == selected { @@ -324,15 +324,7 @@ func i_draw_insert_panel(ui HardUI, in *HostNode) { } } -func i_draw_insert_os(ui HardUI, line int, win Quad, in *HostNode) int { - return 0 -} - -func i_draw_insert_cmd(ui HardUI, line int, win Quad, in *HostNode) int { - return 0 -} - -func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int { +func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int { red := false if win.T + line >= win.B { return line } text := "---- Host settings ----" @@ -340,25 +332,18 @@ func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int { win.T + line, ui.style[DEF_STYLE], text) if line += 2; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, - INS_RDP_HOST, ui.insert_sel, false) + INS_SSH_HOST, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)), - INS_RDP_PORT, ui.insert_sel, false); - if line += 1; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "Domain", in.Domain, - INS_RDP_DOMAIN, ui.insert_sel, false); + INS_SSH_PORT, ui.insert_sel, false); if line += 2; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "User", in.User, - INS_RDP_USER, ui.insert_sel, false) + INS_SSH_USER, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, - INS_RDP_PASS, ui.insert_sel, false) - if line += 2; win.T + line >= win.B { return line } - text = "---- RDP File ----" - i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1, - win.T + line, ui.style[DEF_STYLE], text) - if line += 2; win.T + line >= win.B { return line } - if file := in.RDPFile; len(file) > 0 { + INS_SSH_PASS, ui.insert_sel, false) + if line += 1; win.T + line >= win.B { return line } + if file := in.Priv; len(file) > 0 { if file[0] == '~' { home, _ := os.UserHomeDir() file = home + file[1:] @@ -368,8 +353,8 @@ func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int { red = true } } - i_draw_text_box(ui, win.T + line, win, "RDP file", in.RDPFile, - INS_RDP_FILE, ui.insert_sel, red) + i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Priv, + INS_SSH_PRIV, ui.insert_sel, red) if red == true { if line += 1; win.T + line >= win.B { return line } text := "file does not exist" @@ -378,26 +363,48 @@ func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int { } red = false if line += 2; win.T + line >= win.B { return line } - text = "---- Window settings ----" + text = "---- Jump settings ----" i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1, win.T + line, ui.style[DEF_STYLE], text) if line += 2; win.T + line >= win.B { return line } - screensize := strconv.Itoa(int(in.Width)) + "x" + - strconv.Itoa(int(in.Height)) - i_draw_text_box(ui, win.T + line, win, "Window size", screensize, - INS_RDP_SCREENSIZE, ui.insert_sel, red) + i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Jump.Host, + INS_SSH_JUMP_HOST, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } - i_draw_tick_box(ui, win.T + line, win, "Dynamic window", in.Dynamic, - INS_RDP_DYNAMIC, ui.insert_sel, red) + i_draw_text_box(ui, win.T + line, win, "Port", + strconv.Itoa(int(in.Jump.Port)), + INS_SSH_JUMP_PORT, ui.insert_sel, false) + if line += 2; win.T + line >= win.B { return line } + i_draw_text_box(ui, win.T + line, win, "User", in.Jump.User, + INS_SSH_JUMP_USER, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "Quality", RDP_QUALITY[in.Quality], - INS_RDP_QUALITY, ui.insert_sel, red) + i_draw_text_box(ui, win.T + line, win, "Pass", in.Jump.Pass, + INS_SSH_JUMP_PASS, ui.insert_sel, false) + if line += 1; win.T + line >= win.B { return line} + if len(in.Jump.Priv) > 0 { + file := in.Jump.Priv + if file[0] == '~' { + home, _ := os.UserHomeDir() + file = home + file[1:] + } + if stat, err := os.Stat(file); + err != nil || stat.IsDir() == true { + red = true + } + } + i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Jump.Priv, + INS_SSH_JUMP_PRIV, ui.insert_sel, red) + if red == true { + if line += 1; win.T + line >= win.B { return line } + text := "file does not exist" + i_draw_text(ui.s, ui.dim[W] / 2, win.T + line, + win.R - 1, win.T + line, ui.style[ERR_STYLE], text) + } if line += 2; win.T + line >= win.B { return line } - i_draw_ok_butt(ui, win.T + line, INS_RDP_OK, ui.insert_sel) + i_draw_ok_butt(ui, win.T + line, INS_SSH_OK, ui.insert_sel) return line } -func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int { +func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int { red := false if win.T + line >= win.B { return line } text := "---- Host settings ----" @@ -405,18 +412,25 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int { win.T + line, ui.style[DEF_STYLE], text) if line += 2; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, - INS_SSH_HOST, ui.insert_sel, false) + INS_RDP_HOST, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)), - INS_SSH_PORT, ui.insert_sel, false); + INS_RDP_PORT, ui.insert_sel, false); + if line += 1; win.T + line >= win.B { return line } + i_draw_text_box(ui, win.T + line, win, "Domain", in.Domain, + INS_RDP_DOMAIN, ui.insert_sel, false); if line += 2; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "User", in.User, - INS_SSH_USER, ui.insert_sel, false) + INS_RDP_USER, ui.insert_sel, false) if line += 1; win.T + line >= win.B { return line } i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, - INS_SSH_PASS, ui.insert_sel, false) - if line += 1; win.T + line >= win.B { return line } - if file := in.Priv; len(file) > 0 { + INS_RDP_PASS, ui.insert_sel, false) + if line += 2; win.T + line >= win.B { return line } + text = "---- RDP File ----" + i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1, + win.T + line, ui.style[DEF_STYLE], text) + if line += 2; win.T + line >= win.B { return line } + if file := in.RDPFile; len(file) > 0 { if file[0] == '~' { home, _ := os.UserHomeDir() file = home + file[1:] @@ -426,8 +440,8 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int { red = true } } - i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Priv, - INS_SSH_PRIV, ui.insert_sel, red) + i_draw_text_box(ui, win.T + line, win, "RDP file", in.RDPFile, + INS_RDP_FILE, ui.insert_sel, red) if red == true { if line += 1; win.T + line >= win.B { return line } text := "file does not exist" @@ -436,43 +450,58 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int { } red = false if line += 2; win.T + line >= win.B { return line } - text = "---- Jump settings ----" + text = "---- Window settings ----" i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1, win.T + line, ui.style[DEF_STYLE], text) if line += 2; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Jump.Host, - INS_SSH_JUMP_HOST, ui.insert_sel, false) + screensize := strconv.Itoa(int(in.Width)) + "x" + + strconv.Itoa(int(in.Height)) + i_draw_text_box(ui, win.T + line, win, "Window size", screensize, + INS_RDP_SCREENSIZE, ui.insert_sel, red) if line += 1; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "Port", - strconv.Itoa(int(in.Jump.Port)), - INS_SSH_JUMP_PORT, ui.insert_sel, false) - if line += 2; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "User", in.Jump.User, - INS_SSH_JUMP_USER, ui.insert_sel, false) + i_draw_tick_box(ui, win.T + line, win, "Dynamic window", in.Dynamic, + INS_RDP_DYNAMIC, ui.insert_sel) if line += 1; win.T + line >= win.B { return line } - i_draw_text_box(ui, win.T + line, win, "Pass", in.Jump.Pass, - INS_SSH_JUMP_PASS, ui.insert_sel, false) - if line += 1; win.T + line >= win.B { return line} - if len(in.Jump.Priv) > 0 { - file := in.Jump.Priv - if file[0] == '~' { - home, _ := os.UserHomeDir() - file = home + file[1:] + i_draw_text_box(ui, win.T + line, win, "Quality", RDP_QUALITY[in.Quality], + INS_RDP_QUALITY, ui.insert_sel, red) + if line += 2; win.T + line >= win.B { return line } + text = "---- Share mounts ----" + i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1, + win.T + line, ui.style[DEF_STYLE], text) + if line += 2; win.T + line >= win.B { return line } + for k, v := range in.drive_keys { + if dir := in.Drive[v]; len(dir) > 0 { + if dir[0] == '~' { + home, _ := os.UserHomeDir() + dir = home + dir[1:] + } + if stat, err := os.Stat(dir); + err != nil || stat.IsDir() == false { + red = true + } } - if stat, err := os.Stat(file); - err != nil || stat.IsDir() == true { - red = true + i_draw_text_box(ui, win.T + line, win, "Share " + strconv.Itoa(k + 1), + "(" + v + "): " + in.Drive[v], + INS_RDP_DRIVE + k, ui.insert_sel, red) + if red == true { + if line += 1; win.T + line >= win.B { return line } + text := "path is not a directory" + i_draw_text(ui.s, ui.dim[W] / 2, win.T + line, + win.R - 1, win.T + line, ui.style[ERR_STYLE], text) } - } - i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Jump.Priv, - INS_SSH_JUMP_PRIV, ui.insert_sel, red) - if red == true { if line += 1; win.T + line >= win.B { return line } - text := "file does not exist" - i_draw_text(ui.s, ui.dim[W] / 2, win.T + line, - win.R - 1, win.T + line, ui.style[ERR_STYLE], text) } + i_draw_text_box(ui, win.T + line, win, "Add share", "", + INS_RDP_DRIVE + len(in.Drive), ui.insert_sel, false) if line += 2; win.T + line >= win.B { return line } - i_draw_ok_butt(ui, win.T + line, INS_SSH_OK, ui.insert_sel) + i_draw_ok_butt(ui, win.T + line, INS_RDP_OK + len(in.Drive), ui.insert_sel) return line } + +func i_draw_insert_os(ui HardUI, line int, win Quad, in *HostNode) int { + return 0 +} + +func i_draw_insert_cmd(ui HardUI, line int, win Quad, in *HostNode) int { + return 0 +} diff --git a/src/i_ui.go b/src/i_ui.go index c8b9a3d..d4278e2 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -67,6 +67,7 @@ type HardUI struct { dim [2]int err [2]string buff string + drives_buff string insert_sel int insert_sel_max int insert_sel_ok bool @@ -404,6 +405,32 @@ func i_prompt_generic(ui HardUI, prompt string, secret bool, home_dir string) { ui.s.ShowCursor(len(prompt) + 1 + len(ui.buff), ui.dim[H] - 1) } +func i_prompt_dir(ui HardUI, prompt string, home_dir string) { + i_draw_text(ui.s, + 1, ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[DEF_STYLE], prompt) + style := ui.style[DEF_STYLE].Bold(true) + if len(home_dir) > 0 && len(ui.buff) > 0 { + file := ui.buff + if file[0] == '~' { + file = home_dir + file[1:] + } + if stat, err := os.Stat(file); + err != nil { + style = style.Foreground(tcell.ColorRed) + } else if stat.IsDir() == true { + style = style.Foreground(tcell.ColorGreen). + Bold(true) + } else { + style = style.Foreground(tcell.ColorRed) + } + } + i_draw_text(ui.s, len(prompt) + 1, + ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + style, ui.buff) + ui.s.ShowCursor(len(prompt) + 1 + len(ui.buff), ui.dim[H] - 1) +} + func i_prompt_insert(ui HardUI, curr *ItemsNode) { path := "/" if curr != nil { @@ -712,6 +739,12 @@ func i_ui(data_dir string) { case INS_RDP_QUALITY: i_prompt_list(data.ui, "Quality", "Quality:", RDP_QUALITY[:]) + case INS_RDP_DRIVE + len(data.insert.Drive): + if len(data.ui.drives_buff) == 0 { + i_prompt_generic(data.ui, "Name: ", false, "") + } else { + i_prompt_dir(data.ui, "Local directory: ", home_dir) + } } } else if data.insert_err != nil { i_draw_insert_err_msg(data.ui, data.insert_err) |