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

91 lines
2.0 KiB
Go

package cointop
import (
"fmt"
"sort"
5 years ago
"github.com/miguelmota/cointop/cointop/common/pad"
)
func (ct *Cointop) updateHelp() {
5 years ago
keys := make([]string, 0, len(ct.State.shortcutKeys))
for k := range ct.State.shortcutKeys {
keys = append(keys, k)
}
sort.Strings(keys)
5 years ago
header := ct.colorscheme.MenuHeader(fmt.Sprintf(" Help %s\n\n", pad.Left("[q] close ", ct.maxTableWidth-10, " ")))
cnt := 0
5 years ago
h := ct.viewHeight(ct.Views.Help.Name)
percol := h - 6
cols := make([][]string, percol)
for i := range cols {
cols[i] = make([]string, 20)
}
for _, k := range keys {
5 years ago
v := ct.State.shortcutKeys[k]
if cnt%percol == 0 {
cnt = 0
}
5 years ago
item := fmt.Sprintf("%10s %-40s", k, ct.colorscheme.MenuLabel(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)
}
body = fmt.Sprintf("%s\n", body)
infoline := " List of keyboard shortcuts\n\n"
5 years ago
versionline := pad.Left(fmt.Sprintf("v%s", ct.version()), ct.maxTableWidth-5, " ")
content := header + infoline + body + versionline
ct.update(func() {
5 years ago
if ct.Views.Help.Backing == nil {
return
}
5 years ago
ct.Views.Help.Backing.Clear()
ct.Views.Help.Backing.Frame = true
fmt.Fprintln(ct.Views.Help.Backing, content)
})
}
func (ct *Cointop) showHelp() error {
5 years ago
ct.State.helpVisible = true
ct.updateHelp()
5 years ago
ct.setActiveView(ct.Views.Help.Name)
return nil
}
func (ct *Cointop) hideHelp() error {
5 years ago
ct.State.helpVisible = false
ct.setViewOnBottom(ct.Views.Help.Name)
ct.setActiveView(ct.Views.Table.Name)
ct.update(func() {
5 years ago
if ct.Views.Help.Backing == nil {
return
}
5 years ago
ct.Views.Help.Backing.Clear()
ct.Views.Help.Backing.Frame = false
fmt.Fprintln(ct.Views.Help.Backing, "")
})
return nil
}
5 years ago
func (ct *Cointop) toggleHelp() error {
ct.State.helpVisible = !ct.State.helpVisible
if ct.State.helpVisible {
return ct.showHelp()
}
return ct.hideHelp()
}