You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cointop/cointop/help.go

81 lines
1.6 KiB
Go

package cointop
import (
"fmt"
"sort"
"github.com/miguelmota/cointop/pkg/color"
"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() {
keys := make([]string, 0, len(ct.shortcutkeys))
for k := range ct.shortcutkeys {
keys = append(keys, k)
}
sort.Strings(keys)
header := color.GreenBg(fmt.Sprintf(" Help %s\n\n", pad.Left("[q] close help ", ct.maxtablewidth-10, " ")))
cnt := 0
h := ct.viewHeight("help")
percol := h - 3
cols := make([][]string, percol)
for i := range cols {
cols[i] = make([]string, 20)
}
for _, k := range keys {
v := ct.shortcutkeys[k]
if cnt%percol == 0 {
cnt = 0
}
item := fmt.Sprintf("%10s %-40s", k, color.Yellow(v))
cols[cnt] = append(cols[cnt], item)
cnt = cnt + 1
}
var body string
for i := 0; i < percol; i++ {
var row string
for j := 0; j < len(cols[i]); j++ {
item := cols[i][j]
row = fmt.Sprintf("%s%s", row, item)
}
body = fmt.Sprintf("%s%s\n", body, row)
}
content := fmt.Sprintf("%s%s", header, body)
ct.update(func() {
ct.helpview.Clear()
ct.helpview.Frame = true
fmt.Fprintln(ct.helpview, content)
})
}
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")
6 years ago
ct.setActiveView("table")
ct.update(func() {
ct.helpview.Clear()
ct.helpview.Frame = false
fmt.Fprintln(ct.helpview, "")
})
return nil
}