add first/last page key shortcut

pull/5/head
Miguel Mota 6 years ago
parent 8dd89487d0
commit ca7bb5111f

@ -51,31 +51,39 @@ $ cointop
List of shortcuts:
Key|Action
----|------
----|------|
<kbd></kbd>|navigate up
<kbd></kbd>|navigate down
<kbd></kbd>|next page
<kbd></kbd>|previous page
<kbd>Page Up</kbd>|page up
<kbd>Page Down</kbd>|page down
<kbd>Home</kbd>|navigate to first line of page
<kbd>End</kbd>|navigate to last line of page
<kbd>Enter</kbd>|visit highlighted coin on CoinMarketCap
<kbd>Esc</kbd>|alias to quit
<kbd>Space</kbd>|alias to enter key
<kbd>Ctrl</kbd>+<kbd>c</kbd>|alias to quit
<kbd>Ctrl</kbd>+<kbd>d</kbd>|page down
<kbd>Ctrl</kbd>+<kbd>n</kbd>|alias to next page
<kbd>Ctrl</kbd>+<kbd>p</kbd>|alias to previous page
<kbd>Ctrl</kbd>+<kbd>d</kbd>|page down (vim style)
<kbd>Ctrl</kbd>+<kbd>n</kbd>|next page (vim style)
<kbd>Ctrl</kbd>+<kbd>p</kbd>|previous page (vim style)
<kbd>Ctrl</kbd>+<kbd>r</kbd>|force refresh
<kbd>Ctrl</kbd>+<kbd>u</kbd>|page up
<kbd>Ctrl</kbd>+<kbd>u</kbd>|page up (vim style)
<kbd>0</kbd>|navigate to first page (vim style)
<kbd>1</kbd>|sort by *[1] hour change*
<kbd>2</kbd>|sort by *[2]4 hour change*
<kbd>7</kbd>|sort by *[7] day change*
<kbd>a</kbd>|sort by *[a]vailable supply*
<kbd>g</kbd>|navigate to first line
<kbd>G</kbd>|navigate to last line
<kbd>h</kbd>|alias to previous page
<kbd>j</kbd>|alias to navigate down
<kbd>k</kbd>|alias to navigate up
<kbd>l</kbd>|alias to next page
<kbd>g</kbd>|navigate to first line of page (vim style)
<kbd>G</kbd>|navigate to last line of page (vim style)
<kbd>h</kbd>|previous page (vim style)
<kbd>H</kbd>|navigate to top of table window (vim style)
<kbd>j</kbd>|navigate down (vim style)
<kbd>k</kbd>|navigate up (vim style)
<kbd>l</kbd>|next page (vim style)
<kbd>L</kbd>|navigate to last line of table window (vim style)
<kbd>m</kbd>|sort by *[m]arket cap*
<kbd>M</kbd>|navigate to middle of table window (vim style)
<kbd>n</kbd>|sort by *[n]ame*
<kbd>p</kbd>|sort by *[p]rice*
<kbd>r</kbd>|sort by *[r]ank*
@ -84,6 +92,7 @@ Key|Action
<kbd>u</kbd>|sort by *last [u]pdated*
<kbd>v</kbd>|sort by *24 hour [v]olume*
<kbd>q</kbd>|[q]uit
<kbd>$</kbd>|navigate to last page (vim style)
<!--
|`h`|toggle [h]elp|

