Added page up/down features

This commit is contained in:
yashpatel5400 2017-03-23 22:31:08 -04:00
parent 5db90f31dc
commit 6560768e08
3 changed files with 59 additions and 0 deletions

View File

@ -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)
}

View File

@ -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

View File

@ -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/<down>",
"/sys/kbd/j",
},
"pgup": []string{
"/sys/kbd/<previous>",
"/sys/kbd/C-<up>",
},
"pgdown": []string{
"/sys/kbd/<next>",
"/sys/kbd/C-<down>",
},
"exit": []string{
"/sys/kbd/q",
"/sys/kbd/C-c",