diff options
author | Joe <rbo@gmx.us> | 2024-01-19 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-19 20:20:20 +0100 |
commit | 06a41eb85b9db31c6ca6502417c02e726d724578 (patch) | |
tree | 609199fb9c34bb967bb5ab0dd6aa22e6e707636f | |
parent | less retarded limits (diff) | |
download | hardflip-06a41eb85b9db31c6ca6502417c02e726d724578.tar.gz hardflip-06a41eb85b9db31c6ca6502417c02e726d724578.tar.bz2 hardflip-06a41eb85b9db31c6ca6502417c02e726d724578.tar.xz hardflip-06a41eb85b9db31c6ca6502417c02e726d724578.tar.zst hardflip-06a41eb85b9db31c6ca6502417c02e726d724578.zip |
msg mode
-rw-r--r-- | i_info.go | 82 | ||||
-rw-r--r-- | i_ui.go | 102 |
2 files changed, 105 insertions, 79 deletions
@@ -64,28 +64,28 @@ func i_info_panel_dirs(ui HardUI, dir *DirsNode) { } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Name: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, dir.Name) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Type: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, "Directory") if line += 2; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Path: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, dir.path()) } @@ -97,19 +97,19 @@ func i_info_panel_host(ui HardUI, host *HostNode) { } // name, type i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Name: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, host.Name) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Type: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, host_type) if line += 2; line > ui.dim[H] - 3 { return @@ -119,19 +119,19 @@ func i_info_panel_host(ui HardUI, host *HostNode) { } // host, port i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Host: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, host.Host) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Port: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, strconv.Itoa(int(host.Port))) if line += 1; line > ui.dim[H] - 3 { return @@ -140,10 +140,10 @@ func i_info_panel_host(ui HardUI, host *HostNode) { if host.Protocol == 1 { if len(host.Domain) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Domain: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line, ui.def_style, host.Domain) if line += 1; line > ui.dim[H] - 3 { return @@ -155,20 +155,20 @@ func i_info_panel_host(ui HardUI, host *HostNode) { } // user infos i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "User: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, host.User) if line += 1; line > ui.dim[H] - 3 { return } if len(host.Pass) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Pass: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, "***") if line += 1; line > ui.dim[H] - 3 { return @@ -176,10 +176,10 @@ func i_info_panel_host(ui HardUI, host *HostNode) { } if host.Protocol == 0 && len(host.Priv) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Privkey: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 13, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line, ui.def_style, host.Priv) if line += 1; line > ui.dim[H] - 3 { return @@ -191,44 +191,44 @@ func i_info_panel_host(ui HardUI, host *HostNode) { // jump if host.Protocol == 0 && len(host.Jump) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Jump settings: ") if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 5, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, ui.title_style, "Host: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, ui.def_style, host.Jump) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 5, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, ui.title_style, "Port: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, ui.def_style, strconv.Itoa(int(host.JumpPort))) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 5, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, ui.title_style, "User: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, ui.def_style, host.JumpUser) if line += 1; line > ui.dim[H] - 3 { return } if len(host.JumpPass) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 5, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, ui.title_style, "Pass: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, ui.def_style, "***") if line += 1; line > ui.dim[H] - 3 { return @@ -236,10 +236,10 @@ func i_info_panel_host(ui HardUI, host *HostNode) { } if host.Protocol == 0 && len(host.JumpPriv) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 5, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, ui.title_style, "Privkey: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 14, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 13, line, ui.dim[W] - 2, line, ui.def_style, host.JumpPriv) if line += 1; line > ui.dim[H] - 3 { return @@ -253,10 +253,10 @@ func i_info_panel_host(ui HardUI, host *HostNode) { if host.Protocol == 1 { qual := [3]string{"Low", "Medium", "High"} i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Screen size: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 17, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 16, line, ui.dim[W] - 2, line, ui.def_style, strconv.Itoa(int(host.Width)) + "x" + strconv.Itoa(int(host.Height))) @@ -264,19 +264,19 @@ func i_info_panel_host(ui HardUI, host *HostNode) { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Dynamic window: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 20, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 19, line, ui.dim[W] - 2, line, ui.def_style, strconv.FormatBool(host.Dynamic)) if line += 1; line > ui.dim[H] - 3 { return } i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Quality: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 13, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line, ui.def_style, qual[host.Quality]) line += 1 if line += 1; line > ui.dim[H] - 3 { @@ -286,10 +286,10 @@ func i_info_panel_host(ui HardUI, host *HostNode) { // note if len(host.Note) > 0 { i_draw_text(ui.s, - (ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line, ui.title_style, "Note: ") i_draw_text(ui.s, - (ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line, + (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line, ui.def_style, host.Note) if line += 1; line > ui.dim[H] - 3 { return @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Thu Jan 18 17:51:03 2024 + * Fri Jan 19 17:09:15 2024 * Joe * * interfacing with the user @@ -68,6 +68,18 @@ type HardUI struct { dim [2]int } +func i_left_right(text_len int, ui *HardUI) (int, int) { + left := (ui.dim[W] / 2) - text_len / 2 + right := ui.dim[W] - 1 + if left < 1 { + left = 1 + } + if right >= ui.dim[W] - 1 { + right = ui.dim[W] - 1 + } + return left, right +} + func i_draw_text(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string) { @@ -123,6 +135,42 @@ func i_draw_box(s tcell.Screen, x1, y1, x2, y2 int, title string, fill bool) { i_draw_text(s, x1 + 1, y1, x2 - 1, y1, style, title) } +func i_draw_msg(s tcell.Screen, lines int, dim [2]int, title string) { + style := tcell.StyleDefault. + Background(tcell.ColorReset). + Foreground(tcell.ColorReset) + + lines += 1 + if lines < 0 { + return + } + if lines > dim[H] - 2 { + lines = dim[H] - 2 + } + for row := dim[H] - 2 - lines; row < dim[H] - 2; row++ { + s.SetContent(0, row, tcell.RuneVLine, nil, style) + s.SetContent(dim[W] - 1, row, tcell.RuneVLine, nil, style) + } + for col := 1; col < dim[W] - 1; col++ { + s.SetContent(col, dim[H] - 2 - lines, tcell.RuneHLine, nil, style) + s.SetContent(col, dim[H] - 2, tcell.RuneHLine, nil, style) + } + s.SetContent(0, dim[H] - 2 - lines, tcell.RuneULCorner, nil, style) + s.SetContent(dim[W] - 1, dim[H] - 2 - lines, tcell.RuneURCorner, nil, style) + s.SetContent(0, dim[H] - 2, tcell.RuneLLCorner, nil, style) + s.SetContent(dim[W] - 1, dim[H] - 2, tcell.RuneLRCorner, nil, style) + // s.SetContent(dim[W] / 3, dim[H] - 2 - lines, tcell.RuneBTee, nil, style) + // s.SetContent(0, dim[H] - 2 - lines, tcell.RuneLTee, nil, style) + // s.SetContent(dim[W] - 1, dim[H] - 2 - lines, tcell.RuneRTee, nil, style) + for y := dim[H] - 2 - lines + 1; y < dim[H] - 2; y++ { + for x := 1; x < dim[W] - 1; x++ { + s.SetContent(x, y, ' ', nil, style) + } + } + i_draw_text(s, 1, dim[H] - 2 - lines, len(title) + 2, dim[H] - 2 - lines, + style, title) +} + func i_draw_bottom_text(ui HardUI) { text := "" @@ -141,6 +189,7 @@ func i_draw_bottom_text(ui HardUI) { } func i_draw_zhosts_box(ui HardUI) { + // TODO: msg mode text := "Hosts list empty. Add hosts/folders by pressing (a/m)" left, right := (ui.dim[W] / 2) - (len(text) / 2) - 5, @@ -159,7 +208,7 @@ func i_draw_zhosts_box(ui HardUI) { ui.def_style, text) } -func i_draw_delete_box(ui HardUI, item *ItemsNode) { +func i_draw_delete_msg(ui HardUI, item *ItemsNode) { var text string var file string @@ -171,39 +220,15 @@ func i_draw_delete_box(ui HardUI, item *ItemsNode) { text = "Really delete this host?" file = host.Parent.path() + host.Filename } - max_len := len(text) - - if max_len < len(file) { - max_len = len(file) - } - left, right := - (ui.dim[W] / 2) - (max_len / 2) - 5, - (ui.dim[W] / 2) + (max_len / 2) + 5 - if left < 1 { - left = 1 - } - if right > ui.dim[W] - 2 { - right = ui.dim[W] - 2 - } - top, bot := - (ui.dim[H] / 2) - 2, - (ui.dim[H] / 2) + 2 - i_draw_box(ui.s, left, top, right, bot, " Delete ", true) - left = (ui.dim[W] / 2) - (len(text) / 2) - if left < (ui.dim[W] / 8) + 1 { - left = (ui.dim[W] / 8) + 1 - } - top = ui.dim[H] / 2 - 1 + file = file[1:] + i_draw_msg(ui.s, 2, ui.dim, " Delete ") + left, right := i_left_right(len(text), &ui) + line := ui.dim[H] - 2 - 2 + i_draw_text(ui.s, left, line, right, line, ui.def_style, text) + left, right = i_left_right(len(file), &ui) + line += 1 i_draw_text(ui.s, - left, top, right, top, - ui.def_style, text) - left = (ui.dim[W] / 2) - (len(file) / 2) - if left < (ui.dim[W] / 8) + 1 { - left = (ui.dim[W] / 8) + 1 - } - top += 1 - i_draw_text(ui.s, - left, top, right, top, + left, line, right, line, ui.def_style.Bold(true), file) } @@ -242,9 +267,10 @@ func i_draw_load_ui(ui *HardUI) { return } ui.s.Clear() + // TODO: msg mode text := "Loading " + strconv.Itoa(g_load_count) + " hosts" text_len := len(text) / 2 - i_draw_box(ui.s, 0, 0, ui.dim[W] - 1, ui.dim[H] - 2, " hardflip ", false) + // i_draw_box(ui.s, 0, 0, ui.dim[W] - 1, ui.dim[H] - 2, " hardflip ", false) left, right := (ui.dim[W] / 2) - (text_len + 2), (ui.dim[W] / 2) + (text_len + 2) @@ -261,8 +287,8 @@ func i_draw_load_ui(ui *HardUI) { left, right = (ui.dim[W] / 2) - (text_len - 1), (ui.dim[W] / 2) + (text_len + 1) - if left < 1 { - left = 1 + if left < 2 { + left = 2 } if right > ui.dim[W] - 2 { right = ui.dim[W] - 2 @@ -340,7 +366,7 @@ func i_ui(data_dir string, opts HardOpts) { i_draw_zhosts_box(data.ui) } if data.ui.mode == DELETE_MODE { - i_draw_delete_box(data.ui, data.litems.curr) + i_draw_delete_msg(data.ui, data.litems.curr) } data.ui.s.Show() i_events(&data) |