/
view.go
83 lines (70 loc) · 1.73 KB
/
view.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package cointop
import (
"fmt"
"github.com/miguelmota/gocui"
)
// IView is a cointop view
type IView interface {
Backing() *gocui.View
SetBacking(gocuiView *gocui.View)
Name() string
}
// View is a cointop view
type View struct {
backing *gocui.View
name string
}
// NewView creates a new view
func NewView(name string) *View {
return &View{
name: name,
}
}
// Backing returns the backing gocui view
func (view *View) Backing() *gocui.View {
return view.backing
}
// SetBacking sets the backing gocui view
func (view *View) SetBacking(gocuiView *gocui.View) {
view.backing = gocuiView
}
// Height returns the view height
func (view *View) Height() int {
_, h := view.backing.Size()
return h
}
// Width returns the view width
func (view *View) Width() int {
w, _ := view.backing.Size()
return w
}
// Name returns the view's name
func (view *View) Name() string {
return view.name
}
// SetActiveView sets the active view
func (ct *Cointop) SetActiveView(v string) error {
ct.g.SetViewOnTop(v)
ct.g.SetCurrentView(v)
if v == ct.Views.SearchField.Name() {
ct.Views.SearchField.Backing().Clear()
ct.Views.SearchField.Backing().SetCursor(1, 0)
fmt.Fprintf(ct.Views.SearchField.Backing(), "%s", "/")
} else if v == ct.Views.Table.Name() {
ct.g.SetViewOnTop(ct.Views.Statusbar.Name())
}
if v == ct.Views.PortfolioUpdateMenu.Name() {
ct.g.SetViewOnTop(ct.Views.Input.Name())
ct.g.SetCurrentView(ct.Views.Input.Name())
}
return nil
}
// ActiveViewName returns the name of the active view
func (ct *Cointop) ActiveViewName() string {
return ct.g.CurrentView().Name()
}
// SetViewOnBottom sets the view to the bottom layer
func (ct *Cointop) SetViewOnBottom(v string) error {
_, err := ct.g.SetViewOnBottom(v)
return err
}