toggle help menu

Former-commit-id: d9aad64fd3087c6789de73a7946a16caad9c7fc2 [formerly d9aad64fd3087c6789de73a7946a16caad9c7fc2 [formerly 0fd056c846092e8310cab5dd042e927e8fca74d6 [formerly b3f6d2ec560622cede5c81658302154814f02d9b]]]
Former-commit-id: f4da4cdd33244f486f2e29355a20c0b011718518
Former-commit-id: 31cc38d2450cbef3401a1183b1b0519d0043a9de [formerly f8ecf5b286c93e0672058008c9a9651919107633]
Former-commit-id: 526df3564e2949dfb4d16f36736fa32a5ef95919
pull/15/head
Miguel Mota 6 years ago
parent 9f7977a065
commit 7b5b39a9e7

@ -4,6 +4,8 @@ func actionsMap() map[string]bool {
return map[string]bool{
"first_page": true,
"help": true,
"toggle_show_help": true,
"close_help": true,
"last_page": true,
"move_to_page_first_row": true,
"move_to_page_last_row": true,

@ -46,6 +46,7 @@ type Cointop struct {
cache *cache.Cache
debug bool
helpview *gocui.View
helpvisible bool
}
// Run runs cointop
@ -109,5 +110,13 @@ func Run() {
}
func (ct *Cointop) quit() error {
if ct.helpvisible {
return nil
}
return ct.forceQuit()
}
func (ct *Cointop) forceQuit() error {
return gocui.ErrQuit
}

@ -1,6 +1,53 @@
package cointop
func (ct *Cointop) openHelp() error {
import (
"fmt"
"github.com/miguelmota/cointop/pkg/pad"
)
func (ct *Cointop) toggleHelp() error {
ct.helpvisible = !ct.helpvisible
if ct.helpvisible {
return ct.showHelp()
}
return ct.hideHelp()
}
func (ct *Cointop) updateHelp() {
str := fmt.Sprintf(" Help %s\n\n", pad.Left("[x] exit", ct.maxtablewidth-11, " "))
i := 0
for k, v := range ct.shortcutkeys {
nl := " "
i = i + 1
if i%3 == 0 {
i = 0
nl = "\n"
}
str = fmt.Sprintf("%s%10s %-40s%s", str, fmt.Sprintf("[%s]", k), v, nl)
}
ct.update(func() {
ct.helpview.Clear()
ct.helpview.Frame = true
fmt.Fprintln(ct.helpview, str)
})
}
func (ct *Cointop) showHelp() error {
ct.helpvisible = true
ct.updateHelp()
ct.setActiveView("help")
return nil
}
func (ct *Cointop) hideHelp() error {
ct.helpvisible = false
ct.setViewOnBottom("help")
ct.update(func() {
ct.helpview.Clear()
ct.helpview.Frame = false
fmt.Fprintln(ct.helpview, "")
})
return nil
}

@ -225,8 +225,13 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
case "sort_right_column":
fn = ct.keyfn(ct.sortNextCol)
case "help":
fn = ct.keyfn(ct.openHelp)
fallthrough
case "toggle_show_help":
fn = ct.keyfn(ct.toggleHelp)
view = ""
case "hide_help":
fn = ct.keyfn(ct.hideHelp)
view = "help"
case "first_page":
fn = ct.keyfn(ct.firstPage)
case "sort_column_1h_change":
@ -280,8 +285,18 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error {
ct.setKeybindingMod(key, mod, fn, view)
}
// keys to force quit
ct.setKeybindingMod(gocui.KeyCtrlC, gocui.ModNone, ct.keyfn(ct.forceQuit), "")
ct.setKeybindingMod(gocui.KeyCtrlZ, gocui.ModNone, ct.keyfn(ct.forceQuit), "")
// searchfield keys
ct.setKeybindingMod(gocui.KeyEnter, gocui.ModNone, ct.keyfn(ct.doSearch), "searchfield")
ct.setKeybindingMod(gocui.KeyEsc, gocui.ModNone, ct.keyfn(ct.cancelSearch), "searchfield")
// keys to quit help when open
ct.setKeybindingMod(gocui.KeyEsc, gocui.ModNone, ct.keyfn(ct.hideHelp), "help")
ct.setKeybindingMod('q', gocui.ModNone, ct.keyfn(ct.hideHelp), "help")
ct.setKeybindingMod('x', gocui.ModNone, ct.keyfn(ct.hideHelp), "help")
return nil
}

@ -80,20 +80,12 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.searchfield.FgColor = gocui.ColorWhite
}
helpwidth := 50
helpheight := 25
tablewidth := 182
helpX := (tablewidth / 2) - (helpwidth / 2)
helpY := topOffset + 2
if helpX <= 0 {
helpX = 5
}
if v, err := g.SetView("help", helpX, helpY, helpX+helpwidth, helpY+helpheight); err != nil {
if v, err := g.SetView("help", 1, 1, ct.maxtablewidth-2, maxY-2); err != nil {
if err != gocui.ErrUnknownView {
return err
}
ct.helpview = v
ct.helpview.Frame = true
ct.helpview.Frame = false
ct.helpview.BgColor = gocui.ColorBlack
ct.helpview.FgColor = gocui.ColorWhite
@ -122,6 +114,11 @@ func (ct *Cointop) setActiveView(v string) error {
return nil
}
func (ct *Cointop) setViewOnBottom(v string) error {
_, err := ct.g.SetViewOnBottom(v)
return err
}
func (ct *Cointop) intervalFetchData() {
go func() {
for {

Loading…
Cancel
Save