|
|
|
@ -167,17 +167,16 @@ func (ct *Cointop) ParseKeys(s string) (interface{}, gocui.Modifier) {
|
|
|
|
|
return key, mod
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keybindings sets keyboard shortcut key bindings
|
|
|
|
|
func (ct *Cointop) Keybindings(g *gocui.Gui) error {
|
|
|
|
|
for k, v := range ct.State.shortcutKeys {
|
|
|
|
|
if k == "" {
|
|
|
|
|
continue
|
|
|
|
|
// SetKeybindingAction maps a shortcut key to an action
|
|
|
|
|
func (ct *Cointop) SetKeybindingAction(shortcutKey string, action string) error {
|
|
|
|
|
if shortcutKey == "" {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
v = strings.TrimSpace(strings.ToLower(v))
|
|
|
|
|
action = strings.TrimSpace(strings.ToLower(action))
|
|
|
|
|
var fn func(g *gocui.Gui, v *gocui.View) error
|
|
|
|
|
key, mod := ct.ParseKeys(k)
|
|
|
|
|
key, mod := ct.ParseKeys(shortcutKey)
|
|
|
|
|
view := "table"
|
|
|
|
|
switch v {
|
|
|
|
|
switch action {
|
|
|
|
|
case "move_up":
|
|
|
|
|
fn = ct.Keyfn(ct.CursorUp)
|
|
|
|
|
case "move_down":
|
|
|
|
@ -327,6 +326,15 @@ func (ct *Cointop) Keybindings(g *gocui.Gui) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct.SetKeybindingMod(key, mod, fn, view)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetKeybindings sets keyboard shortcut key bindings
|
|
|
|
|
func (ct *Cointop) SetKeybindings() error {
|
|
|
|
|
for k, v := range ct.State.shortcutKeys {
|
|
|
|
|
if err := ct.SetKeybindingAction(k, v); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// keys to force quit
|
|
|
|
@ -352,6 +360,9 @@ func (ct *Cointop) Keybindings(g *gocui.Gui) error {
|
|
|
|
|
// keys to update portfolio holdings
|
|
|
|
|
ct.SetKeybindingMod(gocui.KeyEnter, gocui.ModNone, ct.Keyfn(ct.EnterKeyPressHandler), ct.Views.Input.Name())
|
|
|
|
|
|
|
|
|
|
key, mod := ct.ParseKeys("/")
|
|
|
|
|
ct.DeleteKeybindingMod(key, mod, "")
|
|
|
|
|
|
|
|
|
|
// mouse events
|
|
|
|
|
ct.SetKeybindingMod(gocui.MouseRelease, gocui.ModNone, ct.Keyfn(ct.MouseRelease), "")
|
|
|
|
|
ct.SetKeybindingMod(gocui.MouseLeft, gocui.ModNone, ct.Keyfn(ct.MouseLeftClick), "")
|
|
|
|
@ -382,11 +393,32 @@ func (ct *Cointop) SetKeybindingMod(key interface{}, mod gocui.Modifier, callbac
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteKeybinding ...
|
|
|
|
|
func (ct *Cointop) DeleteKeybinding(shortcutKey string) error {
|
|
|
|
|
key, mod := ct.ParseKeys(shortcutKey)
|
|
|
|
|
return ct.DeleteKeybindingMod(key, mod, "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeleteKeybindingMod ...
|
|
|
|
|
func (ct *Cointop) DeleteKeybindingMod(key interface{}, mod gocui.Modifier, view string) error {
|
|
|
|
|
var err error
|
|
|
|
|
switch t := key.(type) {
|
|
|
|
|
case gocui.Key:
|
|
|
|
|
err = ct.g.DeleteKeybinding(view, t, mod)
|
|
|
|
|
case rune:
|
|
|
|
|
err = ct.g.DeleteKeybinding(view, t, mod)
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keyfn returns the keybinding function as a wrapped gocui view function
|
|
|
|
|
func (ct *Cointop) Keyfn(fn func() error) func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
return func(g *gocui.Gui, v *gocui.View) error {
|
|
|
|
|
if fn != nil {
|
|
|
|
|
return fn()
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleHkey handles the h key
|
|
|
|
|