aboutsummaryrefslogtreecommitdiffstats
path: root/src/e_keys.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/e_keys.go')
-rw-r--r--src/e_keys.go205
1 files changed, 106 insertions, 99 deletions
diff --git a/src/e_keys.go b/src/e_keys.go
index a4e52cb..3a60a98 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 12:16:05 2024
+ * Wed Apr 24 16:51:45 2024
* Joe
*
* events in the keys
@@ -52,6 +52,7 @@
package main
import (
+ "fmt"
"os"
"strconv"
"strings"
@@ -59,10 +60,10 @@ import (
"github.com/gdamore/tcell/v2"
)
-func e_normal_events(data *HardData, event tcell.EventKey) bool {
+func e_normal_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if event.Key() == tcell.KeyCtrlC ||
event.Rune() == 'q' {
- data.ui.s.Fini()
+ ui.s.Fini()
os.Exit(0)
} else if event.Rune() == 'j' ||
event.Key() == tcell.KeyDown {
@@ -72,10 +73,10 @@ func e_normal_events(data *HardData, event tcell.EventKey) bool {
data.litems.inc(-1)
} else if event.Key() == tcell.KeyCtrlD ||
event.Key() == tcell.KeyPgDn {
- data.litems.inc(+(data.ui.dim[H] / 3))
+ data.litems.inc(+(ui.dim[H] / 3))
} else if event.Key() == tcell.KeyCtrlU ||
event.Key() == tcell.KeyPgUp {
- data.litems.inc(-(data.ui.dim[H] / 3))
+ data.litems.inc(-(ui.dim[H] / 3))
} else if event.Key() == tcell.KeyCtrlF {
// TODO: maybe keymap these
} else if event.Key() == tcell.KeyCtrlB {
@@ -100,7 +101,7 @@ func e_normal_events(data *HardData, event tcell.EventKey) bool {
} else if event.Rune() == 'D' &&
data.litems.head != nil &&
data.litems.curr != nil {
- data.ui.mode = DELETE_MODE
+ ui.mode = DELETE_MODE
} else if event.Rune() == 'H' {
for curr := data.litems.last; curr != nil; curr = curr.prev {
if curr.is_dir() == true && data.folds[curr.Dirs] == nil {
@@ -151,7 +152,7 @@ func e_normal_events(data *HardData, event tcell.EventKey) bool {
if data.litems.curr == nil {
return true
} else if data.litems.curr.is_dir() == false {
- c_exec(data.litems.curr.Host, data.opts, &data.ui)
+ c_exec(data.litems.curr.Host, data.opts, ui)
} else if data.litems.curr.Dirs != nil &&
data.folds[data.litems.curr.Dirs] == nil {
e_fold_dir(data, data.litems.curr)
@@ -171,58 +172,66 @@ func e_normal_events(data *HardData, event tcell.EventKey) bool {
}
} else if event.Rune() == 'a' ||
event.Rune() == 'i' {
- data.ui.mode = INSERT_MODE
- data.ui.insert_sel = 0
- data.ui.insert_sel_ok = false
+ 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' ||
event.Key() == tcell.KeyF7 {
- data.ui.mode = MKDIR_MODE
- } else if event.Rune() == 'y' {
- if data.litems.curr == nil ||
- data.litems.curr.is_dir() == true {
- return true
- }
+ ui.mode = MKDIR_MODE
+ } else if event.Rune() == 'y' &&
+ (data.litems.curr == nil ||
+ data.litems.curr.is_dir() == true) == false {
data.yank = data.litems.curr
+ ui.msg_buff = "yanked " + data.yank.Host.Name +
+ " (" + data.yank.Host.parent.path() + data.yank.Host.filename + ")"
+ } else if event.Rune() == 'p' && data.yank != nil {
+ // TODO: here
+ new_item := e_paste_prepare_item(data.yank)
+ e_paste_item(data.litems, new_item)
+ data.yank = nil
+ ui.msg_buff = "pasted " + new_item.Host.Name
}
- // TODO: here paste
return false
}
-func e_delete_events(data *HardData, event tcell.EventKey) bool {
+func e_delete_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC ||
event.Rune() == 'n' {
- data.ui.mode = NORMAL_MODE
+ ui.mode = NORMAL_MODE
} else if event.Key() == tcell.KeyEnter ||
event.Rune() == 'y' {
+ if data.yank == data.litems.curr {
+ data.yank = nil
+ }
if err := e_delete_host(data); err == nil {
- data.ui.mode = NORMAL_MODE
+ ui.mode = NORMAL_MODE
return true
}
}
return false
}
-func e_load_events(data *HardData, event tcell.EventKey) bool {
+func e_load_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
return true
}
-func e_error_events(data *HardData, event tcell.EventKey) bool {
+func e_error_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if event.Rune() != 0 ||
event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyEnter {
- data.ui.mode = NORMAL_MODE
+ ui.mode = NORMAL_MODE
data.load_err = nil
}
return false
}
-func e_welcome_events(data *HardData, event tcell.EventKey) bool {
+func e_welcome_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
- data.ui.s.Fini()
+ ui.s.Fini()
os.Exit(0)
}
if len(data.opts.GPG) == 0 {
@@ -230,11 +239,11 @@ func e_welcome_events(data *HardData, event tcell.EventKey) bool {
return true
} else {
data.opts.GPG = data.keys[event.Rune() - 48 - 1][0]
- data.ui.s.HideCursor()
+ ui.s.HideCursor()
}
} else {
if event.Rune() == 'y' {
- data.ui.mode = NORMAL_MODE
+ ui.mode = NORMAL_MODE
c_write_options(data.opts.file, data.opts, &data.load_err)
} else if event.Rune() == 'n' {
data.opts.GPG = ""
@@ -243,41 +252,39 @@ func e_welcome_events(data *HardData, event tcell.EventKey) bool {
return false
}
-func e_mkdir_events(data *HardData, event tcell.EventKey) bool {
+func e_mkdir_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
- data.ui.s.HideCursor()
- data.ui.mode = NORMAL_MODE
- data.ui.buff = ""
+ ui.s.HideCursor()
+ ui.mode = NORMAL_MODE
+ ui.buff = ""
data.insert = nil
} else if event.Key() == tcell.KeyEnter {
- e_mkdir(data, &data.ui)
- data.ui.s.HideCursor()
- data.ui.mode = NORMAL_MODE
- data.ui.buff = ""
+ e_mkdir(data, ui)
+ ui.s.HideCursor()
+ ui.mode = NORMAL_MODE
+ ui.buff = ""
} else {
- e_readline(event, &data.ui.buff)
+ e_readline(event, &ui.buff)
}
return false
}
-func e_insert_events(data *HardData, event tcell.EventKey) bool {
- ui := &data.ui
-
+func e_insert_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
if data.insert == nil {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
ui.s.HideCursor()
- data.ui.mode = NORMAL_MODE
- data.ui.insert_sel = 0
+ ui.mode = NORMAL_MODE
+ ui.insert_sel = 0
data.insert = nil
ui.buff = ""
} else if event.Key() == tcell.KeyEnter {
if ui.buff == "" {
ui.s.HideCursor()
- data.ui.mode = NORMAL_MODE
- data.ui.insert_sel = 0
- data.ui.insert_sel_ok = false
+ ui.mode = NORMAL_MODE
+ ui.insert_sel = 0
+ ui.insert_sel_ok = false
data.insert = nil
ui.buff = ""
return true
@@ -293,7 +300,7 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
data.insert.parent = data.ldirs.head
}
} else {
- e_readline(event, &data.ui.buff)
+ e_readline(event, &ui.buff)
}
} else if data.insert != nil {
if data.insert_err != nil {
@@ -302,71 +309,71 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
event.Key() == tcell.KeyEnter {
data.insert_err = nil
}
- } else if data.ui.insert_sel_ok == false {
+ } else if ui.insert_sel_ok == false {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC ||
event.Rune() == 'q' {
ui.s.HideCursor()
- data.ui.mode = NORMAL_MODE
- data.ui.insert_sel = 0
+ ui.mode = NORMAL_MODE
+ ui.insert_sel = 0
data.insert = nil
ui.buff = ""
} else if event.Rune() == 'j' ||
event.Key() == tcell.KeyDown ||
event.Key() == tcell.KeyTab {
if data.insert.Protocol == PROTOCOL_RDP &&
- data.ui.insert_sel == INS_PROTOCOL {
- data.ui.insert_sel = INS_RDP_HOST
+ ui.insert_sel == INS_PROTOCOL {
+ ui.insert_sel = INS_RDP_HOST
} else if data.insert.Protocol == PROTOCOL_CMD &&
- data.ui.insert_sel == INS_PROTOCOL {
- data.ui.insert_sel = INS_CMD_CMD
+ ui.insert_sel == INS_PROTOCOL {
+ ui.insert_sel = INS_CMD_CMD
} else if data.insert.Protocol == PROTOCOL_OS &&
- data.ui.insert_sel == INS_PROTOCOL {
- data.ui.insert_sel = INS_OS_HOST
+ ui.insert_sel == INS_PROTOCOL {
+ ui.insert_sel = INS_OS_HOST
} else if data.insert.Protocol == PROTOCOL_SSH &&
- data.ui.insert_sel == INS_SSH_JUMP_HOST &&
+ ui.insert_sel == INS_SSH_JUMP_HOST &&
len(data.insert.Jump.Host) == 0 {
- data.ui.insert_sel = INS_SSH_NOTE
- } else if data.ui.insert_sel < data.ui.insert_sel_max {
- data.ui.insert_sel += 1
+ ui.insert_sel = INS_SSH_NOTE
+ } else if ui.insert_sel < ui.insert_sel_max {
+ ui.insert_sel += 1
}
} else if event.Rune() == 'k' ||
event.Key() == tcell.KeyUp {
if data.insert.Protocol == PROTOCOL_RDP &&
- data.ui.insert_sel == INS_RDP_HOST {
- data.ui.insert_sel = INS_PROTOCOL
+ ui.insert_sel == INS_RDP_HOST {
+ ui.insert_sel = INS_PROTOCOL
} else if data.insert.Protocol == PROTOCOL_CMD &&
- data.ui.insert_sel == INS_CMD_CMD {
- data.ui.insert_sel = INS_PROTOCOL
+ ui.insert_sel == INS_CMD_CMD {
+ ui.insert_sel = INS_PROTOCOL
} else if data.insert.Protocol == PROTOCOL_OS &&
- data.ui.insert_sel == INS_OS_HOST {
- data.ui.insert_sel = INS_PROTOCOL
+ ui.insert_sel == INS_OS_HOST {
+ ui.insert_sel = INS_PROTOCOL
} else if data.insert.Protocol == PROTOCOL_SSH &&
- data.ui.insert_sel == INS_SSH_NOTE &&
+ ui.insert_sel == INS_SSH_NOTE &&
len(data.insert.Jump.Host) == 0 {
- data.ui.insert_sel = INS_SSH_JUMP_HOST
- } else if data.ui.insert_sel > INS_PROTOCOL {
- data.ui.insert_sel -= 1
+ ui.insert_sel = INS_SSH_JUMP_HOST
+ } else if ui.insert_sel > INS_PROTOCOL {
+ ui.insert_sel -= 1
}
} else if event.Rune() == 'g' ||
event.Rune() == 'h' ||
event.Key() == tcell.KeyLeft {
- data.ui.insert_sel = INS_PROTOCOL
+ ui.insert_sel = INS_PROTOCOL
} else if event.Rune() == 'G' ||
event.Rune() == 'l' ||
event.Key() == tcell.KeyRight {
- data.ui.insert_sel = data.ui.insert_sel_max
+ ui.insert_sel = ui.insert_sel_max
} else if event.Rune() == 'i' ||
event.Rune() == 'a' ||
event.Rune() == ' ' ||
event.Key() == tcell.KeyEnter {
- data.ui.insert_sel_ok = true
- switch data.ui.insert_sel {
+ ui.insert_sel_ok = true
+ switch ui.insert_sel {
case INS_SSH_OK,
INS_RDP_OK + len(data.insert.Drive),
INS_CMD_OK,
INS_OS_OK:
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
i_insert_check_ok(data, data.insert)
if data.insert_err != nil {
return true
@@ -403,7 +410,7 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
case INS_RDP_FILE: ui.buff = data.insert.RDPFile
case INS_RDP_SCREENSIZE: return true
case INS_RDP_DYNAMIC:
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
if data.insert.Dynamic == true {
data.insert.Dynamic = false
} else {
@@ -415,7 +422,7 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
case INS_CMD_CMD: ui.buff = data.insert.Host
case INS_CMD_SHELL: ui.buff = data.insert.Shell[0]
case INS_CMD_SILENT:
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
if data.insert.Silent == true {
data.insert.Silent = false
} else {
@@ -450,33 +457,33 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
} else {
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.buff = ""
ui.drives_buff = ""
ui.s.HideCursor()
}
if len(data.insert.Drive) > 0 &&
- (data.ui.insert_sel >= INS_RDP_DRIVE &&
- data.ui.insert_sel < INS_RDP_DRIVE +
+ (ui.insert_sel >= INS_RDP_DRIVE &&
+ 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])
+ ui.insert_sel - INS_RDP_DRIVE])
if len(data.insert.Drive) == 0 {
data.insert.Drive = nil
}
e_set_drive_keys(data)
}
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
return true
}
- switch data.ui.insert_sel {
+ switch ui.insert_sel {
case INS_PROTOCOL:
if event.Rune() < '1' || event.Rune() > '4' {
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.buff = ""
ui.s.HideCursor()
return true
@@ -488,13 +495,13 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
data.insert.Name = name
data.insert.parent = parent
data.insert.Protocol = int8(event.Rune() - 48 - 1)
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.s.HideCursor()
e_set_protocol_defaults(data, data.insert)
}
case INS_RDP_SCREENSIZE:
if event.Rune() < '1' || event.Rune() > '7' {
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.buff = ""
ui.s.HideCursor()
return true
@@ -509,40 +516,40 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
data.insert.Width = uint16(tmp)
tmp, _ = strconv.Atoi(s[H])
data.insert.Height = uint16(tmp)
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.s.HideCursor()
}
case INS_RDP_QUALITY:
if event.Rune() < '1' || event.Rune() > '3' {
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.buff = ""
ui.s.HideCursor()
return true
} else {
data.insert.Quality = uint8(event.Rune() - 48 - 1)
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.s.HideCursor()
}
case INS_RDP_DRIVE + len(data.insert.Drive):
- if len(data.ui.drives_buff) == 0 {
+ if len(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.insert_sel_ok = false
+ ui.drives_buff = ""
ui.buff = ""
ui.s.HideCursor()
return true
}
- data.ui.drives_buff = ui.buff
+ ui.drives_buff = ui.buff
ui.buff = ""
} else {
- e_readline(event, &data.ui.buff)
+ e_readline(event, &ui.buff)
}
} else {
if event.Key() == tcell.KeyEnter {
if len(ui.buff) == 0 {
- data.ui.insert_sel_ok = false
- data.ui.drives_buff = ""
+ ui.insert_sel_ok = false
+ ui.drives_buff = ""
ui.buff = ""
ui.s.HideCursor()
return true
@@ -552,12 +559,12 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
}
data.insert.Drive[ui.drives_buff] = ui.buff
e_set_drive_keys(data)
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.drives_buff = ""
ui.buff = ""
ui.s.HideCursor()
} else {
- e_readline(event, &data.ui.buff)
+ e_readline(event, &ui.buff)
}
}
case INS_SSH_HOST,
@@ -595,7 +602,7 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
INS_OS_VOLAPI,
INS_OS_NOTE:
if event.Key() == tcell.KeyEnter {
- switch data.ui.insert_sel {
+ switch ui.insert_sel {
case INS_SSH_HOST,
INS_RDP_HOST,
INS_OS_HOST:
@@ -663,11 +670,11 @@ func e_insert_events(data *HardData, event tcell.EventKey) bool {
INS_OS_NOTE:
data.insert.Note = ui.buff
}
- data.ui.insert_sel_ok = false
+ ui.insert_sel_ok = false
ui.buff = ""
ui.s.HideCursor()
} else {
- e_readline(event, &data.ui.buff)
+ e_readline(event, &ui.buff)
}
}
}