diff options
-rw-r--r-- | c_defs.go | 5 | ||||
-rw-r--r-- | c_hardflip.go | 8 | ||||
-rw-r--r-- | c_utils.go | 2 | ||||
-rw-r--r-- | i_ui.go | 38 |
4 files changed, 33 insertions, 20 deletions
@@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_defs.go - * Tue Dec 19 16:36:48 2023 + * Wed Dec 20 12:21:38 2023 * Joe * * constants @@ -54,8 +54,9 @@ const ( (q)uit - [x](a)dd/(i)nsert host - [x](e)dit - -[x](D)elete - +(D)elete - [x](s)earch - (c-r) reload - [x](?) help` + DATA_DIR_NAME = "hardflip" ) diff --git a/c_hardflip.go b/c_hardflip.go index 5ad9e8e..ca231f7 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -47,7 +47,11 @@ package main -import "github.com/gdamore/tcell/v2" +import ( + // "os" + + "github.com/gdamore/tcell/v2" +) type Data struct { lhost *HostList @@ -55,6 +59,7 @@ type Data struct { opts Opts s tcell.Screen data_dir string + list_start int } func main() { @@ -64,6 +69,7 @@ func main() { Opts{true, true}, nil, data_dir, + 0, } i_ui(&data) } @@ -70,7 +70,7 @@ func c_get_data_dir() string { ptr = &home *ptr += "/.local/share" } - *ptr += "/hardflip" + *ptr += "/" + DATA_DIR_NAME if _, err := os.Stat(*ptr); os.IsNotExist(err) { if err := os.MkdirAll(*ptr, os.ModePerm); err != nil { c_die("could not create path " + *ptr, err) @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_ui.go - * Wed Dec 20 11:05:07 2023 + * Wed Dec 20 13:53:02 2023 * Joe * * interfacing with the user @@ -132,14 +132,17 @@ func i_draw_zhosts_box(s tcell.Screen, t [2]int, def_style tcell.Style) { def_style, text) } -func i_host_panel(s tcell.Screen, t [2]int, - def_style tcell.Style, lhost *HostList, +func i_host_panel(data *Data, t [2]int, + def_style tcell.Style, sel uint64, sel_max uint64) { - i_draw_box(s, 0, 0, + i_draw_box(data.s, 0, 0, t[W] / 3, t[H] - 2, " Hosts ") - host := lhost.head - for host != nil { + host := data.lhost.head + for i := 0; i < data.list_start && host.next != nil; i++ { + host = host.next + } + for line := 1; line < t[H] - 2 && host != nil; line++ { style := def_style if sel == host.ID { style = tcell.StyleDefault. @@ -147,26 +150,25 @@ func i_host_panel(s tcell.Screen, t [2]int, Foreground(tcell.ColorBlack) } spaces := "" - for i := 0; i < (t[W] / 3) - len(host.Folder + host.Name) - 2; i++ { spaces += " " } if host.Type == 0 { - i_draw_text(s, - 1, int(host.ID) + 1, t[W] / 3, int(host.ID) + 1, + i_draw_text(data.s, + 1, line, t[W] / 3, line, style, " " + host.Folder + host.Name + spaces) } else if host.Type == 1 { - i_draw_text(s, - 1, int(host.ID) + 1, t[W] / 3, int(host.ID) + 1, + i_draw_text(data.s, + 1, line, t[W] / 3, line, style, " " + host.Folder + host.Name + spaces) } - i_draw_text(s, - 4, int(host.ID) + 1, t[W] / 3, int(host.ID) + 1, + i_draw_text(data.s, + 4, line, t[W] / 3, line, style, host.Folder + host.Name + spaces) host = host.next } - i_draw_text(s, - 1, t[H] - 2, (t[W] / 3) - 1, t[H] - 1, + i_draw_text(data.s, + 1, t[H] - 2, (t[W] / 3) - 1, t[H] - 2, def_style, " " + strconv.Itoa(int(sel + 1)) + "/" + strconv.Itoa(int(sel_max)) + " hosts ") @@ -374,12 +376,16 @@ func i_ui(data *Data) { term_size[W], term_size[H], _ = term.GetSize(0) data.s.Clear() i_bottom_text(data.s, term_size) - i_host_panel(data.s, term_size, def_style, data.lhost, sel, sel_max) + i_host_panel(data, term_size, def_style, sel, sel_max) i_info_panel(data.s, term_size, def_style, data.lhost, sel) if data.lhost.head == nil { i_draw_zhosts_box(data.s, term_size, def_style) } data.s.Show() i_events(data, &sel, &sel_max, &term_size) + data.list_start = int(sel) - term_size[H] - 4 + if data.list_start < 0 { + data.list_start = 0 + } } } |