diff options
author | Joe <rbo@gmx.us> | 2024-04-25 20:20:20 +0200 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-04-25 20:20:20 +0200 |
commit | 72ee87d8c097449a315b476f0b359ae6c44c26cf (patch) | |
tree | 122153aa21ae063b9c3a1692ee95aab2f90ed42a | |
parent | goot test (diff) | |
download | hardflip-72ee87d8c097449a315b476f0b359ae6c44c26cf.tar.gz hardflip-72ee87d8c097449a315b476f0b359ae6c44c26cf.tar.bz2 hardflip-72ee87d8c097449a315b476f0b359ae6c44c26cf.tar.xz hardflip-72ee87d8c097449a315b476f0b359ae6c44c26cf.tar.zst hardflip-72ee87d8c097449a315b476f0b359ae6c44c26cf.zip |
wo edit was fast
-rw-r--r-- | ROADMAP.md | 2 | ||||
-rw-r--r-- | src/e_events.go | 41 | ||||
-rw-r--r-- | src/e_keys.go | 11 | ||||
-rw-r--r-- | src/i_insert.go | 20 |
4 files changed, 56 insertions, 18 deletions
@@ -33,7 +33,7 @@ - [x] add - [x] clone - [x] ssh jump for rdp - working but missing in add menu -- [ ] edit +- [x] edit - [ ] move - [ ] rename diff --git a/src/e_events.go b/src/e_events.go index 8f631a6..9a2b867 100644 --- a/src/e_events.go +++ b/src/e_events.go @@ -324,23 +324,33 @@ func e_set_drive_keys(data *HardData) { data.ui.insert_sel_max = INS_RDP_OK + len(data.insert.Drive) } +func e_set_protocol_max(data *HardData, in *HostNode) { + switch in.Protocol { + case PROTOCOL_SSH: + data.ui.insert_sel_max = INS_SSH_OK + case PROTOCOL_RDP: + data.ui.insert_sel_max = INS_RDP_OK + len(in.Drive) + case PROTOCOL_CMD: + data.ui.insert_sel_max = INS_CMD_OK + case PROTOCOL_OS: + data.ui.insert_sel_max = INS_OS_OK + } +} + func e_set_protocol_defaults(data *HardData, in *HostNode) { switch in.Protocol { case PROTOCOL_SSH: in.Port = 22 - data.ui.insert_sel_max = INS_SSH_OK case PROTOCOL_RDP: in.Port = 3389 in.Quality = 2 in.Width = 1600 in.Height = 1200 in.Dynamic = true - data.ui.insert_sel_max = INS_RDP_OK + len(in.Drive) in.drive_keys = nil case PROTOCOL_CMD: in.Silent = false in.Shell = []string{"/bin/sh", "-c"} - data.ui.insert_sel_max = INS_CMD_OK case PROTOCOL_OS: in.Stack.RegionName = "eu-west-0" in.Stack.IdentityAPI = "3" @@ -349,27 +359,32 @@ func e_set_protocol_defaults(data *HardData, in *HostNode) { in.Stack.VolumeAPI = "3.42" in.Stack.EndpointType = "publicURL" in.Stack.Interface = "public" - data.ui.insert_sel_max = INS_OS_OK } + e_set_protocol_max(data, in) } -func e_paste_prepare_item(yank *ItemsNode) HostNode { +func e_deep_copy_host(base *HostNode) HostNode { new_host := HostNode{} - new_host = *yank.Host - new_host.Name += " (copy)" - if yank.Host.Drive != nil { - new_host.Drive = make(map[string]string, len(yank.Host.Drive)) - for k, v := range yank.Host.Drive { + new_host = *base + if base.Drive != nil { + new_host.Drive = make(map[string]string, len(base.Drive)) + for k, v := range base.Drive { new_host.Drive[k] = v } } - if yank.Host.Shell != nil { - new_host.Shell = make([]string, len(yank.Host.Shell)) - copy(new_host.Shell, yank.Host.Shell) + if base.Shell != nil { + new_host.Shell = make([]string, len(base.Shell)) + copy(new_host.Shell, base.Shell) } return new_host } +func e_paste_prepare_item(yank *ItemsNode) HostNode { + new_host := e_deep_copy_host(yank.Host) + new_host.Name += " (copy)" + return new_host +} + // func e_paste_item(litems *ItemsList, item ItemsNode) { // curr := litems.curr // } diff --git a/src/e_keys.go b/src/e_keys.go index ee6c66e..990e7a2 100644 --- a/src/e_keys.go +++ b/src/e_keys.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/e_keys.go - * Wed Apr 24 18:07:00 2024 + * Thu Apr 25 11:42:12 2024 * Joe * * events in the keys @@ -174,6 +174,15 @@ func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool { ui.mode = INSERT_MODE ui.insert_sel = 0 ui.insert_sel_ok = false + } else if event.Rune() == 'e' && + data.litems.curr != nil && + data.litems.curr.is_dir() == false { + tmp := e_deep_copy_host(data.litems.curr.Host) + data.insert = &tmp + e_set_protocol_max(data, data.insert) + ui.mode = INSERT_MODE + ui.insert_sel = 0 + ui.insert_sel_ok = false } else if event.Key() == tcell.KeyCtrlR { e_reload_data(data) } else if event.Rune() == 'm' || diff --git a/src/i_insert.go b/src/i_insert.go index ce08ebc..0bb55a8 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -138,9 +138,15 @@ func i_insert_host(data *HardData, insert *HostNode) { if len(insert.Drive) == 0 { insert.Drive = nil } - filename := i_insert_format_filename(insert.Name, - data.data_dir + insert.parent.path()) - insert.filename = filename + filename := insert.filename + replace := false + if len(filename) == 0 || data.yank != nil { + filename = i_insert_format_filename(insert.Name, + data.data_dir + insert.parent.path()) + insert.filename = filename + } else { + replace = true + } fmt, err := yaml.Marshal(insert) if err != nil { c_error_mode("yaml", err, &data.ui) @@ -154,6 +160,14 @@ func i_insert_host(data *HardData, insert *HostNode) { data.insert = nil return } + if replace == true && data.litems.curr != nil { + tmp := e_deep_copy_host(data.insert) + data.litems.curr.Host = &tmp + data.litems.reset_id() + data.ui.mode = NORMAL_MODE + data.insert = nil + return + } // HACK: not sure if this is necessary // if data.litems.curr.is_dir() == true { // data.litems.curr.Dirs.lhost.add_back(insert) |