Merge branch 'scroll-options' of sloum/bombadillo into master

Closes #13 & #14
This commit is contained in:
sloum 2019-05-24 23:59:37 -04:00 committed by Gitea
commit 6a524d9f70
2 changed files with 78 additions and 0 deletions

View File

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

12
main.go
View File

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