1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-06-19 19:25:24 +00:00

Support paging - fixes #19

This commit is contained in:
makeworld 2020-06-29 15:01:41 -04:00
parent c594155c1a
commit 3e807ab5b8
3 changed files with 29 additions and 0 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Alt-Left and Alt-Right for history navigation (#23)
- You can type `..` in the bottom bar to go up a directory in the URL (#21)
- Error popup for when input string would result in a too long out-of-spec URL (#25)
- Paging, using <kbd>d</kbd> and <kbd>u</kbd>, as well as <kbd>Page Up</kbd> and <kbd>Page Down</kbd> (#19)
### Changed
- Bottom bar now says `URL/Num./Search: ` when space is pressed

View File

@ -20,7 +20,9 @@ var tabMap = make(map[int]*structs.Page) // Map of tab number to page
// Holds the actual tab primitives
var tabViews = make(map[int]*cview.TextView)
// Terminal dimensions
var termW int
var termH int
// The user input and URL display bar at the bottom
var bottomBar = cview.NewInputField().
@ -69,6 +71,7 @@ var App = cview.NewApplication().
SetAfterResizeFunc(func(width int, height int) {
// Store for calculations
termW = width
termH = height
// Shift new tabs created before app startup, when termW == 0
// XXX: This is hacky but works. The biggest issue is that there will sometimes be a tiny flash
@ -247,6 +250,12 @@ func Init() {
case tcell.KeyCtrlD:
go addBookmark()
return nil
case tcell.KeyPgUp:
pageUp()
return nil
case tcell.KeyPgDn:
pageDown()
return nil
case tcell.KeyRune:
// Regular key was sent
switch string(event.Rune()) {
@ -271,6 +280,13 @@ func Init() {
case "?":
Help()
return nil
case "u":
pageUp()
return nil
case "d":
pageDown()
return nil
// Shift+NUMBER keys, for switching to a specific tab
case "!":
SwitchTab(0)

View File

@ -17,6 +17,18 @@ import (
// This file contains the functions that aren't part of the public API.
// pageUp scrolls up 75% of the height of the terminal, like Bombadillo.
func pageUp() {
row, col := tabViews[curTab].GetScrollOffset()
tabViews[curTab].ScrollTo(row-(termH/4)*3, col)
}
// pageDown scrolls down 75% of the height of the terminal, like Bombadillo.
func pageDown() {
row, col := tabViews[curTab].GetScrollOffset()
tabViews[curTab].ScrollTo(row+(termH/4)*3, col)
}
func leftMargin() int {
return int(float64(termW) * viper.GetFloat64("a-general.left_margin"))
}