diff options
Diffstat (limited to '')
-rw-r--r-- | src/c_defs.go | 3 | ||||
-rw-r--r-- | src/c_exec.go | 2 | ||||
-rw-r--r-- | src/i_events.go | 104 | ||||
-rw-r--r-- | src/i_insert.go | 43 | ||||
-rw-r--r-- | src/i_ui.go | 39 |
5 files changed, 157 insertions, 34 deletions
diff --git a/src/c_defs.go b/src/c_defs.go index f11b93c..1385a4c 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -67,8 +67,7 @@ m: mkdir - !?: help` ERROR_KEYS_HINTS = "[Enter]: ok" CONFIRM_KEYS_HINTS = `y/n: yes - no` - INSERT_KEYS_HINTS = `[Tab]: next - -[S-Tab]: prev` + INSERT_KEYS_HINTS = `` ) const ( diff --git a/src/c_exec.go b/src/c_exec.go index 722df37..69bff7c 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -150,7 +150,7 @@ func c_format_rdp(host *HostNode, pass string) ([]string, []string) { "-decorations", "-fonts", "-themes", "/bpp:8", "/compression-level:2") } else if host.Quality == 1 { - } else { + } else if host.Quality == 2 { cmd_fmt = append(cmd_fmt, "+aero", "+menu-anims", "+window-drag", "+decorations", "+fonts", "+themes", "/gfx:RFX", "/rfx", "/gdi:hw", diff --git a/src/i_events.go b/src/i_events.go index 7bbda68..9638ffd 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_events.go - * Wed Feb 21 14:39:57 2024 + * Tue Feb 27 14:56:58 2024 * Joe * * events in the code @@ -320,6 +320,29 @@ func i_mkdir(data *HardData, ui *HardUI) { } } +func i_set_protocol_defaults(in *HostNode) { + switch in.Protocol { + case 0: + in.Port = 22 + case 1: + in.Port = 3389 + in.Quality = 2 + in.Width = 1600 + in.Height = 1200 + in.Dynamic = true + case 2: + in.Shell = []string{"/bin/sh", "-c"} + case 3: + in.Stack.RegionName = "eu-west-0" + in.Stack.IdentityAPI = "3" + in.Stack.ImageAPI = "2" + in.Stack.NetworkAPI = "2" + in.Stack.VolumeAPI = "3.42" + in.Stack.EndpointType = "publicURL" + in.Stack.Interface = "public" + } +} + // screen events such as keypresses func i_events(data *HardData) { ui := &data.ui @@ -444,6 +467,9 @@ func i_events(data *HardData) { } else if event.Rune() == 'a' || event.Rune() == 'i' { data.ui.mode = INSERT_MODE + data.ui.insert_sel = 0 + data.ui.insert_sel_max = 4 + data.ui.insert_sel_ok = false } else if event.Key() == tcell.KeyCtrlR { event = nil i_reload_data(data) @@ -492,26 +518,72 @@ func i_events(data *HardData) { } } case INSERT_MODE: - if event.Key() == tcell.KeyEscape || - event.Key() == tcell.KeyCtrlC { - ui.s.HideCursor() - data.ui.mode = NORMAL_MODE - data.insert = nil - ui.buff = "" - } else if event.Key() == tcell.KeyEnter { - if ui.buff == "" { + 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 data.insert = nil ui.buff = "" - break + } 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 + data.insert = nil + ui.buff = "" + break + } + ui.s.HideCursor() + data.insert = &HostNode{} + i_set_protocol_defaults(data.insert) + data.insert.Name = ui.buff + ui.buff = "" + } else { + i_readline(event, data) + } + } else if data.insert != nil { + if data.ui.insert_sel_ok == false { + if event.Key() == tcell.KeyEscape || + event.Key() == tcell.KeyCtrlC { + ui.s.HideCursor() + data.ui.mode = NORMAL_MODE + data.ui.insert_sel = 0 + data.insert = nil + ui.buff = "" + } else if event.Rune() == 'j' || + event.Key() == tcell.KeyDown { + if data.ui.insert_sel < data.ui.insert_sel_max { + data.ui.insert_sel += 1 + } + } else if event.Rune() == 'k' || + event.Key() == tcell.KeyUp { + if data.ui.insert_sel > 0 { + data.ui.insert_sel -= 1 + } + } else if event.Key() == tcell.KeyEnter { + data.ui.insert_sel_ok = true + } + } else { + if event.Key() == tcell.KeyEscape || + event.Key() == tcell.KeyCtrlC { + data.ui.insert_sel_ok = false + ui.s.HideCursor() + } + switch data.ui.insert_sel { + case 0: + if event.Rune() < '1' || event.Rune() > '4' { + break + } else { + data.insert.Protocol = int8(event.Rune() - 48 - 1) + data.ui.insert_sel_ok = false + ui.s.HideCursor() + i_set_protocol_defaults(data.insert) + } + } } - ui.s.HideCursor() - data.insert = &HostNode{} - data.insert.Name = ui.buff - ui.buff = "" - } else { - i_readline(event, data) } // TODO: reset data.insert to nil on validate case MKDIR_MODE: diff --git a/src/i_insert.go b/src/i_insert.go index 5b246aa..12f4cf3 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_insert.go - * Tue Feb 27 13:48:05 2024 + * Tue Feb 27 14:31:54 2024 * Joe * * insert a new host @@ -51,23 +51,33 @@ package main -import "github.com/gdamore/tcell/v2" +import ( + "strconv" + "github.com/gdamore/tcell/v2" +) -func i_draw_text_box(ui HardUI, line int, dim Quad, label, content string) { +func i_draw_text_box(ui HardUI, line int, dim Quad, label, content string, + id, selected int) { const tbox_size int = 14 + tbox_style := ui.style[STYLE_DEF].Background(tcell.ColorBlack).Dim(true) - l := ui.dim[W] / 2 - len(label) - 1 + if id == selected { + tbox_style = tbox_style.Reverse(true).Dim(false) + } + + l := ui.dim[W] / 2 - len(label) - 2 if l <= dim.L { l = dim.L + 1 } i_draw_text(ui.s, l, line, ui.dim[W] / 2, line, ui.style[STYLE_DEF], label) - // TODO: here spaces := "" for i := 0; i < tbox_size; i++ { spaces += " " } i_draw_text(ui.s, ui.dim[W] / 2, line, dim.R, line, - ui.style[STYLE_DEF].Background(tcell.ColorBlack).Dim(true), - "|" + spaces + "|") + tbox_style, + "[" + spaces + "]") + i_draw_text(ui.s, ui.dim[W] / 2 + 1, line, ui.dim[W] / 2 + 1 + tbox_size, + line, tbox_style, content) } func i_draw_insert_panel(ui HardUI, in *HostNode) { @@ -83,5 +93,22 @@ func i_draw_insert_panel(ui HardUI, in *HostNode) { i_draw_box(ui.s, win.L, win.T, win.R, win.B, ui.style[STYLE_BOX], ui.style[STYLE_HEAD], " Insert - " + in.Name + " ", true) - i_draw_text_box(ui, win.T + 2, win, "Connection type", "fuck this") + line := 2 + i_draw_text_box(ui, win.T + line, win, "Connection type", in.protocol_str(), + 0, ui.insert_sel) + line += 2 + i_draw_insert_ssh(ui, line, win, in) +} + +func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) { + i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, 1, ui.insert_sel) + line += 1 + i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)), + 2, ui.insert_sel) + line += 2 + i_draw_text_box(ui, win.T + line, win, "User", in.User, 3, ui.insert_sel) + line += 1 + i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, 4, ui.insert_sel) // TODO: gpg + line += 1 + // TODO: here } diff --git a/src/i_ui.go b/src/i_ui.go index 15cb24e..043bdca 100644 --- a/src/i_ui.go +++ b/src/i_ui.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Wed Feb 21 19:42:11 2024 + * Tue Feb 27 14:31:52 2024 * Joe * * interfacing with the user @@ -61,12 +61,15 @@ import ( ) type HardUI struct { - s tcell.Screen - mode uint8 - style [7]tcell.Style - dim [2]int - err [2]string - buff string + s tcell.Screen + mode uint8 + style [7]tcell.Style + dim [2]int + err [2]string + buff string + insert_sel int + insert_sel_max int + insert_sel_ok bool } type Quad struct { @@ -356,6 +359,23 @@ func i_prompt_mkdir(ui HardUI, curr *ItemsNode) { ui.s.ShowCursor(len(prompt) + 1 + len(path) + len(ui.buff), ui.dim[H] - 1) } +func i_prompt_type(ui HardUI) { + i_draw_msg(ui.s, 4, ui.style[STYLE_BOX], ui.dim, " Connection type ") + i_draw_text(ui.s, 2, ui.dim[H] - 6, ui.dim[W] - 2, ui.dim[H] - 6, + ui.style[STYLE_DEF], "[1] SSH") + i_draw_text(ui.s, 2, ui.dim[H] - 5, ui.dim[W] - 2, ui.dim[H] - 5, + ui.style[STYLE_DEF], "[2] RDP") + i_draw_text(ui.s, 2, ui.dim[H] - 4, ui.dim[W] - 2, ui.dim[H] - 4, + ui.style[STYLE_DEF], "[3] Single command") + i_draw_text(ui.s, 2, ui.dim[H] - 3, ui.dim[W] - 2, ui.dim[H] - 3, + ui.style[STYLE_DEF], "[4] OpenStack CLI") + text := "Type: " + i_draw_text(ui.s, 0, + ui.dim[H] - 1, ui.dim[W] - 1, ui.dim[H] - 1, + ui.style[STYLE_DEF], text) + ui.s.ShowCursor(len(text), ui.dim[H] - 1) +} + func i_prompt_insert(ui HardUI, curr *ItemsNode) { path := "/" if curr != nil { @@ -616,6 +636,11 @@ func i_ui(data_dir string) { i_prompt_insert(data.ui, data.litems.curr) } else { i_draw_insert_panel(data.ui, data.insert) + if data.ui.insert_sel_ok == true { + if data.ui.insert_sel == 0 { + i_prompt_type(data.ui) + } + } } } data.ui.s.Show() |