aboutsummaryrefslogtreecommitdiffstats
path: root/i_ui.go
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-01-05 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-01-05 20:20:20 +0100
commit1844f8bae695fc677062fb06db012a4102cd3f0a (patch)
tree342992624a99bbc05b942d35e955c3be4cfd4b91 /i_ui.go
parentnow draw litems list (diff)
downloadhardflip-1844f8bae695fc677062fb06db012a4102cd3f0a.tar.gz
hardflip-1844f8bae695fc677062fb06db012a4102cd3f0a.tar.bz2
hardflip-1844f8bae695fc677062fb06db012a4102cd3f0a.tar.xz
hardflip-1844f8bae695fc677062fb06db012a4102cd3f0a.tar.zst
hardflip-1844f8bae695fc677062fb06db012a4102cd3f0a.zip
now really draw
Diffstat (limited to 'i_ui.go')
-rw-r--r--i_ui.go36
1 files changed, 22 insertions, 14 deletions
diff --git a/i_ui.go b/i_ui.go
index 51ba600..72a7ecf 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_ui.go
- * Thu Jan 04 16:20:24 2024
+ * Fri Jan 05 16:40:33 2024
* Joe
*
* interfacing with the user
@@ -63,7 +63,7 @@ type HardUI struct {
list_start int
mode uint8
sel_max int
- line int
+ sel_id int
count_dirs int
count_hosts int
def_style tcell.Style
@@ -73,16 +73,21 @@ type HardUI struct {
}
func (ui *HardUI) inc_sel(n int, data *HardData) {
- if ui.line + n < 1 ||
- ui.line + n >= ui.sel_max {
+ // HACK: ui.sel_id and litems.curr.ID are essentially the same thing
+ // NOTE: maybe keep only one there, see later
+ if data.litems.curr == nil {
+ return
+ }
+ if ui.sel_id + n < 1 ||
+ ui.sel_id + n >= ui.sel_max {
n = 0
}
- ui.line += n
data.litems.curr = data.litems.curr.inc(n)
- if ui.line > ui.list_start + ui.dim[H] - 4 {
- ui.list_start = (ui.line + 1) - (ui.dim[H] + 3)
- } else if ui.line < ui.list_start {
- ui.list_start = ui.line
+ ui.sel_id = data.litems.curr.ID
+ if ui.sel_id > ui.list_start + ui.dim[H] - 4 {
+ ui.list_start = (ui.sel_id + 1) - (ui.dim[H] + 3)
+ } else if ui.sel_id < ui.list_start {
+ ui.list_start = ui.sel_id
}
}
@@ -236,7 +241,7 @@ func i_draw_delete_box(ui HardUI, host *HostNode) {
func i_host_panel_dirs(ui HardUI, icons bool, dirs *DirsNode, line int) {
style := ui.dir_style
- if ui.line == dirs.ID {
+ if ui.sel_id == dirs.ID {
style = style.Reverse(true)
}
text := ""
@@ -266,7 +271,7 @@ func i_host_panel_dirs(ui HardUI, icons bool, dirs *DirsNode, line int) {
func i_host_panel_host(ui HardUI, icons bool,
dirs *DirsNode, host *HostNode, line int) {
style := ui.def_style
- if ui.line == host.ID {
+ if ui.sel_id == host.ID {
style = style.Reverse(true)
}
text := ""
@@ -319,7 +324,7 @@ func i_host_panel(ui HardUI, icons bool, ldirs *DirsList) {
i_draw_text(ui.s,
1, ui.dim[H] - 2, (ui.dim[W] / 3) - 1, ui.dim[H] - 2,
ui.def_style,
- " " + strconv.Itoa(int(ui.line + 1)) + "/" +
+ " " + strconv.Itoa(int(ui.sel_id + 1)) + "/" +
strconv.Itoa(int(ui.sel_max)) + " hosts ")
}
}
@@ -338,7 +343,7 @@ func i_info_panel(ui HardUI, lhost *HostList) {
if lhost.head == nil {
return
}
- host = lhost.sel(ui.line)
+ host = lhost.sel(ui.sel_id)
host_type = host.protocol_str()
// name, type
i_draw_text(ui.s,
@@ -504,11 +509,14 @@ func i_get_sel_max(ldirs *DirsList) (int, int, int) {
}
func i_ui(data *HardData) {
+ // TODO: replace everything ui with litems
var err error
ui := &data.ui
- ui.s, err = tcell.NewScreen()
+ // TODO: get better counts
+ // NOTE: put this in c_load_data and also produce better code
ui.sel_max, ui.count_dirs, ui.count_hosts = i_get_sel_max(data.ldirs)
+ ui.s, err = tcell.NewScreen()
if err != nil {
c_die("view", err)
}