From 4a080bfc3f94d6875be8697edd17b29d8dd9a176 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 2 May 2022 00:19:34 +0100 Subject: [PATCH] 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. --- cmd/mop/main.go | 4 ++++ screen.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cmd/mop/main.go b/cmd/mop/main.go index 1368303..e280e48 100644 --- a/cmd/mop/main.go +++ b/cmd/mop/main.go @@ -114,6 +114,10 @@ loop: } else if event.Key == termbox.KeyArrowDown || event.Ch == 'j' { screen.IncreaseOffset(1, len(profile.Tickers)) 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 { if done := lineEditor.Handle(event); done { diff --git a/screen.go b/screen.go index b7c32fe..12e6a8a 100644 --- a/screen.go +++ b/screen.go @@ -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 // market data, stock quotes, current time, and an arbitrary string. func (screen *Screen) Draw(objects ...interface{}) *Screen {