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() {
screen := new(mop.Screen).Initialize()
screen := mop.NewScreen()
defer screen.Close()
profile := new(mop.Profile).Initialize()
profile := mop.NewProfile()
mainLoop(screen, profile)
}

@ -27,9 +27,10 @@ type Profile struct {
selectedColumn int // Stores selected column number when the column editor is active.
}
// Initialize attempts to load the settings from ~/.moprc file. If the
// file is not there it gets created with the default values.
func (profile *Profile) Initialize() *Profile {
// Creates the profile and attempts to load the settings from ~/.moprc file.
// If the file is not there it gets created with default values.
func NewProfile() *Profile {
profile := &Profile{}
data, err := ioutil.ReadFile(profile.defaultFileName())
if err != nil { // Set default values:
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.
}
// Initialize loads the Termbox, allocates and initializes layout and markup,
// and calculates current screen dimensions. Once initialized the screen is
// Initializes Termbox, creates screen along with layout and markup, and
// calculates current screen dimensions. Once initialized the screen is
// ready for display.
func (screen *Screen) Initialize() *Screen {
func NewScreen() *Screen {
if err := termbox.Init(); err != nil {
panic(err)
}
screen.layout = new(Layout).Initialize()
screen.markup = new(Markup).Initialize()
screen := &Screen{}
screen.layout = NewLayout()
screen.markup = NewMarkup()
return screen.Resize()
}

Loading…
Cancel
Save