add moar comments
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
624c286650
commit
3655f5605b
2
keys.go
2
keys.go
|
@ -11,11 +11,13 @@ type Binding struct {
|
|||
}
|
||||
|
||||
func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error {
|
||||
// TODO propper error handling?
|
||||
vc.State.SetCurrent(vc.State.GetState().Current - 1)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error {
|
||||
// TODO propper error handling?
|
||||
vc.State.SetCurrent(vc.State.GetState().Current + 1)
|
||||
return nil
|
||||
}
|
||||
|
|
5
main.go
5
main.go
|
@ -16,6 +16,7 @@ const interval = 5
|
|||
|
||||
var threadDone = make(chan struct{})
|
||||
|
||||
// TODO Add command line options
|
||||
func main() {
|
||||
// Custom location for log messages
|
||||
clientLogFile, err := os.OpenFile("./app.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||
|
@ -38,8 +39,9 @@ func main() {
|
|||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Create a state wrapper.
|
||||
state := NewState(client)
|
||||
// Subscribe rendering method to state changes
|
||||
// Subscribe rendering method to state changes.
|
||||
state.Store.Subscribe(GenRenderFunc(g, state))
|
||||
|
||||
mainView := &ViewController{
|
||||
|
@ -78,6 +80,7 @@ func main() {
|
|||
TopLeft: func(mx, my int) (int, int) { return 0, (my / 2) + 1 },
|
||||
BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 },
|
||||
}
|
||||
// TODO Create a prompt view for user convirmations.
|
||||
|
||||
views := []*ViewController{mainView, infoView}
|
||||
|
||||
|
|
1
model.go
1
model.go
|
@ -15,6 +15,7 @@ type Model struct {
|
|||
}
|
||||
|
||||
func (m *Model) Current(state PeersState, peerIndex int) PeersState {
|
||||
// NOTE Not sure if I should just ignore invalid values or panic
|
||||
if peerIndex < 0 || peerIndex >= len(state.Peers) {
|
||||
return state
|
||||
}
|
||||
|
|
19
state.go
19
state.go
|
@ -8,6 +8,8 @@ import (
|
|||
"github.com/dannypsnl/redux/store"
|
||||
)
|
||||
|
||||
// This might need renaming, since it also contains the Client.
|
||||
// I need the client to make the RPC calls.
|
||||
type State struct {
|
||||
Reducer *Model
|
||||
Store *store.Store
|
||||
|
@ -17,27 +19,27 @@ type State struct {
|
|||
}
|
||||
|
||||
func NewState(client *StatusGoClient) *State {
|
||||
// Generate the reducer from our model
|
||||
// Generate the reducer from our model.
|
||||
Reducer := &Model{
|
||||
State: PeersState{
|
||||
Peers: make([]Peer, 0),
|
||||
Current: -1, // start with first
|
||||
Current: -1, // Should mean non selected.
|
||||
},
|
||||
}
|
||||
// Instantiate the redux state from the reducer
|
||||
// Instantiate the redux state from the reducer.
|
||||
return &State{
|
||||
Reducer: Reducer,
|
||||
// Define the store
|
||||
// Define the store.
|
||||
Store: store.New(Reducer),
|
||||
// Client for RPC calls
|
||||
// Client for RPC calls.
|
||||
Client: client,
|
||||
// Define available reducers for the store
|
||||
// Define available reducers for the store.
|
||||
updatePeers: Reducer.Action(Reducer.Update),
|
||||
setCurrent: Reducer.Action(Reducer.Current),
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers for shorter calls
|
||||
// Helpers for shorter calls.
|
||||
func (s *State) Update(peers []Peer) {
|
||||
s.Store.Dispatch(s.updatePeers.With(peers))
|
||||
}
|
||||
|
@ -54,6 +56,8 @@ func (s *State) SetCurrent(index int) {
|
|||
func (s *State) GetState() PeersState {
|
||||
return s.Store.StateOf(s.Reducer).(PeersState)
|
||||
}
|
||||
|
||||
// For fetching current state of peers from status-go
|
||||
func (s *State) Fetch() {
|
||||
peers, err := s.Client.getPeers()
|
||||
if err != nil {
|
||||
|
@ -66,6 +70,7 @@ func (s *State) Fetch() {
|
|||
}
|
||||
}
|
||||
|
||||
// For removing a selected peer from connected to status-go
|
||||
func (s *State) Remove(peer *Peer) error {
|
||||
success, err := s.Client.removePeer(peer.Enode)
|
||||
if err != nil || success != true {
|
||||
|
|
5
view.go
5
view.go
|
@ -7,6 +7,8 @@ import (
|
|||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
||||
// Default Gocui views arent granular enough
|
||||
// so I'm adding a custom one to have more control.
|
||||
type ViewController struct {
|
||||
Name string
|
||||
Title string
|
||||
|
@ -22,10 +24,11 @@ type ViewController struct {
|
|||
SelBgColor gocui.Attribute
|
||||
SelFgColor gocui.Attribute
|
||||
Keybindings []Binding
|
||||
// extra field for view state
|
||||
// Extra field for view state. Might need different name.
|
||||
State *State
|
||||
}
|
||||
|
||||
// To combine all existing views into one
|
||||
type ViewManager struct {
|
||||
g *gocui.Gui
|
||||
views []*ViewController
|
||||
|
|
Loading…
Reference in New Issue