Documentation ¶
Index ¶
- type Column
- type ColumnEditor
- type Layout
- type LineEditor
- type Market
- type Markup
- type Profile
- func (profile *Profile) AddTickers(tickers []string) (added int, err error)
- func (profile *Profile) Initialize() *Profile
- func (profile *Profile) Regroup() error
- func (profile *Profile) RemoveTickers(tickers []string) (removed int, err error)
- func (profile *Profile) Reorder() error
- func (profile *Profile) Save() error
- type Quotes
- func (quotes *Quotes) AddTickers(tickers []string) (added int, err error)
- func (quotes *Quotes) Fetch() (self *Quotes)
- func (quotes *Quotes) Initialize(market *Market, profile *Profile) *Quotes
- func (quotes *Quotes) Ok() (bool, string)
- func (quotes *Quotes) RemoveTickers(tickers []string) (removed int, err error)
- type Screen
- func (screen *Screen) Clear() *Screen
- func (screen *Screen) ClearLine(x int, y int) *Screen
- func (screen *Screen) Close() *Screen
- func (screen *Screen) Draw(objects ...interface{}) *Screen
- func (screen *Screen) DrawLine(x int, y int, str string)
- func (screen *Screen) Initialize() *Screen
- func (screen *Screen) Resize() *Screen
- type Sorter
- type Stock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column describes formatting rules for individual column within the list of stock quotes.
type ColumnEditor ¶
type ColumnEditor struct {
// contains filtered or unexported fields
}
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).
func (*ColumnEditor) Handle ¶
func (editor *ColumnEditor) Handle(event termbox.Event) bool
Handle takes over the keyboard events and dispatches them to appropriate column editor handlers. It returns true when user presses Esc.
func (*ColumnEditor) Initialize ¶
func (editor *ColumnEditor) Initialize(screen *Screen, quotes *Quotes) *ColumnEditor
Initialize sets internal variables and highlights current column name (as stored in Profile).
type Layout ¶
type Layout struct {
// contains filtered or unexported fields
}
Layout is used to format and display all the collected data, i.e. market updates and the list of stock quotes.
func (*Layout) Header ¶
Header iterates over column titles and formats the header line. The formatting includes placing an arrow next to the sorted column title. When the column editor is active it knows how to highlight currently selected column title.
func (*Layout) Initialize ¶
Initialize assigns the default values that stay unchanged for the life of allocated Layout struct.
func (*Layout) Market ¶
Market merges given market data structure with the market template and returns formatted string that includes highlighting markup.
func (*Layout) Quotes ¶
Quotes uses quotes template to format timestamp, stock quotes header, and the list of given stock quotes. It returns formatted string with all the necessary markup.
func (*Layout) TotalColumns ¶
TotalColumns is the utility method for the column editor that returns total number of columns.
type LineEditor ¶
type LineEditor struct {
// contains filtered or unexported fields
}
LineEditor kicks in when user presses '+' or '-' to add or delete stock tickers. The data structure and methods are used to collect the input data and keep track of cursor movements (left, right, beginning of the line, end of the line, and backspace).
func (*LineEditor) Handle ¶
func (editor *LineEditor) Handle(ev termbox.Event) bool
Handle takes over the keyboard events and dispatches them to appropriate line editor handlers. As user types or edits the text cursor movements are tracked in `editor.cursor` while the text itself is stored in `editor.input`. The method returns true when user presses Esc (discard) or Enter (process).
func (*LineEditor) Initialize ¶
func (editor *LineEditor) Initialize(screen *Screen, quotes *Quotes) *LineEditor
Initialize sets internal pointers and compiles the regular expression.
func (*LineEditor) Prompt ¶
func (editor *LineEditor) Prompt(command rune) *LineEditor
Prompt displays a prompt in response to '+' or '-' commands. Unknown commands are simply ignored. The prompt is displayed on the 3rd line (between the market data and the stock quotes).
type Market ¶
type Market struct { IsClosed bool // True when U.S. markets are closed. Dow map[string]string // Hash of Dow Jones indicators. Nasdaq map[string]string // Hash of NASDAQ indicators. Sp500 map[string]string // Hash of S&P 500 indicators. Advances map[string]string // Number of advanced stocks on NYSE and NASDAQ. Declines map[string]string // Ditto for declines. Unchanged map[string]string // Ditto for unchanged. Highs map[string]string // Number of new highs on NYSE and NASDAQ. Lows map[string]string // Ditto for new lows. // contains filtered or unexported fields }
Market stores current market information displayed in the top three lines of the screen. The market data is fetched and parsed from the HTML page above.
func (*Market) Fetch ¶
Fetch downloads HTML page from the 'marketURL', parses it, and stores resulting data in internal hashes. If download or data parsing fails Fetch populates 'market.errors'.
func (*Market) Initialize ¶
Initialize creates empty hashes and builds regular expression used to parse market data from HTML page.
type Markup ¶
type Markup struct { Foreground termbox.Attribute // Foreground color. Background termbox.Attribute // Background color (so far always termbox.ColorDefault). RightAligned bool // True when the string is right aligned. // contains filtered or unexported fields }
Markup implements some minimalistic text formatting conventions that get translated to Termbox colors and attributes. To colorize a string wrap it in <color-name>...</> tags. Unlike HTML each tag sets a new color whereas the </> tag changes color back to default. For example:
<green>Hello, <red>world!</>
The color tags could be combined with the attributes: <b>...</b> for bold, <u>...</u> for underline, and <r>...</r> for reverse. Unlike colors the attributes require matching closing tag.
The <right>...</right> tag is used to right align the enclosed string (ex. when displaying current time in the upper right corner).
func (*Markup) Initialize ¶
Initialize creates tags to Termbox translation hash and sets default colors and string alignment.
func (*Markup) IsTag ¶
IsTag returns true when the given string looks like markup tag. When the tag name matches one of the markup-supported tags it gets translated to relevant Termbox attributes and colors.
type Profile ¶
type Profile struct { Tickers []string // List of stock tickers to display. MarketRefresh int // Time interval to refresh market data. QuotesRefresh int // Time interval to refresh stock quotes. SortColumn int // Column number by which we sort stock quotes. Ascending bool // True when sort order is ascending. Grouped bool // True when stocks are grouped by advancing/declining. // contains filtered or unexported fields }
Profile manages Mop program settings as defined by user (ex. list of stock tickers). The settings are serialized using JSON and saved in the ~/.moprc file.
func (*Profile) AddTickers ¶
AddTickers updates the list of existing tikers to add the new ones making sure there are no duplicates.
func (*Profile) Initialize ¶
Initialize attempts to load the settings from ~/.moprc file. If the file is not there it gets created with the default values.
func (*Profile) Regroup ¶
Regroup flips the flag that controls whether the stock quotes are grouped by advancing/declining issues.
func (*Profile) RemoveTickers ¶
RemoveTickers removes requested stock tickers from the list we track.
type Quotes ¶
type Quotes struct {
// contains filtered or unexported fields
}
Quotes stores relevant pointers as well as the array of stock quotes for the tickers we are tracking.
func (*Quotes) AddTickers ¶
AddTickers saves the list of tickers and refreshes the stock data if new tickers have been added. The function gets called from the line editor when user adds new stock tickers.
func (*Quotes) Fetch ¶
Fetch the latest stock quotes and parse raw fetched data into array of []Stock structs.
func (*Quotes) Initialize ¶
Initialize sets the initial values for the Quotes struct. It returns "self" so that the next function call could be chained.
func (*Quotes) Ok ¶
Ok returns two values: 1) boolean indicating whether the error has occured, and 2) the error text itself.
func (*Quotes) RemoveTickers ¶
RemoveTickers saves the list of tickers and refreshes the stock data if some tickers have been removed. The function gets called from the line editor when user removes existing stock tickers.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen is thin wrapper aroung Termbox library to provide basic display capabilities as requied by Mop.
func (*Screen) ClearLine ¶
ClearLine erases the contents of the line starting from (x,y) coordinate till the end of the line.
func (*Screen) Draw ¶
Draw accepts variable number of arguments and knows how to display the market data, stock quotes, current time, and an arbitrary string.
func (*Screen) DrawLine ¶
DrawLine takes the incoming string, tokenizes it to extract markup elements, and displays it all starting at (x,y) location.
func (*Screen) Initialize ¶
Initialize loads the Termbox, allocates and initializes layout and markup, and calculates current screen dimensions. Once initialized the screen is ready for display.
type Sorter ¶
type Sorter struct {
// contains filtered or unexported fields
}
Sorter gets called to sort stock quotes by one of the columns. The setup is rather lengthy; there should probably be more concise way that uses reflection and avoids hardcoding the column names.
func (*Sorter) Initialize ¶
Initialize simply saves the pointer to Profile for later use.
func (*Sorter) SortByCurrentColumn ¶
SortByCurrentColumn builds a list of sort interface based on current sort order, then calls sort.Sort to do the actual job.
type Stock ¶
type Stock struct { Ticker string // Stock ticker. LastTrade string // l1: last trade. Change string // c6: change real time. ChangePct string // k2: percent change real time. Open string // o: market open price. Low string // g: day's low. High string // h: day's high. Low52 string // j: 52-weeks low. High52 string // k: 52-weeks high. Volume string // v: volume. AvgVolume string // a2: average volume. PeRatio string // r2: P/E ration real time. PeRatioX string // r: P/E ration (fallback when real time is N/A). Dividend string // d: dividend. Yield string // y: dividend yield. MarketCap string // j3: market cap real time. MarketCapX string // j1: market cap (fallback when real time is N/A). Advancing bool // True when change is >= $0. }
Stock stores quote information for the particular stock ticker. The data for all the fields except 'Advancing' is fetched using Yahoo market API.