Skip to content

Commit

Permalink
Improve Viewport
Browse files Browse the repository at this point in the history
Call Bell function when we reach the end and the beginning of the
context we're scrolling.

I wanted to add page up and page down so I moved move up and move down
logic into functions, key presses for viewport will just give a smaller
or greater value of how much to move up or down.
  • Loading branch information
electrikmilk committed Mar 12, 2023
1 parent af9a13f commit b2994ac
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ func wrapString(str *string, limit int) (wrapped string) {
return
}

func moveUp(n int) {
if (lineIdx - 1) >= 0 {
lineIdx -= n
} else {
Bell()
}
}

func moveDown(n int) {
if (rows + lineIdx - 1) < contentsLinesCount {
lineIdx += n
} else {
Bell()
}
}

func handleViewportKeys(key any) {
select {
case <-stopViewport:
Expand All @@ -92,14 +108,14 @@ func handleViewportKeys(key any) {
case keyboard.KeyCtrlC:
StopPainting()
stopViewport <- true
case keyboard.KeyPgup:
moveUp(5)
case keyboard.KeyPgdn:
moveDown(5)
case keyboard.KeyArrowUp:
if (lineIdx - 1) >= 0 {
lineIdx--
}
moveUp(1)
case keyboard.KeyArrowDown:
if (rows + lineIdx - 1) < contentsLinesCount {
lineIdx++
}
moveDown(1)
}
}
}

0 comments on commit b2994ac

Please sign in to comment.