2
0
mirror of https://github.com/edouardparis/lntop synced 2024-11-16 00:12:44 +00:00
lntop/ui/views/help.go

107 lines
1.9 KiB
Go
Raw Normal View History

2019-04-01 16:30:25 +00:00
package views
import (
"fmt"
"github.com/jroimartin/gocui"
2019-04-02 08:14:39 +00:00
"github.com/edouardparis/lntop/ui/color"
2019-04-01 16:30:25 +00:00
)
const (
HELP = "help"
)
2019-04-02 08:14:39 +00:00
type Help struct {
2019-04-10 07:44:52 +00:00
view *gocui.View
2019-04-02 08:14:39 +00:00
}
func (h Help) Name() string {
return HELP
}
2019-04-10 07:44:52 +00:00
func (h *Help) Wrap(v *gocui.View) view {
h.view = v
return h
}
2019-04-10 11:16:51 +00:00
func (h *Help) CursorDown() error {
if h.view != nil {
cx, cy := h.view.Cursor()
err := h.view.SetCursor(cx, cy+1)
if err != nil {
ox, oy := h.view.Origin()
err := h.view.SetOrigin(ox, oy+1)
if err != nil {
return err
}
}
}
return nil
}
func (h *Help) CursorUp() error {
if h.view != nil {
ox, oy := h.view.Origin()
cx, cy := h.view.Cursor()
err := h.view.SetCursor(cx, cy-1)
if err != nil && oy > 0 {
err := h.view.SetOrigin(ox, oy-1)
if err != nil {
return err
}
}
}
return nil
}
func (h *Help) CursorRight() error {
if h.view != nil {
cx, cy := h.view.Cursor()
err := h.view.SetCursor(cx+2, cy)
if err != nil {
ox, oy := h.view.Origin()
err := h.view.SetOrigin(ox+2, oy)
if err != nil {
return err
}
}
}
return nil
}
func (h *Help) CursorLeft() error {
if h.view != nil {
ox, oy := h.view.Origin()
cx, cy := h.view.Cursor()
err := h.view.SetCursor(cx-2, cy)
if err != nil && ox > 1 {
err := h.view.SetOrigin(ox-2, oy)
if err != nil {
return err
}
}
}
return nil
}
2019-04-02 08:14:39 +00:00
func (h Help) Set(g *gocui.Gui, x0, y0, x1, y1 int) error {
2019-04-10 07:44:52 +00:00
var err error
h.view, err = g.SetView(HELP, x0-1, y0, x1, y1)
2019-04-01 16:30:25 +00:00
if err != nil {
if err != gocui.ErrUnknownView {
return err
}
}
2019-04-10 07:44:52 +00:00
h.view.Frame = false
fmt.Fprintln(h.view, "lntop 0.0.1 - (C) 2019 Edouard Paris")
fmt.Fprintln(h.view, "Released under the MIT License")
fmt.Fprintln(h.view, "")
fmt.Fprintln(h.view, fmt.Sprintf("%5s %s",
2019-04-02 08:14:39 +00:00
color.Cyan("F1 h:"), "show this help screen"))
2019-04-01 16:30:25 +00:00
_, err = g.SetCurrentView(HELP)
return err
}
2019-04-02 08:14:39 +00:00
func NewHelp() *Help { return &Help{} }