aboutsummaryrefslogtreecommitdiffstats
path: root/i_events.go
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-01-08 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-01-08 20:20:20 +0100
commit17b7d77493da530519c087d7a8168981afb406de (patch)
treefe8649fecd46774fa9b89e5a44ce48825de18f7b /i_events.go
parentok good (diff)
downloadhardflip-17b7d77493da530519c087d7a8168981afb406de.tar.gz
hardflip-17b7d77493da530519c087d7a8168981afb406de.tar.bz2
hardflip-17b7d77493da530519c087d7a8168981afb406de.tar.xz
hardflip-17b7d77493da530519c087d7a8168981afb406de.tar.zst
hardflip-17b7d77493da530519c087d7a8168981afb406de.zip
pretty fast
Diffstat (limited to 'i_events.go')
-rw-r--r--i_events.go36
1 files changed, 28 insertions, 8 deletions
diff --git a/i_events.go b/i_events.go
index 8f1601b..a5eb6a8 100644
--- a/i_events.go
+++ b/i_events.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_events.go
- * Mon Jan 08 11:35:21 2024
+ * Mon Jan 08 13:56:06 2024
* Joe
*
* events in the code
@@ -55,8 +55,23 @@ import (
"os"
"github.com/gdamore/tcell/v2"
+ "golang.org/x/term"
)
+func i_list_follow_cursor(litems *ItemsList, ui *HardUI) {
+ if litems.draw_start == nil {
+ return
+ }
+ for litems.draw_start.ID < litems.curr.ID - (ui.dim[H] - 4) &&
+ litems.draw_start.next != nil {
+ litems.draw_start = litems.draw_start.next
+ }
+ for litems.curr.ID < litems.draw_start.ID &&
+ litems.draw_start.prev != nil {
+ litems.draw_start = litems.draw_start.prev
+ }
+}
+
func i_reload_data(data *HardData) {
data.ldirs = c_load_data_dir(data.data_dir, data.opts)
data.litems = c_load_litems(data.ldirs)
@@ -87,6 +102,8 @@ func i_events(data *HardData) {
event := ui.s.PollEvent()
switch event := event.(type) {
case *tcell.EventResize:
+ ui.dim[W], ui.dim[H], _ = term.GetSize(0)
+ i_list_follow_cursor(data.litems, ui)
ui.s.Sync()
case *tcell.EventKey:
switch ui.mode {
@@ -97,16 +114,17 @@ func i_events(data *HardData) {
os.Exit(0)
} else if event.Rune() == 'j' ||
event.Key() == tcell.KeyDown {
- ui.inc_cursor(+1, data)
+ data.litems.inc(+1)
} else if event.Rune() == 'k' ||
- event.Key() == tcell.KeyUp {
- ui.inc_cursor(-1, data)
+ event.Key() == tcell.KeyUp {
+ data.litems.inc(-1)
} else if event.Key() == tcell.KeyCtrlD {
- ui.inc_cursor(+(ui.dim[H] / 4), data)
+ data.litems.inc(+(ui.dim[H] / 3))
} else if event.Key() == tcell.KeyCtrlU {
- ui.inc_cursor(-(ui.dim[H] / 4), data)
+ data.litems.inc(-(ui.dim[H] / 3))
} else if event.Rune() == 'g' {
data.litems.curr = data.litems.head
+ data.litems.draw_start = data.litems.head
} else if event.Rune() == 'G' {
data.litems.curr = data.litems.last
} else if event.Rune() == 'D' &&
@@ -114,7 +132,8 @@ func i_events(data *HardData) {
ui.sel_max != 0 {
ui.mode = DELETE_MODE
} else if event.Key() == tcell.KeyEnter {
- if data.litems.curr != nil && data.litems.curr.is_dir() == false {
+ if data.litems.curr != nil &&
+ data.litems.curr.is_dir() == false {
ui.s.Fini()
c_exec(data.litems.curr.Host)
if data.opts.Loop == false {
@@ -143,6 +162,7 @@ func i_events(data *HardData) {
i_delete_host(data)
ui.mode = NORMAL_MODE
}
- }
+ }
+ i_list_follow_cursor(data.litems, ui)
}
}