@ -25,6 +25,10 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
ct.setKeybinding(gocui.KeyArrowDown, ct.cursorDown)
ct.setKeybinding(gocui.KeyArrowLeft, ct.prevPage)
ct.setKeybinding(gocui.KeyArrowRight, ct.nextPage)
ct.setKeybinding(gocui.KeyPgdn, ct.pageUp)
ct.setKeybinding(gocui.KeyPgup, ct.pageUp)
ct.setKeybinding(gocui.KeyHome, ct.navigateFirstLine)
ct.setKeybinding(gocui.KeyEnd, ct.navigateLastLine)
ct.setKeybinding(gocui.KeyEnter, ct.enter)
ct.setKeybinding(gocui.KeyEsc, ct.quit)
ct.setKeybinding(gocui.KeySpace, ct.enter)
@ -34,6 +38,7 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
ct.setKeybinding(gocui.KeyCtrlP, ct.prevPage)
ct.setKeybinding(gocui.KeyCtrlR, ct.refresh)
ct.setKeybinding(gocui.KeyCtrlU, ct.pageUp)
ct.setKeybinding('0', ct.firstPage)
ct.setKeybinding('1', ct.sortfn("1hchange", true))
ct.setKeybinding('2', ct.sortfn("24hchange", true))
ct.setKeybinding('7', ct.sortfn("7dchange", true))
@ -41,10 +46,13 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
ct.setKeybinding('g', ct.navigateFirstLine)
ct.setKeybinding('G', ct.navigateLastLine)
ct.setKeybinding('h', ct.prevPage)
ct.setKeybinding('H', ct.navigatePageFirstLine)
ct.setKeybinding('j', ct.cursorDown)
ct.setKeybinding('k', ct.cursorUp)
ct.setKeybinding('l', ct.nextPage)
ct.setKeybinding('L', ct.navigatePageLastLine)
ct.setKeybinding('m', ct.sortfn("marketcap", true))
ct.setKeybinding('M', ct.navigatePageMiddleLine)
ct.setKeybinding('n', ct.sortfn("name", true))
ct.setKeybinding('p', ct.sortfn("price", true))
ct.setKeybinding('r', ct.sortfn("rank", false))
@ -53,6 +61,7 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
ct.setKeybinding('u', ct.sortfn("lastupdated", true))
ct.setKeybinding('v', ct.sortfn("24hvolume", true))
ct.setKeybinding('q', ct.quit)
ct.setKeybinding('$', ct.lastPage)
return nil
}

@ -126,6 +126,44 @@ func (ct *Cointop) navigateLastLine(g *gocui.Gui, v *gocui.View) error {
return nil
}
func (ct *Cointop) navigatePageFirstLine(g *gocui.Gui, v *gocui.View) error {
if ct.tableview == nil {
return nil
}
cx, _ := ct.tableview.Cursor()
if err := ct.tableview.SetCursor(cx, 0); err != nil {
return err
}
ct.rowChanged()
return nil
}
func (ct *Cointop) navigatePageMiddleLine(g *gocui.Gui, v *gocui.View) error {
if ct.tableview == nil {
return nil
}
cx, _ := ct.tableview.Cursor()
_, sy := ct.tableview.Size()
if err := ct.tableview.SetCursor(cx, (sy/2)-1); err != nil {
return err
}
ct.rowChanged()
return nil
}
func (ct *Cointop) navigatePageLastLine(g *gocui.Gui, v *gocui.View) error {
if ct.tableview == nil {
return nil
}
cx, _ := ct.tableview.Cursor()
_, sy := ct.tableview.Size()
if err := ct.tableview.SetCursor(cx, sy-1); err != nil {
return err
}
ct.rowChanged()
return nil
}
func (ct *Cointop) prevPage(g *gocui.Gui, v *gocui.View) error {
if (ct.page - 1) >= 0 {
ct.page = ct.page - 1
@ -143,3 +181,17 @@ func (ct *Cointop) nextPage(g *gocui.Gui, v *gocui.View) error {
ct.rowChanged()
return nil
}
func (ct *Cointop) firstPage(g *gocui.Gui, v *gocui.View) error {
ct.page = 0
ct.updateTable()
ct.rowChanged()
return nil
}
func (ct *Cointop) lastPage(g *gocui.Gui, v *gocui.View) error {
ct.page = len(ct.allcoins) / ct.perpage
ct.updateTable()
ct.rowChanged()
return nil
}

Loading…
Cancel
Save