From a19bc2c6d80ce5a764c24e8d3fc37bc902182b08 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Fri, 24 May 2019 20:49:37 -0700 Subject: [PATCH] Added page up, page down, home, and end to hot keys --- cui/window.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 12 ++++++++++ 2 files changed, 78 insertions(+) diff --git a/cui/window.go b/cui/window.go index 4569e5f..067e306 100644 --- a/cui/window.go +++ b/cui/window.go @@ -111,3 +111,69 @@ func (w *Window) ScrollUp() { fmt.Print("\a") } } + +func (w *Window) PageDown() { + var borderThickness int + if w.drawBox { + borderThickness = -1 + } else { + borderThickness = 1 + } + + height := w.Box.row2 - w.Box.row1 + borderThickness + contentLength := len(w.Content) + if w.Scrollposition < contentLength-height { + w.Scrollposition += height + if w.Scrollposition > contentLength-height { + w.Scrollposition = contentLength-height + } + } else { + fmt.Print("\a") + } +} + +func (w *Window) PageUp() { + var borderThickness int + if w.drawBox { + borderThickness = -1 + } else { + borderThickness = 1 + } + + height := w.Box.row2 - w.Box.row1 + borderThickness + contentLength := len(w.Content) + if w.Scrollposition > 0 && height < contentLength { + w.Scrollposition -= height + if w.Scrollposition < 0 { + w.Scrollposition = 0 + } + } else { + fmt.Print("\a") + } +} + +func (w *Window) ScrollHome() { + if w.Scrollposition > 0 { + w.Scrollposition = 0 + } else { + fmt.Print("\a") + } +} + +func (w *Window) ScrollEnd() { + var borderThickness int + if w.drawBox { + borderThickness = -1 + } else { + borderThickness = 1 + } + + height := w.Box.row2 - w.Box.row1 + borderThickness + + contentLength := len(w.Content) + if w.Scrollposition < contentLength-height { + w.Scrollposition = contentLength-height + } else { + fmt.Print("\a") + } +} diff --git a/main.go b/main.go index 0b811a4..4eb9996 100644 --- a/main.go +++ b/main.go @@ -487,6 +487,18 @@ func main() { screen.ReflashScreen(false) case 'q', 'Q': cui.Exit() + case 'g': + screen.Windows[screen.Activewindow].ScrollHome() + screen.ReflashScreen(false) + case 'G': + screen.Windows[screen.Activewindow].ScrollEnd() + screen.ReflashScreen(false) + case 'd': + screen.Windows[screen.Activewindow].PageDown() + screen.ReflashScreen(false) + case 'u': + screen.Windows[screen.Activewindow].PageUp() + screen.ReflashScreen(false) case 'b': success := history.GoBack() if success {