Minor simplification

master
Michael Dvorkin 11 years ago
parent cef05232a6
commit d20bd3e822
  1. 2
      lib/format.go
  2. 6
      lib/screen.go
  3. 3
      mop.go

@ -149,7 +149,7 @@ func last_of_pair(str string) string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func with_currency(str string) string { func with_currency(str string) string {
if str == `N/A` || str == `0.00` { if str == `N/A` {
return `-` return `-`
} else { } else {
switch str[0:1] { switch str[0:1] {

@ -13,6 +13,7 @@ import (
type Screen struct { type Screen struct {
width int width int
height int height int
cleared bool
tags map[string]termbox.Attribute tags map[string]termbox.Attribute
} }
@ -44,12 +45,14 @@ func (self *Screen) Initialize() *Screen {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Screen) Resize() *Screen { func (self *Screen) Resize() *Screen {
self.width, self.height = termbox.Size() self.width, self.height = termbox.Size()
self.cleared = false
return self return self
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Screen) Clear() *Screen { func (self *Screen) Clear() *Screen {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault) termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
self.cleared = true
return self return self
} }
@ -121,6 +124,9 @@ func (self *Screen) DrawLine(x int, y int, str string) {
// private // private
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Screen) draw(str string) { func (self *Screen) draw(str string) {
if !self.cleared {
self.Clear()
}
for row, line := range strings.Split(str, "\n") { for row, line := range strings.Split(str, "\n") {
self.DrawLine(0, row, line) self.DrawLine(0, row, line)
} }

@ -24,7 +24,6 @@ func mainLoop(screen *mop.Screen, profile *mop.Profile) {
market := new(mop.Market).Initialize().Fetch() market := new(mop.Market).Initialize().Fetch()
quotes := new(mop.Quotes).Initialize(market, profile) quotes := new(mop.Quotes).Initialize(market, profile)
screen.Clear()
screen.DrawMarket(market) screen.DrawMarket(market)
screen.DrawQuotes(quotes) screen.DrawQuotes(quotes)
@ -48,7 +47,7 @@ loop:
} }
} }
case termbox.EventResize: case termbox.EventResize:
screen.Resize().Clear() screen.Resize()
screen.DrawMarket(market) screen.DrawMarket(market)
screen.DrawQuotes(quotes) screen.DrawQuotes(quotes)
} }

Loading…
Cancel
Save