Scroll top/bottom with Home and End keys

* Allows the use of the Home/End keys in order to scroll to the top or
   bottom of the list of stocks.
master
root 3 years ago
parent e1f62d6afc
commit 4a080bfc3f
  1. 4
      cmd/mop/main.go
  2. 13
      screen.go

@ -114,6 +114,10 @@ loop:
} else if event.Key == termbox.KeyArrowDown || event.Ch == 'j' { } else if event.Key == termbox.KeyArrowDown || event.Ch == 'j' {
screen.IncreaseOffset(1, len(profile.Tickers)) screen.IncreaseOffset(1, len(profile.Tickers))
redrawQuotesFlag = true redrawQuotesFlag = true
} else if event.Key == termbox.KeyHome {
screen.ScrollTop()
} else if event.Key == termbox.KeyEnd {
screen.ScrollBottom(len(profile.Tickers))
} }
} else if lineEditor != nil { } else if lineEditor != nil {
if done := lineEditor.Handle(event); done { if done := lineEditor.Handle(event); done {

@ -106,6 +106,19 @@ func (screen *Screen) DecreaseOffset(n int) {
} }
} }
func (screen *Screen) ScrollTop() {
screen.offset = 0
}
func (screen *Screen) ScrollBottom(max int) {
bottom := max - screen.height + screen.headerLine
if bottom > 0 {
screen.offset = bottom
} else {
screen.offset = 0
}
}
// Draw accepts variable number of arguments and knows how to display the // Draw accepts variable number of arguments and knows how to display the
// market data, stock quotes, current time, and an arbitrary string. // market data, stock quotes, current time, and an arbitrary string.
func (screen *Screen) Draw(objects ...interface{}) *Screen { func (screen *Screen) Draw(objects ...interface{}) *Screen {

Loading…
Cancel
Save