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 | b33dca29fdf3ccefd16412589feefd66b735a534 (patch) | |
tree | 35f58b8e433e77ec1ab2dcf7381f80c8f9dcfbf9 | |
parent | progress (diff) | |
download | hardflip-b33dca29fdf3ccefd16412589feefd66b735a534.tar.gz hardflip-b33dca29fdf3ccefd16412589feefd66b735a534.tar.bz2 hardflip-b33dca29fdf3ccefd16412589feefd66b735a534.tar.xz hardflip-b33dca29fdf3ccefd16412589feefd66b735a534.tar.zst hardflip-b33dca29fdf3ccefd16412589feefd66b735a534.zip |
up
Diffstat (limited to '')
-rw-r--r-- | src/i_events.go | 103 | ||||
-rw-r--r-- | src/i_insert.go | 37 | ||||
-rw-r--r-- | src/i_ui.go | 15 |
3 files changed, 108 insertions, 47 deletions
diff --git a/src/i_events.go b/src/i_events.go index 9d40333..32fa38d 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -52,6 +52,7 @@ package main import ( + "fmt" "os" "strconv" "strings" @@ -619,13 +620,6 @@ 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: @@ -725,6 +719,48 @@ func i_events(data *HardData) { data.ui.insert_sel_ok = false ui.s.HideCursor() } + 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 + ui.s.Fini() + fmt.Println(data.insert.Drive) + os.Exit(0) + 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) + } + } case INS_SSH_HOST, INS_SSH_PORT, INS_SSH_USER, @@ -786,45 +822,22 @@ func i_events(data *HardData) { } else { 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) - } + } + if len(data.insert.Drive) > 0 && + data.ui.insert_sel >= INS_RDP_DRIVE && + data.ui.insert_sel < INS_RDP_DRIVE + + len(data.insert.Drive) { + if event.Rune() == 'y' || + event.Rune() == 'Y' || + event.Key() == tcell.KeyEnter { + delete(data.insert.Drive, + data.insert.drive_keys[data.ui.insert_sel - + INS_RDP_DRIVE]) + data.ui.insert_sel_max = INS_RDP_OK + + len(data.insert.Drive) + i_set_drive_keys(data) } + data.ui.insert_sel_ok = false } } } diff --git a/src/i_insert.go b/src/i_insert.go index 637f01f..5bc959c 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -87,7 +87,7 @@ func i_insert_format_filename(name, path string) string { } func i_insert_abs_files(insert *HostNode) { - files := [3]*string{ + files := []*string{ &insert.Priv, &insert.Jump.Priv, &insert.RDPFile, @@ -105,6 +105,19 @@ func i_insert_abs_files(insert *HostNode) { *v, _ = filepath.Abs(*v) } } + for k, v := range insert.Drive { + if len(v) > 0 { + if (v)[0] == '~' { + home_dir, err := os.UserHomeDir() + if err != nil { + return + } + v = home_dir + (v)[1:] + } + v, _ = filepath.Abs(v) + insert.Drive[k] = v + } + } } func i_insert_default_users(insert *HostNode) { @@ -124,6 +137,9 @@ func i_insert_default_users(insert *HostNode) { func i_insert_host(data *HardData, insert *HostNode) { i_insert_abs_files(insert) i_insert_default_users(insert) + if len(insert.Drive) == 0 { + insert.Drive = nil + } filename := i_insert_format_filename(insert.Name, data.data_dir + insert.parent.path()) insert.filename = filename @@ -207,7 +223,7 @@ func i_insert_check_ok(data *HardData, in *HostNode) { v = home_dir + v[1:] } if stat, err := os.Stat(v); - err != nil { + err != nil { data.insert_err = append(data.insert_err, errors.New(v + ": file does not exist")) } else if stat.IsDir() == true { @@ -216,6 +232,23 @@ func i_insert_check_ok(data *HardData, in *HostNode) { } } } + for _, v := range in.Drive { + if v[0] == '~' { + home_dir, err := os.UserHomeDir() + if err != nil { + return + } + v = home_dir + v[1:] + } + if stat, err := os.Stat(v); + err != nil { + data.insert_err = append(data.insert_err, errors.New(v + + ": path does not exist")) + } else if stat.IsDir() == false { + data.insert_err = append(data.insert_err, errors.New(v + + ": path is not a directory")) + } + } } func i_draw_tick_box(ui HardUI, line int, dim Quad, label string, content bool, diff --git a/src/i_ui.go b/src/i_ui.go index d4278e2..d6b8f46 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -450,6 +450,15 @@ func i_prompt_insert(ui HardUI, curr *ItemsNode) { ui.s.ShowCursor(len(prompt) + 1 + len(path) + len(ui.buff), ui.dim[H] - 1) } +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) + line := ui.dim[H] - 2 - 1 + i_draw_text(ui.s, left, line, right, line, ui.style[DEF_STYLE], text) +} + 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)" @@ -746,6 +755,12 @@ func i_ui(data_dir string) { i_prompt_dir(data.ui, "Local directory: ", home_dir) } } + if len(data.insert.Drive) > 0 && + data.ui.insert_sel >= INS_RDP_DRIVE && + data.ui.insert_sel < INS_RDP_DRIVE + + len(data.insert.Drive) { + i_draw_remove_share(data.ui) + } } else if data.insert_err != nil { i_draw_insert_err_msg(data.ui, data.insert_err) } |