Documentation ¶
Index ¶
- type Column
- type ColumnEditor
- type Layout
- type LineEditor
- type Market
- type Markup
- type Profile
- type Quotes
- 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) Pause(pause bool) *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 NewColumnEditor ¶ added in v0.2.0
func NewColumnEditor(screen *Screen, quotes *Quotes) *ColumnEditor
Returns new initialized ColumnEditor struct. As part of initialization it highlights current column name (as stored in Profile).
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.
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 NewLayout ¶ added in v0.2.0
func NewLayout() *Layout
Creates the layout and assigns the default values that stay unchanged.
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) 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 NewLineEditor ¶ added in v0.2.0
func NewLineEditor(screen *Screen, quotes *Quotes) *LineEditor
Returns new initialized LineEditor struct.
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) 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. Tokyo map[string]string HongKong map[string]string London map[string]string Frankfurt map[string]string Yield map[string]string Oil map[string]string Yen map[string]string Euro map[string]string Gold map[string]string // 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.
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 NewMarkup ¶ added in v0.2.0
func NewMarkup() *Markup
Creates markup to define tag to Termbox translation rules and store default colors and column alignments.
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 NewProfile ¶ added in v0.2.0
func NewProfile() *Profile
Creates the profile and attempts to load the settings from ~/.moprc file. If the file is not there it gets created with default values.
func (*Profile) AddTickers ¶
AddTickers updates the list of existing tikers to add the new ones making sure there are no duplicates.
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) 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 NewScreen ¶ added in v0.2.0
func NewScreen() *Screen
Initializes Termbox, creates screen along with layout and markup, and calculates current screen dimensions. Once initialized the screen is ready for display.
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.
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) 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.