aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ROADMAP.md1
-rw-r--r--go.mod10
-rw-r--r--go.sum16
-rw-r--r--src/c_defs.go2
-rw-r--r--src/e_events.go (renamed from src/i_events.go)219
-rw-r--r--src/e_keys.go209
-rw-r--r--src/i_host.go5
-rw-r--r--src/i_ui.go37
8 files changed, 288 insertions, 211 deletions
diff --git a/ROADMAP.md b/ROADMAP.md
index de79ef6..cd691e5 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -33,6 +33,7 @@
- [x] add
- [ ] clone
- [ ] edit
+- [ ] move
- [ ] rename
## v0.7
diff --git a/go.mod b/go.mod
index e106c87..ec0c32a 100644
--- a/go.mod
+++ b/go.mod
@@ -1,12 +1,12 @@
module hf
-go 1.22rc2
+go 1.22.1
require (
- github.com/gdamore/tcell/v2 v2.7.0
- golang.org/x/term v0.17.0
+ github.com/gdamore/tcell/v2 v2.7.4
+ golang.org/x/term v0.19.0
gopkg.in/yaml.v3 v3.0.1
- k8s.io/apimachinery v0.29.3
+ k8s.io/apimachinery v0.30.0
)
require (
@@ -15,6 +15,6 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
- golang.org/x/sys v0.17.0 // indirect
+ golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
diff --git a/go.sum b/go.sum
index 292bd53..9667612 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
-github.com/gdamore/tcell/v2 v2.7.0 h1:I5LiGTQuwrysAt1KS9wg1yFfOI3arI3ucFrxtd/xqaA=
-github.com/gdamore/tcell/v2 v2.7.0/go.mod h1:hl/KtAANGBecfIPxk+FzKvThTqI84oplgbPEmVX60b8=
+github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
+github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
@@ -29,15 +29,15 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
+golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
-golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
-golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
+golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
+golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
@@ -53,5 +53,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU=
-k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU=
+k8s.io/apimachinery v0.30.0 h1:qxVPsyDM5XS96NIh9Oj6LavoVFYff/Pon9cZeDIkHHA=
+k8s.io/apimachinery v0.30.0/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
diff --git a/src/c_defs.go b/src/c_defs.go
index 48afed0..579df64 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -98,6 +98,8 @@ const (
ERR_STYLE
TITLE_STYLE
BOT_STYLE
+ YANK_STYLE
+ MAX_STYLE = YANK_STYLE
)
const (
diff --git a/src/i_events.go b/src/e_events.go
index 7aad44a..742aa41 100644
--- a/src/i_events.go
+++ b/src/e_events.go
@@ -42,7 +42,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * hardflip: src/i_events.go
+ * hardflip: src/e_events.go
* Thu Apr 11 16:00:44 2024
* Joe
*
@@ -60,7 +60,7 @@ import (
"golang.org/x/term"
)
-func i_list_follow_cursor(litems *ItemsList, ui *HardUI) {
+func e_list_follow_cursor(litems *ItemsList, ui *HardUI) {
if litems.draw == nil || litems.curr == nil {
return
}
@@ -80,12 +80,12 @@ func i_list_follow_cursor(litems *ItemsList, ui *HardUI) {
}
}
-func i_set_unfold(data *HardData, item *ItemsNode) {
+func e_set_unfold(data *HardData, item *ItemsNode) {
delete(data.folds, item.Dirs)
data.litems.reset_id()
}
-func i_unfold_dir(data *HardData, item *ItemsNode) {
+func e_unfold_dir(data *HardData, item *ItemsNode) {
if item == nil || item.Dirs == nil {
return
}
@@ -96,12 +96,12 @@ func i_unfold_dir(data *HardData, item *ItemsNode) {
start, end := fold.head, fold.last
// last empty dir
if start == nil && end == nil {
- i_set_unfold(data, item)
+ e_set_unfold(data, item)
return
}
// single empty dir
if start == item && end == end { // HACK: i forgot why end == end
- i_set_unfold(data, item)
+ e_set_unfold(data, item)
return
}
if data.litems.last == item {
@@ -114,10 +114,10 @@ func i_unfold_dir(data *HardData, item *ItemsNode) {
item.next.prev = end
}
item.next = start
- i_set_unfold(data, item)
+ e_set_unfold(data, item)
}
-func i_set_fold(data *HardData, curr, start, end *ItemsNode) {
+func e_set_fold(data *HardData, curr, start, end *ItemsNode) {
folds := data.folds
tmp := ItemsList{
start,
@@ -130,7 +130,7 @@ func i_set_fold(data *HardData, curr, start, end *ItemsNode) {
data.litems.reset_id()
}
-func i_fold_dir(data *HardData, item *ItemsNode) {
+func e_fold_dir(data *HardData, item *ItemsNode) {
if item == nil || item.Dirs == nil {
return
}
@@ -138,12 +138,12 @@ func i_fold_dir(data *HardData, item *ItemsNode) {
start = item.next
// last dir + empty
if start == nil {
- i_set_fold(data, item, nil, nil)
+ e_set_fold(data, item, nil, nil)
return
}
// empty dir
if start.Dirs != nil && start.Dirs.Depth <= item.Dirs.Depth {
- i_set_fold(data, item, item, item)
+ e_set_fold(data, item, item, item)
return
}
// non-empty dir
@@ -156,7 +156,7 @@ func i_fold_dir(data *HardData, item *ItemsNode) {
end = data.litems.last
end.next = nil
data.litems.last = item
- i_set_fold(data, item, start, end)
+ e_set_fold(data, item, start, end)
return
}
// this is not the end
@@ -164,10 +164,10 @@ func i_fold_dir(data *HardData, item *ItemsNode) {
end.next = nil
item.next = next_dir
next_dir.prev = item
- i_set_fold(data, item, start, end)
+ e_set_fold(data, item, start, end)
}
-func i_reload_data(data *HardData) {
+func e_reload_data(data *HardData) {
tmp_name := ""
tmp_parent_path := ""
if data.litems.curr != nil {
@@ -217,7 +217,7 @@ func i_reload_data(data *HardData) {
data.litems.curr = data.litems.head
}
-func i_delete_dir(data *HardData) error {
+func e_delete_dir(data *HardData) error {
if data.litems.curr == nil || data.litems.curr.Dirs == nil {
return nil
}
@@ -228,7 +228,7 @@ func i_delete_dir(data *HardData) error {
return err
}
if data.folds[curr.Dirs] == nil {
- i_fold_dir(data, curr)
+ e_fold_dir(data, curr)
}
delete(data.folds, curr.Dirs)
if curr == data.litems.head {
@@ -253,12 +253,12 @@ func i_delete_dir(data *HardData) error {
return nil
}
-func i_delete_host(data *HardData) error {
+func e_delete_host(data *HardData) error {
if data.litems.curr == nil {
return nil
}
if data.litems.curr.is_dir() == true {
- return i_delete_dir(data)
+ return e_delete_dir(data)
}
host := data.litems.curr.Host
if host == nil {
@@ -280,7 +280,7 @@ func i_delete_host(data *HardData) error {
return nil
}
-func i_readline(event *tcell.EventKey, buffer *string) {
+func e_readline(event *tcell.EventKey, buffer *string) {
if len(*buffer) > 0 &&
(event.Key() == tcell.KeyBackspace ||
event.Key() == tcell.KeyBackspace2) {
@@ -292,7 +292,7 @@ func i_readline(event *tcell.EventKey, buffer *string) {
}
}
-func i_mkdir(data *HardData, ui *HardUI) {
+func e_mkdir(data *HardData, ui *HardUI) {
if len(ui.buff) == 0 {
return
}
@@ -307,7 +307,7 @@ func i_mkdir(data *HardData, ui *HardUI) {
err, ui)
return
}
- i_reload_data(data)
+ e_reload_data(data)
for curr := data.litems.head; curr != nil; curr = curr.next {
if curr.is_dir() == true &&
curr.Dirs.Name == ui.buff &&
@@ -318,7 +318,7 @@ func i_mkdir(data *HardData, ui *HardUI) {
}
}
-func i_set_drive_keys(data *HardData) {
+func e_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)
@@ -326,7 +326,7 @@ func i_set_drive_keys(data *HardData) {
data.ui.insert_sel_max = INS_RDP_OK + len(data.insert.Drive)
}
-func i_set_protocol_defaults(data *HardData, in *HostNode) {
+func e_set_protocol_defaults(data *HardData, in *HostNode) {
switch in.Protocol {
case PROTOCOL_SSH:
in.Port = 22
@@ -356,164 +356,25 @@ func i_set_protocol_defaults(data *HardData, in *HostNode) {
}
// screen events such as keypresses
-func i_events(data *HardData) {
+func e_events(data *HardData) {
ui := &data.ui
event := ui.s.PollEvent()
switch event := event.(type) {
case *tcell.EventResize:
ui.dim[W], ui.dim[H], _ = term.GetSize(0)
- i_list_follow_cursor(data.litems, ui)
+ e_list_follow_cursor(data.litems, ui)
ui.s.Sync()
case *tcell.EventKey:
switch ui.mode {
case NORMAL_MODE:
- if event.Key() == tcell.KeyCtrlC ||
- event.Rune() == 'q' {
- ui.s.Fini()
- os.Exit(0)
- } else if event.Rune() == 'j' ||
- event.Key() == tcell.KeyDown {
- data.litems.inc(+1)
- } else if event.Rune() == 'k' ||
- event.Key() == tcell.KeyUp {
- data.litems.inc(-1)
- } else if event.Key() == tcell.KeyCtrlD ||
- event.Key() == tcell.KeyPgDn {
- data.litems.inc(+(ui.dim[H] / 3))
- } else if event.Key() == tcell.KeyCtrlU ||
- event.Key() == tcell.KeyPgUp {
- data.litems.inc(-(ui.dim[H] / 3))
- } else if event.Key() == tcell.KeyCtrlF {
- // TODO: maybe keymap these
- } else if event.Key() == tcell.KeyCtrlB {
- // TODO: maybe keymap these
- } else if event.Rune() == '}' ||
- event.Rune() == ']' {
- if next := data.litems.curr.next_dir(); next != nil {
- data.litems.curr = next
- }
- } else if event.Rune() == '{' ||
- event.Rune() == '[' {
- if prev := data.litems.curr.prev_dir(); prev != nil {
- data.litems.curr = prev
- }
- } else if event.Rune() == 'g' ||
- event.Key() == tcell.KeyHome {
- data.litems.curr = data.litems.head
- data.litems.draw = data.litems.head
- } else if event.Rune() == 'G' ||
- event.Key() == tcell.KeyEnd {
- data.litems.curr = data.litems.last
- } else if event.Rune() == 'D' &&
- data.litems.head != nil &&
- data.litems.curr != nil {
- 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 {
- i_fold_dir(data, curr)
- }
- }
- data.litems.curr = data.litems.head
- data.litems.draw = data.litems.curr
- } else if event.Rune() == 'h' ||
- event.Key() == tcell.KeyLeft {
- for curr := data.litems.curr;
- curr != nil;
- curr = curr.prev {
- if curr.is_dir() == true {
- if data.folds[curr.Dirs] == nil {
- i_fold_dir(data, curr)
- data.litems.curr = curr
- data.litems.draw = data.litems.curr
- break
- } else {
- if data.folds[curr.Dirs.Parent] == nil {
- parent := curr.Dirs.Parent
- for curr_new := curr;
- curr_new != nil;
- curr_new = curr_new.prev {
- if curr_new.is_dir() == true {
- if curr_new.Dirs == parent {
- i_fold_dir(data, curr_new)
- data.litems.curr = curr_new
- data.litems.draw = data.litems.curr
- break
- } else {
- if data.folds[curr_new.Dirs] ==
- nil {
- i_fold_dir(data, curr_new)
- }
- }
- }
- }
- }
- break
- }
- }
- }
- } else if event.Rune() == 'l' ||
- event.Key() == tcell.KeyRight ||
- event.Key() == tcell.KeyEnter {
- if data.litems.curr == nil {
- break
- } else if data.litems.curr.is_dir() == false {
- c_exec(data.litems.curr.Host, data.opts, ui)
- } else if data.litems.curr.Dirs != nil &&
- data.folds[data.litems.curr.Dirs] == nil {
- i_fold_dir(data, data.litems.curr)
- } else {
- i_unfold_dir(data, data.litems.curr)
- }
- } else if event.Rune() == ' ' {
- if data.litems.curr == nil ||
- data.litems.curr.is_dir() == false {
- break
- }
- if data.litems.curr.Dirs != nil &&
- data.folds[data.litems.curr.Dirs] == nil {
- i_fold_dir(data, data.litems.curr)
- } else {
- i_unfold_dir(data, data.litems.curr)
- }
- } else if event.Rune() == 'a' ||
- event.Rune() == 'i' {
- data.ui.mode = INSERT_MODE
- data.ui.insert_sel = 0
- data.ui.insert_sel_ok = false
- } else if event.Key() == tcell.KeyCtrlR {
- event = nil
- i_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 {
- break
- }
- data.yank = data.litems.curr
- }
- i_list_follow_cursor(data.litems, ui)
+ e_normal_events(data, *event)
+ e_list_follow_cursor(data.litems, ui)
case DELETE_MODE:
- if event.Key() == tcell.KeyEscape ||
- event.Key() == tcell.KeyCtrlC ||
- event.Rune() == 'n' {
- ui.mode = NORMAL_MODE
- } else if event.Key() == tcell.KeyEnter ||
- event.Rune() == 'y' {
- if err := i_delete_host(data); err == nil {
- ui.mode = NORMAL_MODE
- }
- }
+ e_delete_events(data, *event)
case ERROR_MODE:
- if event.Rune() != 0 ||
- event.Key() == tcell.KeyEscape ||
- event.Key() == tcell.KeyEnter {
- ui.mode = NORMAL_MODE
- data.load_err = nil
- }
+ e_error_events(data, *event)
case WELCOME_MODE:
+ // TODO: here
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
ui.s.Fini()
@@ -555,7 +416,7 @@ func i_events(data *HardData) {
}
ui.s.HideCursor()
data.insert = &HostNode{}
- i_set_protocol_defaults(data, data.insert)
+ e_set_protocol_defaults(data, data.insert)
data.insert.Name = ui.buff
ui.buff = ""
if data.litems.curr != nil {
@@ -564,7 +425,7 @@ func i_events(data *HardData) {
data.insert.parent = data.ldirs.head
}
} else {
- i_readline(event, &data.ui.buff)
+ e_readline(event, &data.ui.buff)
}
} else if data.insert != nil {
if data.insert_err != nil {
@@ -739,7 +600,7 @@ func i_events(data *HardData) {
if len(data.insert.Drive) == 0 {
data.insert.Drive = nil
}
- i_set_drive_keys(data)
+ e_set_drive_keys(data)
}
data.ui.insert_sel_ok = false
break
@@ -761,7 +622,7 @@ func i_events(data *HardData) {
data.insert.Protocol = int8(event.Rune() - 48 - 1)
data.ui.insert_sel_ok = false
ui.s.HideCursor()
- i_set_protocol_defaults(data, data.insert)
+ e_set_protocol_defaults(data, data.insert)
}
case INS_RDP_SCREENSIZE:
if event.Rune() < '1' || event.Rune() > '7' {
@@ -807,7 +668,7 @@ func i_events(data *HardData) {
data.ui.drives_buff = ui.buff
ui.buff = ""
} else {
- i_readline(event, &data.ui.buff)
+ e_readline(event, &data.ui.buff)
}
} else {
if event.Key() == tcell.KeyEnter {
@@ -822,13 +683,13 @@ func i_events(data *HardData) {
data.insert.Drive = make(map[string]string)
}
data.insert.Drive[ui.drives_buff] = ui.buff
- i_set_drive_keys(data)
+ e_set_drive_keys(data)
data.ui.insert_sel_ok = false
ui.drives_buff = ""
ui.buff = ""
ui.s.HideCursor()
} else {
- i_readline(event, &data.ui.buff)
+ e_readline(event, &data.ui.buff)
}
}
case INS_SSH_HOST,
@@ -938,7 +799,7 @@ func i_events(data *HardData) {
ui.buff = ""
ui.s.HideCursor()
} else {
- i_readline(event, &data.ui.buff)
+ e_readline(event, &data.ui.buff)
}
}
}
@@ -951,12 +812,12 @@ func i_events(data *HardData) {
ui.buff = ""
data.insert = nil
} else if event.Key() == tcell.KeyEnter {
- i_mkdir(data, ui)
+ e_mkdir(data, ui)
ui.s.HideCursor()
ui.mode = NORMAL_MODE
ui.buff = ""
} else {
- i_readline(event, &data.ui.buff)
+ e_readline(event, &data.ui.buff)
}
}
}
diff --git a/src/e_keys.go b/src/e_keys.go
new file mode 100644
index 0000000..831a80f
--- /dev/null
+++ b/src/e_keys.go
@@ -0,0 +1,209 @@
+/*
+ * ========================
+ * ===== ===============
+ * ====== ================
+ * ====== ================
+ * ====== ==== ==== ==
+ * ====== === == = =
+ * ====== === = == =
+ * = === === = == ====
+ * = === === = == = =
+ * == ===== ==== ==
+ * ========================
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 2023-2024, Joe
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the organization nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * hardflip: src/e_keys.go
+ * Mon Apr 22 17:04:37 2024
+ * Joe
+ *
+ * events in the keys
+ */
+
+package main
+
+import (
+ "os"
+
+ "github.com/gdamore/tcell/v2"
+)
+
+func e_normal_events(data *HardData, event tcell.EventKey) {
+ if event.Key() == tcell.KeyCtrlC ||
+ event.Rune() == 'q' {
+ data.ui.s.Fini()
+ os.Exit(0)
+ } else if event.Rune() == 'j' ||
+ event.Key() == tcell.KeyDown {
+ data.litems.inc(+1)
+ } else if event.Rune() == 'k' ||
+ event.Key() == tcell.KeyUp {
+ data.litems.inc(-1)
+ } else if event.Key() == tcell.KeyCtrlD ||
+ event.Key() == tcell.KeyPgDn {
+ data.litems.inc(+(data.ui.dim[H] / 3))
+ } else if event.Key() == tcell.KeyCtrlU ||
+ event.Key() == tcell.KeyPgUp {
+ data.litems.inc(-(data.ui.dim[H] / 3))
+ } else if event.Key() == tcell.KeyCtrlF {
+ // TODO: maybe keymap these
+ } else if event.Key() == tcell.KeyCtrlB {
+ // TODO: maybe keymap these
+ } else if event.Rune() == '}' ||
+ event.Rune() == ']' {
+ if next := data.litems.curr.next_dir(); next != nil {
+ data.litems.curr = next
+ }
+ } else if event.Rune() == '{' ||
+ event.Rune() == '[' {
+ if prev := data.litems.curr.prev_dir(); prev != nil {
+ data.litems.curr = prev
+ }
+ } else if event.Rune() == 'g' ||
+ event.Key() == tcell.KeyHome {
+ data.litems.curr = data.litems.head
+ data.litems.draw = data.litems.head
+ } else if event.Rune() == 'G' ||
+ event.Key() == tcell.KeyEnd {
+ data.litems.curr = data.litems.last
+ } else if event.Rune() == 'D' &&
+ data.litems.head != nil &&
+ data.litems.curr != nil {
+ data.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 {
+ e_fold_dir(data, curr)
+ }
+ }
+ data.litems.curr = data.litems.head
+ data.litems.draw = data.litems.curr
+ } else if event.Rune() == 'h' ||
+ event.Key() == tcell.KeyLeft {
+ for curr := data.litems.curr;
+ curr != nil;
+ curr = curr.prev {
+ if curr.is_dir() == true {
+ if data.folds[curr.Dirs] == nil {
+ e_fold_dir(data, curr)
+ data.litems.curr = curr
+ data.litems.draw = data.litems.curr
+ return
+ } else {
+ if data.folds[curr.Dirs.Parent] == nil {
+ parent := curr.Dirs.Parent
+ for curr_new := curr;
+ curr_new != nil;
+ curr_new = curr_new.prev {
+ if curr_new.is_dir() == true {
+ if curr_new.Dirs == parent {
+ e_fold_dir(data, curr_new)
+ data.litems.curr = curr_new
+ data.litems.draw = data.litems.curr
+ return
+ } else {
+ if data.folds[curr_new.Dirs] ==
+ nil {
+ e_fold_dir(data, curr_new)
+ }
+ }
+ }
+ }
+ }
+ return
+ }
+ }
+ }
+ } else if event.Rune() == 'l' ||
+ event.Key() == tcell.KeyRight ||
+ event.Key() == tcell.KeyEnter {
+ if data.litems.curr == nil {
+ return
+ } else if data.litems.curr.is_dir() == false {
+ c_exec(data.litems.curr.Host, data.opts, &data.ui)
+ } else if data.litems.curr.Dirs != nil &&
+ data.folds[data.litems.curr.Dirs] == nil {
+ e_fold_dir(data, data.litems.curr)
+ } else {
+ e_unfold_dir(data, data.litems.curr)
+ }
+ } else if event.Rune() == ' ' {
+ if data.litems.curr == nil ||
+ data.litems.curr.is_dir() == false {
+ return
+ }
+ if data.litems.curr.Dirs != nil &&
+ data.folds[data.litems.curr.Dirs] == nil {
+ e_fold_dir(data, data.litems.curr)
+ } else {
+ e_unfold_dir(data, data.litems.curr)
+ }
+ } else if event.Rune() == 'a' ||
+ event.Rune() == 'i' {
+ data.ui.mode = INSERT_MODE
+ data.ui.insert_sel = 0
+ data.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
+ }
+ data.yank = data.litems.curr
+ }
+}
+
+func e_delete_events(data *HardData, event tcell.EventKey) {
+ if event.Key() == tcell.KeyEscape ||
+ event.Key() == tcell.KeyCtrlC ||
+ event.Rune() == 'n' {
+ data.ui.mode = NORMAL_MODE
+ } else if event.Key() == tcell.KeyEnter ||
+ event.Rune() == 'y' {
+ if err := e_delete_host(data); err == nil {
+ data.ui.mode = NORMAL_MODE
+ }
+ }
+}
+
+func e_error_events(data *HardData, event tcell.EventKey) {
+ if event.Rune() != 0 ||
+ event.Key() == tcell.KeyEscape ||
+ event.Key() == tcell.KeyEnter {
+ data.ui.mode = NORMAL_MODE
+ data.load_err = nil
+ }
+}
diff --git a/src/i_host.go b/src/i_host.go
index c30c444..2ad71d2 100644
--- a/src/i_host.go
+++ b/src/i_host.go
@@ -51,8 +51,6 @@
package main
-import "github.com/gdamore/tcell/v2"
-
func i_host_panel_dirs(ui HardUI, icons bool, dir_icon uint8,
dir *DirsNode, curr *DirsNode, line int) {
style := ui.style[DIR_STYLE]
@@ -83,8 +81,7 @@ func i_host_panel_host(ui HardUI, icons bool,
line int) {
style := ui.style[DEF_STYLE]
if yank != nil && host == yank.Host {
- style = style.Foreground(tcell.ColorPurple).Bold(true)
- // TODO: here
+ style = ui.style[YANK_STYLE]
}
if host == curr {
// style = style.Background(tcell.ColorBlack)
diff --git a/src/i_ui.go b/src/i_ui.go
index 25395d6..f327629 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -63,7 +63,7 @@ import (
type HardUI struct {
s tcell.Screen
mode uint8
- style [7]tcell.Style
+ style [MAX_STYLE + 1]tcell.Style
dim [2]int
err [2]string
buff string
@@ -622,19 +622,7 @@ func i_load_ui(data_dir string,
return ldirs, litems, *load_err
}
-func i_ui(data_dir string) {
- home_dir, _ := os.UserHomeDir()
- ui := HardUI{}
- opts := HardOpts{}
- var err error
-
- ui.s, err = tcell.NewScreen()
- if err != nil {
- c_die("view", err)
- }
- if err := ui.s.Init(); err != nil {
- c_die("view", err)
- }
+func i_init_styles(ui *HardUI) {
ui.style[DEF_STYLE] = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorReset)
@@ -656,6 +644,25 @@ func i_ui(data_dir string) {
ui.style[BOT_STYLE] = tcell.StyleDefault.
Background(tcell.ColorReset).
Foreground(tcell.ColorBlue).Dim(true)
+ ui.style[YANK_STYLE] = tcell.StyleDefault.
+ Background(tcell.ColorReset).
+ Foreground(tcell.ColorYellow).Dim(true).Bold(true)
+}
+
+func i_ui(data_dir string) {
+ home_dir, _ := os.UserHomeDir()
+ ui := HardUI{}
+ opts := HardOpts{}
+ var err error
+
+ ui.s, err = tcell.NewScreen()
+ if err != nil {
+ c_die("view", err)
+ }
+ if err := ui.s.Init(); err != nil {
+ c_die("view", err)
+ }
+ i_init_styles(&ui)
ui.s.SetStyle(ui.style[DEF_STYLE])
ui.dim[W], ui.dim[H], _ = term.GetSize(0)
var load_err []error
@@ -720,6 +727,6 @@ func i_ui(data_dir string) {
}
}
data.ui.s.Show()
- i_events(&data)
+ e_events(&data)
}
}