aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/i_events.go27
-rw-r--r--src/i_insert.go50
-rw-r--r--src/i_ui.go33
3 files changed, 64 insertions, 46 deletions
diff --git a/src/i_events.go b/src/i_events.go
index 6582ac6..39db96a 100644
--- a/src/i_events.go
+++ b/src/i_events.go
@@ -570,10 +570,12 @@ func i_events(data *HardData) {
} else if event.Key() == tcell.KeyEnter {
data.ui.insert_sel_ok = true
switch data.ui.insert_sel {
- case 1:
- ui.buff = data.insert.Host
- case 2:
- ui.buff = strconv.Itoa(int(data.insert.Port))
+ case 1: ui.buff = data.insert.Host
+ case 2: ui.buff = strconv.Itoa(int(data.insert.Port))
+ case 3: ui.buff = data.insert.User
+ case 4: break
+ case 5: ui.buff = data.insert.Priv
+ case 6: ui.buff = data.insert.Jump.Host
}
}
} else {
@@ -604,21 +606,18 @@ func i_events(data *HardData) {
}
case 1, 2, 3, 4, 5, 6:
if event.Key() == tcell.KeyEnter {
- if data.ui.insert_sel == 1 {
- data.insert.Host = ui.buff
- } else if data.ui.insert_sel == 2 {
+ switch data.ui.insert_sel {
+ case 1: data.insert.Host = ui.buff
+ case 2:
tmp, _ := strconv.Atoi(ui.buff)
data.insert.Port = uint16(tmp)
- } else if data.ui.insert_sel == 3 {
- data.insert.User = ui.buff
- } else if data.ui.insert_sel == 4 {
+ case 3: data.insert.User = ui.buff
+ case 4:
pass, _ := c_encrypt_str(ui.buff,
data.opts.GPG)
data.insert.Pass = pass
- } else if data.ui.insert_sel == 5 {
- data.insert.Priv = ui.buff
- } else if data.ui.insert_sel == 6 {
- data.insert.Jump.Host = ui.buff
+ case 5: data.insert.Priv = ui.buff
+ case 6: data.insert.Jump.Host = ui.buff
}
data.ui.insert_sel_ok = false
ui.buff = ""
diff --git a/src/i_insert.go b/src/i_insert.go
index e2f677d..7d5a6ed 100644
--- a/src/i_insert.go
+++ b/src/i_insert.go
@@ -59,7 +59,7 @@ import (
)
func i_draw_text_box(ui HardUI, line int, dim Quad, label, content string,
- id, selected int) {
+ id, selected int, red bool) {
const tbox_size int = 14
tbox_style := ui.style[DEF_STYLE].Background(tcell.ColorBlack).Dim(true)
@@ -73,16 +73,9 @@ func i_draw_text_box(ui HardUI, line int, dim Quad, label, content string,
ui.style[DEF_STYLE], label)
if id == 4 && len(content) > 0 {
content = "***"
- } else if id == 5 && len(content) > 0 {
- file := content
- if file[0] == '~' {
- home, _ := os.UserHomeDir()
- file = home + file[1:]
- }
- if _, err := os.Stat(file);
- err != nil {
- tbox_style = tbox_style.Foreground(tcell.ColorRed)
- }
+ }
+ if red == true {
+ tbox_style = tbox_style.Foreground(tcell.ColorRed)
}
spaces := ""
for i := 0; i < tbox_size; i++ {
@@ -111,7 +104,7 @@ func i_draw_insert_panel(ui HardUI, in *HostNode) {
line := 2
if win.T + line >= win.B { return }
i_draw_text_box(ui, win.T + line, win, "Connection type", in.protocol_str(),
- 0, ui.insert_sel)
+ 0, ui.insert_sel, false)
line += 2
switch in.Protocol {
case 0:
@@ -120,42 +113,49 @@ func i_draw_insert_panel(ui HardUI, in *HostNode) {
}
func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) {
+ red := false
if win.T + line >= win.B { return }
text := "---- Host 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 }
- i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, 1, ui.insert_sel)
+ i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, 1, ui.insert_sel,
+ false)
if line += 1; win.T + line >= win.B { return }
i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)),
- 2, ui.insert_sel)
+ 2, ui.insert_sel, false)
if line += 2; win.T + line >= win.B { return }
- i_draw_text_box(ui, win.T + line, win, "User", in.User, 3, ui.insert_sel)
+ i_draw_text_box(ui, win.T + line, win, "User", in.User, 3, ui.insert_sel,
+ false)
if line += 1; win.T + line >= win.B { return }
- i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, 4, ui.insert_sel)
+ i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, 4, ui.insert_sel,
+ false)
if line += 1; win.T + line >= win.B { return }
- i_draw_text_box(ui, win.T + line, win, "SSH private key",
- in.Priv, 5, ui.insert_sel)
if len(in.Priv) > 0 {
file := in.Priv
if file[0] == '~' {
home, _ := os.UserHomeDir()
file = home + file[1:]
}
- if _, err := os.Stat(file);
- err != nil {
- if line += 1; win.T + line >= win.B { return }
- text := "file does not exist"
- i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line,
- win.R - 1, win.T + line, ui.style[ERR_STYLE], text)
+ 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.Priv, 5, ui.insert_sel, red)
+ if red == true {
+ if line += 1; win.T + line >= win.B { return }
+ 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 }
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 }
i_draw_text_box(ui, win.T + line, win, "Host/IP",
- in.Jump.Host, 6, ui.insert_sel)
+ in.Jump.Host, 6, ui.insert_sel, false)
// TODO: here
}
diff --git a/src/i_ui.go b/src/i_ui.go
index 31cc6bb..db782c1 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -372,7 +372,7 @@ func i_prompt_type(ui HardUI) {
ui.s.ShowCursor(len(text), ui.dim[H] - 1)
}
-func i_prompt_generic(ui HardUI, prompt string, secret, file bool) {
+func i_prompt_generic(ui HardUI, prompt string, secret bool, 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)
@@ -380,9 +380,26 @@ func i_prompt_generic(ui HardUI, prompt string, secret, file bool) {
ui.s.ShowCursor(len(prompt) + 1, ui.dim[H] - 1)
return
}
+ 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.ColorPurple).
+ Bold(false).
+ Underline(true)
+ } else {
+ style = style.Foreground(tcell.ColorGreen)
+ }
+ }
i_draw_text(ui.s, len(prompt) + 1,
ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1,
- ui.style[DEF_STYLE].Bold(true), ui.buff)
+ style, ui.buff)
ui.s.ShowCursor(len(prompt) + 1 + len(ui.buff), ui.dim[H] - 1)
}
@@ -552,6 +569,7 @@ func i_load_ui(data_dir string,
}
func i_ui(data_dir string) {
+ home_dir, _ := os.UserHomeDir()
ui := HardUI{}
opts := HardOpts{}
var err error
@@ -644,15 +662,16 @@ func i_ui(data_dir string) {
case 0:
i_prompt_type(data.ui)
case 1, 6:
- i_prompt_generic(data.ui, "Host/IP: ", false, false)
+ i_prompt_generic(data.ui, "Host/IP: ", false, "")
case 2:
- i_prompt_generic(data.ui, "Port: ", false, false)
+ i_prompt_generic(data.ui, "Port: ", false, "")
case 3:
- i_prompt_generic(data.ui, "User: ", false, false)
+ i_prompt_generic(data.ui, "User: ", false, "")
case 4:
- i_prompt_generic(data.ui, "Pass: ", true, false)
+ i_prompt_generic(data.ui, "Pass: ", true, "")
case 5:
- i_prompt_generic(data.ui, "Private key: ", false, true)
+ i_prompt_generic(data.ui, "Private key: ",
+ false, home_dir)
}
}
}