adjustments
authorSimon J Mudd <sjmudd@pobox.com>
Mon, 5 Jan 2015 08:41:33 +0000 (09:41 +0100)
committerSimon J Mudd <sjmudd@pobox.com>
Mon, 5 Jan 2015 08:41:33 +0000 (09:41 +0100)
main.go
state/state.go

diff --git a/main.go b/main.go
index 94c0036..c7de87b 100644 (file)
--- a/main.go
+++ b/main.go
@@ -233,13 +233,11 @@ func main() {
        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
 
        state.Setup(dbh)
-
-       finished := false
-       for !finished {
+       for !state.Finished() {
                select {
                case <-done:
                        fmt.Println("exiting")
-                       finished = true
+                       state.SetFinished()
                case sig := <-sigChan:
                        fmt.Println("Caught a signal", sig)
                        done <- struct{}{}
@@ -253,7 +251,7 @@ func main() {
                        case termbox.EventKey: // actions depend on key
                                switch event.Key {
                                case termbox.KeyCtrlZ, termbox.KeyCtrlC, termbox.KeyEsc:
-                                       finished = true
+                                       state.SetFinished()
                                case termbox.KeyArrowLeft: // left arrow change to previous display mode
                                        state.DisplayPrevious()
                                        state.Display()
@@ -271,7 +269,7 @@ func main() {
                                case 'h', '?': // help
                                        state.SetHelp(!state.Help())
                                case 'q': // quit
-                                       finished = true
+                                       state.SetFinished()
                                case 't': // toggle between absolute/relative statistics
                                        state.SetWantRelativeStats(!state.WantRelativeStats())
                                        state.Display()
index 124b884..8f56b4d 100644 (file)
@@ -31,6 +31,7 @@ const (
 )
 
 type State struct {
+       finished            bool
        datadir             string
        dbh                 *sql.DB
        help                bool
@@ -47,6 +48,7 @@ type State struct {
 
 func (state *State) Setup(dbh *sql.DB) {
        state.dbh = dbh
+       state.finished = false
 
        state.screen.Initialise()
 
@@ -83,6 +85,16 @@ func (state *State) Setup(dbh *sql.DB) {
        state.SetDatadir(datadir)
 }
 
+// have we finished ?
+func (state State) Finished() bool {
+       return state.finished
+}
+
+// indicate we have finished
+func (state *State) SetFinished() {
+       state.finished = true
+}
+
 // do a fresh collection of data and then update the initial values based on that.
 func (state *State) ResetDBStatistics() {
        state.CollectAll()