Add mouse support for currency conversion screen

pull/224/head
Simon Roberts 3 years ago
parent 3a51cb51a4
commit bc69753e4e
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -3,6 +3,7 @@ package cointop
import (
"errors"
"fmt"
"regexp"
"sort"
"strings"
@ -301,3 +302,23 @@ func CurrencySymbol(currency string) string {
return "?"
}
// StatusbarMouseLeftClick is called on mouse left click event
func (ct *Cointop) ConversionMouseLeftClick() error {
v, x, y, err := ct.g.GetViewRelativeMousePosition(ct.g.CurrentEvent)
if err != nil {
return err
}
// Find the menu entry that includes the mouse position
line := v.BufferLines()[y]
matches := regexp.MustCompile(`\[ . \] \w+ [^\[]+`).FindAllStringIndex(line, -1)
for _, match := range matches {
if x >= match[0] && x <= match[1] {
s := line[match[0]:match[1]]
convert := strings.Split(s, " ")[3]
return ct.SetCurrencyConverstionFn(convert)()
}
}
return nil
}

@ -392,7 +392,7 @@ func (ct *Cointop) SetKeybindings() error {
for i, k := range keys {
ct.SetKeybindingMod(alphanumericcharacters[i], gocui.ModNone, ct.Keyfn(ct.SetCurrencyConverstionFn(k)), ct.Views.Menu.Name())
}
ct.SetKeybindingMod(gocui.MouseLeft, gocui.ModNone, ct.Keyfn(ct.ConversionMouseLeftClick), ct.Views.Menu.Name())
return nil
}
@ -403,7 +403,7 @@ func (ct *Cointop) MouseDebug() error {
if err != nil {
return err
}
log.Debugf("XXX MouseLeftClick view=%s %d,%d", v.Name(), x, y)
log.Debugf("XXX MouseDebug view=%s %d,%d", v.Name(), x, y)
return nil
}

Loading…
Cancel
Save