Refactored for more idiomatic Go

master
Michael Dvorkin 10 years ago
parent db2419638a
commit b9050272ed
  1. 4
      cmd/mop.go
  2. 7
      profile.go
  3. 11
      screen.go

@ -116,9 +116,9 @@ loop:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func main() { func main() {
screen := new(mop.Screen).Initialize() screen := mop.NewScreen()
defer screen.Close() defer screen.Close()
profile := new(mop.Profile).Initialize() profile := mop.NewProfile()
mainLoop(screen, profile) mainLoop(screen, profile)
} }

@ -27,9 +27,10 @@ type Profile struct {
selectedColumn int // Stores selected column number when the column editor is active. selectedColumn int // Stores selected column number when the column editor is active.
} }
// Initialize attempts to load the settings from ~/.moprc file. If the // Creates the profile and attempts to load the settings from ~/.moprc file.
// file is not there it gets created with the default values. // If the file is not there it gets created with default values.
func (profile *Profile) Initialize() *Profile { func NewProfile() *Profile {
profile := &Profile{}
data, err := ioutil.ReadFile(profile.defaultFileName()) data, err := ioutil.ReadFile(profile.defaultFileName())
if err != nil { // Set default values: if err != nil { // Set default values:
profile.MarketRefresh = 12 // Market data gets fetched every 12s (5 times per minute). profile.MarketRefresh = 12 // Market data gets fetched every 12s (5 times per minute).

@ -21,15 +21,16 @@ type Screen struct {
pausedAt *time.Time // Timestamp of the pause request or nil if none. pausedAt *time.Time // Timestamp of the pause request or nil if none.
} }
// Initialize loads the Termbox, allocates and initializes layout and markup, // Initializes Termbox, creates screen along with layout and markup, and
// and calculates current screen dimensions. Once initialized the screen is // calculates current screen dimensions. Once initialized the screen is
// ready for display. // ready for display.
func (screen *Screen) Initialize() *Screen { func NewScreen() *Screen {
if err := termbox.Init(); err != nil { if err := termbox.Init(); err != nil {
panic(err) panic(err)
} }
screen.layout = new(Layout).Initialize() screen := &Screen{}
screen.markup = new(Markup).Initialize() screen.layout = NewLayout()
screen.markup = NewMarkup()
return screen.Resize() return screen.Resize()
} }

Loading…
Cancel
Save