diff --git a/cursor.go b/cursor.go index 37abd15..e9673ea 100644 --- a/cursor.go +++ b/cursor.go @@ -1,6 +1,7 @@ package main import ( + "math" ui "github.com/gizak/termui" ) @@ -130,3 +131,48 @@ func (gc *GridCursor) Down() { gc.ScrollPage() ui.Render(cGrid) } + +func (gc *GridCursor) PgUp() { + idx := gc.Idx() + if idx <= 0 { // already at top + return + } + + var nextidx int + nextidx = int(math.Max(0.0, float64(idx - cGrid.MaxRows()))) + cGrid.Offset = int(math.Max(float64(cGrid.Offset - cGrid.MaxRows()), + float64(0))) + + active := gc.filtered[idx] + next := gc.filtered[nextidx] + + active.Widgets.Name.UnHighlight() + gc.selectedID = next.Id + next.Widgets.Name.Highlight() + + cGrid.Align() + ui.Render(cGrid) +} + +func (gc *GridCursor) PgDown() { + idx := gc.Idx() + if idx >= gc.Len()-1 { // already at bottom + return + } + + var nextidx int + nextidx = int(math.Min(float64(gc.Len() - 1), + float64(idx + cGrid.MaxRows()))) + cGrid.Offset = int(math.Min(float64(cGrid.Offset + cGrid.MaxRows()), + float64(gc.Len() - cGrid.MaxRows()))) + + active := gc.filtered[idx] + next := gc.filtered[nextidx] + + active.Widgets.Name.UnHighlight() + gc.selectedID = next.Id + next.Widgets.Name.Highlight() + + cGrid.Align() + ui.Render(cGrid) +} \ No newline at end of file diff --git a/grid.go b/grid.go index e9cd7d0..dab8943 100644 --- a/grid.go +++ b/grid.go @@ -79,6 +79,10 @@ func Display() bool { HandleKeys("up", cursor.Up) HandleKeys("down", cursor.Down) + + HandleKeys("pgup", cursor.PgUp) + HandleKeys("pgdown", cursor.PgDown) + HandleKeys("exit", ui.StopLoop) HandleKeys("help", func() { menu = HelpMenu diff --git a/keys.go b/keys.go index b7c4d3b..c55a72f 100644 --- a/keys.go +++ b/keys.go @@ -4,6 +4,7 @@ import ( ui "github.com/gizak/termui" ) +// Common action keybindings // Common action keybindings var keyMap = map[string][]string{ "up": []string{ @@ -14,6 +15,14 @@ var keyMap = map[string][]string{ "/sys/kbd/", "/sys/kbd/j", }, + "pgup": []string{ + "/sys/kbd/", + "/sys/kbd/C-", + }, + "pgdown": []string{ + "/sys/kbd/", + "/sys/kbd/C-", + }, "exit": []string{ "/sys/kbd/q", "/sys/kbd/C-c",