From 93ae2134804faed36c2fbe1be8ff02fe1aec95e4 Mon Sep 17 00:00:00 2001
From: Joe <rbo@gmx.us>
Date: Fri, 10 May 2024 20:20:20 +0200
Subject: gogo

---
 src/c_defs.go   | 17 +++++++++++------
 src/e_keys.go   | 10 ++++++++--
 src/i_help.go   | 34 +++++++++++++++++++++++++---------
 src/i_insert.go |  1 -
 src/i_ui.go     |  3 ++-
 5 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/src/c_defs.go b/src/c_defs.go
index 5d741ae..18a1805 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -180,12 +180,17 @@ const (
 
 var (
 	HELP_NORMAL_KEYS = [][2]string{
-	{"j | <down>",	"Down"},
-	{"k | <up>",	"Up"},
-	{"a | i",		"Insert host"},
-	{"y",			"Copy host"},
-	{"d",			"Cut host"},
-	{"p",			"Paste host"},
+	{"a | i",		"Create a new host"},
+	{"y",			"Copy selected host"},
+	{"d",			"Cut selected host"},
+	{"p",			"Paste host in clipboard"},
+	{"m",			"Create a new directory"},
+	{"e",			"Edit selected host"},
+	{"c",			"Rename selected item"},
+	{"<down> | j",	"Select next item"},
+	{"<up> | k",	"Select previous item"},
+	{"g",			"Go to first item"},
+	{"G",			"Go to last item"},
 	}
 )
 
diff --git a/src/e_keys.go b/src/e_keys.go
index 9f82ccc..af19547 100644
--- a/src/e_keys.go
+++ b/src/e_keys.go
@@ -401,7 +401,6 @@ func e_insert_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
 				}
 				if ui.insert_butt == false {
 					ui.insert_scroll += 2
-					// TODO: gogo
 				}
 			} else if event.Rune() == 'k' ||
 					  event.Key() == tcell.KeyUp {
@@ -842,14 +841,21 @@ func e_help_events(data *HardData, ui *HardUI, event tcell.EventKey) bool {
 		return true
 	} else if event.Rune() == 'j' ||
 			  event.Key() == tcell.KeyDown {
+		if ui.help_end == true {
+			return true
+		}
 		ui.help_scroll += 1
 	} else if event.Rune() == 'k' ||
 			  event.Key() == tcell.KeyUp {
-		if ui.help_scroll >= 0 {
+		if ui.help_scroll <= 0 {
 			ui.help_scroll = 0
 			return true
 		}
 		ui.help_scroll -= 1
+	} else if event.Rune() == 'g' {
+		ui.help_scroll = 0
+	} else if event.Rune() == 'G' {
+		// TODO: here
 	}
 	return false
 }
diff --git a/src/i_help.go b/src/i_help.go
index bafe1e2..cd8a5bd 100644
--- a/src/i_help.go
+++ b/src/i_help.go
@@ -51,9 +51,7 @@
 
 package main
 
-import "github.com/gdamore/tcell/v2"
-
-func i_draw_help(ui HardUI) {
+func i_draw_help(ui *HardUI) {
 	if ui.dim[W] < 12 || ui.dim[H] < 6 {
 		return
 	}
@@ -68,15 +66,33 @@ func i_draw_help(ui HardUI) {
 		ui.style[BOX_STYLE], ui.style[HEAD_STYLE],
 		" Keys ", true)
 	line := 0
-	i_help_normal(ui, win, &line)
+	line -= ui.help_scroll
+	if line < 0 {
+		ui.s.SetContent(win.L, win.T + 1, '▲',
+			nil, ui.style[BOX_STYLE])
+	}
+	ui.help_end = i_help_normal(*ui, win, &line)
+	if ui.help_end == false {
+		ui.s.SetContent(win.L, win.B - 1, '▼',
+			nil, ui.style[BOX_STYLE])
+	}
+	// TODO: here
 }
 
-func i_help_normal(ui HardUI, win Quad, line *int) {
+func i_help_normal(ui HardUI, win Quad, line *int) bool {
 	for _, v := range HELP_NORMAL_KEYS {
-		i_draw_text(ui.s, win.L + 4,  win.T + 1 + *line, win.R - 1, win.T + 1 + *line,
-			ui.style[DEF_STYLE], v[0])
-		i_draw_text(ui.s, win.L + 10, win.T + 1 + *line, win.R - 1, win.T + 1 +  *line,
-			ui.style[DEF_STYLE], v[1])
+		if *line < 0 {
+			*line += 1
+			continue
+		} else if win.T + *line + 1 >= win.B {
+			return false
+		}
+		i := 13 - len(v[0])
+		i_draw_text(ui.s, win.L + 1 + i, win.T + 1 + *line, win.L + 14,
+			win.T + 1 + *line, ui.style[BOT_STYLE], v[0])
+		i_draw_text(ui.s, win.L + 15,    win.T + 1 + *line, win.R - 1,
+			win.T + 1 +  *line, ui.style[DEF_STYLE], v[1])
 		*line += 1
 	}
+	return true
 }
diff --git a/src/i_insert.go b/src/i_insert.go
index 08efdb4..e191bc4 100644
--- a/src/i_insert.go
+++ b/src/i_insert.go
@@ -491,7 +491,6 @@ func i_draw_insert_panel(ui *HardUI, in *HostNode, home_dir string) {
 	if win.T + end_line >= win.B {
 		ui.s.SetContent(ui.dim[W] / 2, win.B, '▼',
 			nil, ui.style[BOX_STYLE])
-		// TODO: scroll or something
 	}
 	i_draw_insert_inputs(*ui, in, home_dir)
 }
diff --git a/src/i_ui.go b/src/i_ui.go
index 4de176f..3e0de04 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -76,6 +76,7 @@ type HardUI struct {
 	insert_scroll int
 	insert_butt bool
 	help_scroll int
+	help_end bool
 }
 
 type Quad struct {
@@ -756,7 +757,7 @@ func i_ui(data_dir string) {
 		case RENAME_MODE:
 			i_prompt_insert(data.ui, data.litems.curr)
 		case HELP_MODE:
-			i_draw_help(data.ui)
+			i_draw_help(&data.ui)
 		}
 		data.ui.s.Show()
 		e_events(&data, fp)
-- 
cgit v1.2.3