diff --git a/layout.go b/layout.go index 1dd80fe..5f69d84 100644 --- a/layout.go +++ b/layout.go @@ -165,11 +165,13 @@ func (layout *Layout) prettify(quotes *Quotes) []Stock { profile := quotes.profile - if profile.filterExpression != nil { - if layout.filter == nil { // Initialize filter on first invocation. - layout.filter = NewFilter(profile) + if profile.Filter != ""{ // Fix for blank display if invalid filter expression was cleared. + if profile.filterExpression != nil { + if layout.filter == nil { // Initialize filter on first invocation. + layout.filter = NewFilter(profile) + } + pretty = layout.filter.Apply(pretty) } - pretty = layout.filter.Apply(pretty) } if layout.sorter == nil { // Initialize sorter on first invocation. diff --git a/screen.go b/screen.go index 3085476..51e8d8e 100644 --- a/screen.go +++ b/screen.go @@ -8,6 +8,8 @@ import ( `github.com/nsf/termbox-go` `strings` `time` + `strconv` + `fmt` ) // Screen is thin wrapper aroung Termbox library to provide basic display @@ -140,7 +142,39 @@ func (screen *Screen) draw(str string) { if !screen.cleared { screen.Clear() } - for row, line := range strings.Split(str, "\n") { - screen.DrawLine(0, row, line) + var allLines []string + drewHeading := false + + tempFormat := "%" + strconv.Itoa(screen.width) + "s" + blankLine := fmt.Sprintf(tempFormat,"") + allLines = strings.Split(str, "\n") + + // Write the lines being updated. + for row := 0; row < len(allLines); row++ { + screen.DrawLine(0, row, allLines[row]) + // Did we draw the underlined heading row? This is a crude + // check, but--see comments below... + if strings.Contains(allLines[row],"Ticker") && + strings.Contains(allLines[row],"Last") && + strings.Contains(allLines[row],"Change") { + drewHeading = true + } + } + // If the quotes lines in this cycle are shorter than in the previous + // cycles, e.g., because a filter was just applied, then one or more + // lines from the previous cycles will not be cleared. Since the + // incoming lines don't mark explicitly whether they are part of the + // market summary or quotes, we can't check whether quotes were updated + // in a way that is robust for code changes. This is a simple test: if + // we drew the heading row ("Ticker Last Change..."), then we are + // updating the quotes section in this cycle, and we should pad the + // quotes section with blank lines. If we didn't draw the heading row, + // then we probably only updated the market summary at the top in this + // cycle. In that case, padding with blank lines would overwrite the + // stocks list.) + if drewHeading { + for i := len(allLines)-1; i < screen.height; i++ { + screen.DrawLine(0, i, blankLine) + } } }