Show sort order indicator in the header

master
Michael Dvorkin 12 years ago
parent c8583aa4d0
commit 4d4ed17228
  1. 20
      lib/column_editor.go
  2. 27
      lib/layout.go
  3. 2
      mop.go

@ -3,21 +3,21 @@
package mop
import (
// `regexp`
// `strings`
`github.com/nsf/termbox-go`
)
type ColumnEditor struct {
screen *Screen
layout *Layout
quotes *Quotes
profile *Profile
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) Initialize(screen *Screen, profile *Profile) *ColumnEditor {
func (self *ColumnEditor) Initialize(screen *Screen, quotes *Quotes) *ColumnEditor {
self.screen = screen
self.profile = profile
self.quotes = quotes
self.profile = quotes.profile
self.layout = new(Layout).Initialize()
self.select_current_column()
@ -33,7 +33,7 @@ func (self *ColumnEditor) Handle(ev termbox.Event) bool {
return self.done()
case termbox.KeyEnter:
return self.execute().done()
self.execute()
case termbox.KeyArrowLeft:
self.select_left_column()
@ -72,7 +72,13 @@ func (self *ColumnEditor) select_right_column() *ColumnEditor {
//-----------------------------------------------------------------------------
func (self *ColumnEditor) execute() *ColumnEditor {
if self.profile.selected_column == self.profile.SortColumn {
self.profile.Ascending = !self.profile.Ascending
} else {
self.profile.SortColumn = self.profile.selected_column
}
self.profile.Save()
self.screen.Draw(self.quotes)
return self
}
@ -84,7 +90,7 @@ func (self *ColumnEditor) done() bool {
//-----------------------------------------------------------------------------
func (self *ColumnEditor) redraw_header() {
self.screen.DrawLine(0, 4, self.layout.Header(self.profile.selected_column))
self.screen.DrawLine(0, 4, self.layout.Header(self.profile))
termbox.Flush()
}

@ -96,7 +96,7 @@ func (self *Layout) Quotes(quotes *Quotes) string {
Stocks []Stock
}{
time.Now().Format(`3:04:05pm PST`),
self.Header(quotes.profile.selected_column),
self.Header(quotes.profile),
self.prettify(quotes),
}
@ -123,18 +123,19 @@ func (self *Layout) Quotes(quotes *Quotes) string {
}
//-----------------------------------------------------------------------------
func (self *Layout) Header(selected_column int) string {
str := `<u>`
func (self *Layout) Header(profile *Profile) string {
str, selected_column := ``, profile.selected_column
for i,col := range self.columns {
arrow := arrow_for(i, profile)
if i != selected_column {
str += fmt.Sprintf(`%*s`, col.width, col.title)
str += fmt.Sprintf(`%*s`, col.width, arrow + col.title)
} else {
str += fmt.Sprintf(`<r>%*s</r>`, col.width, col.title)
str += fmt.Sprintf(`<r>%*s</r>`, col.width, arrow + col.title)
}
}
str += `</u>`
return str
return `<u>` + str + `</u>`
}
//-----------------------------------------------------------------------------
@ -183,6 +184,18 @@ func group(quotes *Quotes) []Stock {
}
}
//-----------------------------------------------------------------------------
func arrow_for(column int, profile *Profile) string {
if column == profile.SortColumn {
if profile.Ascending {
return string('\U00002193')
} else {
return string('\U00002191')
}
}
return ``
}
//-----------------------------------------------------------------------------
func nullify(str string) string {
if len(str) == 3 && str[0:3] == `N/A` {

@ -40,7 +40,7 @@ loop:
line_editor = new(mop.LineEditor).Initialize(screen, quotes)
line_editor.Prompt(event.Ch)
} else if event.Ch == 'o' || event.Ch == 'O' {
column_editor = new(mop.ColumnEditor).Initialize(screen, profile)
column_editor = new(mop.ColumnEditor).Initialize(screen, quotes)
} else if event.Ch == 'g' || event.Ch == 'G' {
profile.Regroup()
screen.Draw(quotes)

Loading…
Cancel
Save