Added help screen

master
Michael Dvorkin 11 years ago
parent 11dea8282b
commit b0c4dd0fa9
  1. 48
      mop/mop.go
  2. 2
      screen.go

@ -8,14 +8,30 @@ import (
`time` `time`
) )
const help = `Mop v0.1.0 -- Copyright (c) 2013 Michael Dvorkin. All Rights Reserved.
NO WARRANTIES OF ANY KIND WHATSOEVER. USE AT YOUR OWN DISCRETION.
<u>Command</u> <u>Description </u>
+ Add stocks to the list.
- Remove stocks from the list.
o Change default sorting order.
g Group stocks by advancing/declining issues.
? Display this help screen.
esc Quit mop.
<r> Press any key to continue </r>
`
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func mainLoop(screen *mop.Screen, profile *mop.Profile) { func main_loop(screen *mop.Screen, profile *mop.Profile) {
var line_editor *mop.LineEditor var line_editor *mop.LineEditor
var column_editor *mop.ColumnEditor var column_editor *mop.ColumnEditor
keyboard_queue := make(chan termbox.Event) keyboard_queue := make(chan termbox.Event)
timestamp_queue := time.NewTicker(1 * time.Second) timestamp_queue := time.NewTicker(1 * time.Second)
quotes_queue := time.NewTicker(5 * time.Second) quotes_queue := time.NewTicker(5 * time.Second)
market_queue := time.NewTicker(12 * time.Second) market_queue := time.NewTicker(12 * time.Second)
showing_help := false
go func() { go func() {
for { for {
@ -23,7 +39,7 @@ func mainLoop(screen *mop.Screen, profile *mop.Profile) {
} }
}() }()
market := new(mop.Market).Initialize().Fetch() market := new(mop.Market).Initialize()
quotes := new(mop.Quotes).Initialize(market, profile) quotes := new(mop.Quotes).Initialize(market, profile)
screen.Draw(market, quotes) screen.Draw(market, quotes)
@ -33,7 +49,7 @@ loop:
case event := <-keyboard_queue: case event := <-keyboard_queue:
switch event.Type { switch event.Type {
case termbox.EventKey: case termbox.EventKey:
if line_editor == nil && column_editor == nil { if line_editor == nil && column_editor == nil && !showing_help {
if event.Key == termbox.KeyEsc { if event.Key == termbox.KeyEsc {
break loop break loop
} else if event.Ch == '+' || event.Ch == '-' { } else if event.Ch == '+' || event.Ch == '-' {
@ -44,6 +60,9 @@ loop:
} else if event.Ch == 'g' || event.Ch == 'G' { } else if event.Ch == 'g' || event.Ch == 'G' {
profile.Regroup() profile.Regroup()
screen.Draw(quotes) screen.Draw(quotes)
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' {
showing_help = true
screen.Clear().Draw(help)
} }
} else if line_editor != nil { } else if line_editor != nil {
done := line_editor.Handle(event) done := line_editor.Handle(event)
@ -55,20 +74,33 @@ loop:
if done { if done {
column_editor = nil column_editor = nil
} }
} else if showing_help {
showing_help = false
screen.Clear().Draw(market, quotes)
} }
case termbox.EventResize: case termbox.EventResize:
screen.Resize() screen.Resize()
screen.Draw(market, quotes) if !showing_help {
screen.Draw(market, quotes)
} else {
screen.Draw(help)
}
} }
case <-timestamp_queue.C: case <-timestamp_queue.C:
screen.DrawTime() if !showing_help {
screen.DrawTime()
}
case <-quotes_queue.C: case <-quotes_queue.C:
screen.Draw(quotes) if !showing_help {
screen.Draw(quotes)
}
case <-market_queue.C: case <-market_queue.C:
screen.Draw(market) if !showing_help {
screen.Draw(market)
}
} }
} }
} }
@ -79,5 +111,5 @@ func main() {
defer screen.Close() defer screen.Close()
profile := new(mop.Profile).Initialize() profile := new(mop.Profile).Initialize()
mainLoop(screen, profile) main_loop(screen, profile)
} }

@ -58,6 +58,8 @@ func (self *Screen) Draw(objects ...interface{}) {
case *Quotes: case *Quotes:
object := ptr.(*Quotes) object := ptr.(*Quotes)
self.draw(object.Fetch().Format()) self.draw(object.Fetch().Format())
default:
self.draw(ptr.(string))
} }
} }
} }

Loading…
Cancel
Save