mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Merge pull request #62 from yashpatel5400/yash
Added page up/down features
This commit is contained in:
commit
28f16c9a17
46
cursor.go
46
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)
|
||||
}
|
4
grid.go
4
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
|
||||
|
9
keys.go
9
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/<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",
|
||||
|
Loading…
Reference in New Issue
Block a user