Started making golint happy...

master
Michael Dvorkin 11 years ago
parent 93db48015b
commit f1548e6bac
  1. 66
      cmd/mop.go
  2. 94
      column_editor.go

@ -1,6 +1,6 @@
// Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Use of this source code is governed by a MIT-style license that can
// be found in the LICENSE file.
package main
@ -27,19 +27,19 @@ Enter comma-delimited list of stock tickers when prompted.
`
//-----------------------------------------------------------------------------
func main_loop(screen *mop.Screen, profile *mop.Profile) {
var line_editor *mop.LineEditor
var column_editor *mop.ColumnEditor
func mainLoop(screen *mop.Screen, profile *mop.Profile) {
var lineEditor *mop.LineEditor
var columnEditor *mop.ColumnEditor
keyboard_queue := make(chan termbox.Event)
timestamp_queue := time.NewTicker(1 * time.Second)
quotes_queue := time.NewTicker(5 * time.Second)
market_queue := time.NewTicker(12 * time.Second)
showing_help := false
keyboardQueue := make(chan termbox.Event)
timestampQueue := time.NewTicker(1 * time.Second)
quotesQueue := time.NewTicker(5 * time.Second)
marketQueue := time.NewTicker(12 * time.Second)
showingHelp := false
go func() {
for {
keyboard_queue <- termbox.PollEvent()
keyboardQueue <- termbox.PollEvent()
}
}()
@ -50,58 +50,58 @@ func main_loop(screen *mop.Screen, profile *mop.Profile) {
loop:
for {
select {
case event := <-keyboard_queue:
case event := <-keyboardQueue:
switch event.Type {
case termbox.EventKey:
if line_editor == nil && column_editor == nil && !showing_help {
if lineEditor == nil && columnEditor == nil && !showingHelp {
if event.Key == termbox.KeyEsc {
break loop
} else if event.Ch == '+' || event.Ch == '-' {
line_editor = new(mop.LineEditor).Initialize(screen, quotes)
line_editor.Prompt(event.Ch)
lineEditor = new(mop.LineEditor).Initialize(screen, quotes)
lineEditor.Prompt(event.Ch)
} else if event.Ch == 'o' || event.Ch == 'O' {
column_editor = new(mop.ColumnEditor).Initialize(screen, quotes)
columnEditor = new(mop.ColumnEditor).Initialize(screen, quotes)
} else if event.Ch == 'g' || event.Ch == 'G' {
if profile.Regroup() == nil {
screen.Draw(quotes)
}
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' {
showing_help = true
showingHelp = true
screen.Clear().Draw(help)
}
} else if line_editor != nil {
if done := line_editor.Handle(event); done {
line_editor = nil
} else if lineEditor != nil {
if done := lineEditor.Handle(event); done {
lineEditor = nil
}
} else if column_editor != nil {
if done := column_editor.Handle(event); done {
column_editor = nil
} else if columnEditor != nil {
if done := columnEditor.Handle(event); done {
columnEditor = nil
}
} else if showing_help {
showing_help = false
} else if showingHelp {
showingHelp = false
screen.Clear().Draw(market, quotes)
}
case termbox.EventResize:
screen.Resize()
if !showing_help {
if !showingHelp {
screen.Draw(market, quotes)
} else {
screen.Draw(help)
}
}
case <-timestamp_queue.C:
if !showing_help {
case <-timestampQueue.C:
if !showingHelp {
screen.DrawTime()
}
case <-quotes_queue.C:
if !showing_help {
case <-quotesQueue.C:
if !showingHelp {
screen.Draw(quotes)
}
case <-market_queue.C:
if !showing_help {
case <-marketQueue.C:
if !showingHelp {
screen.Draw(market)
}
}
@ -114,5 +114,5 @@ func main() {
defer screen.Close()
profile := new(mop.Profile).Initialize()
main_loop(screen, profile)
mainLoop(screen, profile)
}

@ -1,93 +1,97 @@
// Copyright (c) 2013 by Michael Dvorkin. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// Use of this source code is governed by a MIT-style license that can
// be found in the LICENSE file.
package mop
import (
`github.com/michaeldv/termbox-go`
)
import `github.com/michaeldv/termbox-go`
// ColumnEditor handles column sort order. When activated it highlights
// current column name in the header, then waits for arrow keys (choose
// another column), Enter (reverse sort order), or Esc (exit).
type ColumnEditor struct {
screen *Screen
quotes *Quotes
profile *Profile
screen *Screen // Pointer to Screen so we could use screen.Draw().
quotes *Quotes // Pointer to Quotes to redraw them when the sort order changes.
profile *Profile // Pointer to Profile where we save newly selected sort order.
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) Initialize(screen *Screen, quotes *Quotes) *ColumnEditor {
self.screen = screen
self.quotes = quotes
self.profile = quotes.profile
// Initialize sets internal variables and highlights current column name
// (as stored in Profile).
func (editor *ColumnEditor) Initialize(screen *Screen, quotes *Quotes) *ColumnEditor {
editor.screen = screen
editor.quotes = quotes
editor.profile = quotes.profile
editor.selectCurrentColumn()
self.select_current_column()
return self
return editor
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) Handle(ev termbox.Event) bool {
defer self.redraw_header()
// Handle takes over the keyboard events and dispatches them to appropriate
// column editor handlers. It returns true when user presses Esc.
func (editor *ColumnEditor) Handle(event termbox.Event) bool {
defer editor.redrawHeader()
switch ev.Key {
switch event.Key {
case termbox.KeyEsc:
return self.done()
return editor.done()
case termbox.KeyEnter:
self.execute()
editor.execute()
case termbox.KeyArrowLeft:
self.select_left_column()
editor.selectLeftColumn()
case termbox.KeyArrowRight:
self.select_right_column()
editor.selectRightColumn()
}
return false
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) select_current_column() *ColumnEditor {
self.profile.selected_column = self.profile.SortColumn
self.redraw_header()
return self
func (editor *ColumnEditor) selectCurrentColumn() *ColumnEditor {
editor.profile.selected_column = editor.profile.SortColumn
editor.redrawHeader()
return editor
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) select_left_column() *ColumnEditor {
self.profile.selected_column--
if self.profile.selected_column < 0 {
self.profile.selected_column = TotalColumns - 1
func (editor *ColumnEditor) selectLeftColumn() *ColumnEditor {
editor.profile.selected_column--
if editor.profile.selected_column < 0 {
editor.profile.selected_column = TotalColumns - 1
}
return self
return editor
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) select_right_column() *ColumnEditor {
self.profile.selected_column++
if self.profile.selected_column > TotalColumns - 1 {
self.profile.selected_column = 0
func (editor *ColumnEditor) selectRightColumn() *ColumnEditor {
editor.profile.selected_column++
if editor.profile.selected_column > TotalColumns - 1 {
editor.profile.selected_column = 0
}
return self
return editor
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) execute() *ColumnEditor {
if self.profile.Reorder() == nil {
self.screen.Draw(self.quotes)
func (editor *ColumnEditor) execute() *ColumnEditor {
if editor.profile.Reorder() == nil {
editor.screen.Draw(editor.quotes)
}
return self
return editor
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) done() bool {
self.profile.selected_column = -1
func (editor *ColumnEditor) done() bool {
editor.profile.selected_column = -1
return true
}
//-----------------------------------------------------------------------------
func (self *ColumnEditor) redraw_header() {
self.screen.DrawLine(0, 4, self.screen.layout.Header(self.profile))
func (editor *ColumnEditor) redrawHeader() {
editor.screen.DrawLine(0, 4, editor.screen.layout.Header(editor.profile))
termbox.Flush()
}

Loading…
Cancel
Save