|
|
@ -16,22 +16,28 @@ import ( |
|
|
|
const defaultGainColor = "green" |
|
|
|
const defaultGainColor = "green" |
|
|
|
const defaultLossColor = "red" |
|
|
|
const defaultLossColor = "red" |
|
|
|
const defaultTagColor = "yellow" |
|
|
|
const defaultTagColor = "yellow" |
|
|
|
|
|
|
|
const defaultHeaderColor = "lightgray" |
|
|
|
|
|
|
|
const defaultTimeColor = "lightgray" |
|
|
|
|
|
|
|
const defaultColor = "lightgray" |
|
|
|
|
|
|
|
|
|
|
|
// Profile manages Mop program settings as defined by user (ex. list of
|
|
|
|
// Profile manages Mop program settings as defined by user (ex. list of
|
|
|
|
// stock tickers). The settings are serialized using JSON and saved in
|
|
|
|
// stock tickers). The settings are serialized using JSON and saved in
|
|
|
|
// the ~/.moprc file.
|
|
|
|
// the ~/.moprc file.
|
|
|
|
type Profile struct { |
|
|
|
type Profile struct { |
|
|
|
Tickers []string // List of stock tickers to display.
|
|
|
|
Tickers []string // List of stock tickers to display.
|
|
|
|
MarketRefresh int // Time interval to refresh market data.
|
|
|
|
MarketRefresh int // Time interval to refresh market data.
|
|
|
|
QuotesRefresh int // Time interval to refresh stock quotes.
|
|
|
|
QuotesRefresh int // Time interval to refresh stock quotes.
|
|
|
|
SortColumn int // Column number by which we sort stock quotes.
|
|
|
|
SortColumn int // Column number by which we sort stock quotes.
|
|
|
|
Ascending bool // True when sort order is ascending.
|
|
|
|
Ascending bool // True when sort order is ascending.
|
|
|
|
Grouped bool // True when stocks are grouped by advancing/declining.
|
|
|
|
Grouped bool // True when stocks are grouped by advancing/declining.
|
|
|
|
Filter string // Filter in human form
|
|
|
|
Filter string // Filter in human form
|
|
|
|
Colors struct { // User defined colors
|
|
|
|
Colors struct { // User defined colors
|
|
|
|
Gain string |
|
|
|
Gain string |
|
|
|
Loss string |
|
|
|
Loss string |
|
|
|
Tag string |
|
|
|
Tag string |
|
|
|
|
|
|
|
Header string |
|
|
|
|
|
|
|
Time string |
|
|
|
|
|
|
|
Default string |
|
|
|
} |
|
|
|
} |
|
|
|
filterExpression *govaluate.EvaluableExpression // The filter as a govaluate expression
|
|
|
|
filterExpression *govaluate.EvaluableExpression // The filter as a govaluate expression
|
|
|
|
selectedColumn int // Stores selected column number when the column editor is active.
|
|
|
|
selectedColumn int // Stores selected column number when the column editor is active.
|
|
|
@ -40,24 +46,24 @@ type Profile struct { |
|
|
|
|
|
|
|
|
|
|
|
func IsSupportedColor(colorName string) bool { |
|
|
|
func IsSupportedColor(colorName string) bool { |
|
|
|
switch colorName { |
|
|
|
switch colorName { |
|
|
|
case |
|
|
|
case |
|
|
|
"black", |
|
|
|
"black", |
|
|
|
"red", |
|
|
|
"red", |
|
|
|
"green", |
|
|
|
"green", |
|
|
|
"yellow", |
|
|
|
"yellow", |
|
|
|
"blue", |
|
|
|
"blue", |
|
|
|
"magenta", |
|
|
|
"magenta", |
|
|
|
"cyan", |
|
|
|
"cyan", |
|
|
|
"white", |
|
|
|
"white", |
|
|
|
"darkgray", |
|
|
|
"darkgray", |
|
|
|
"lightred", |
|
|
|
"lightred", |
|
|
|
"lightgreen", |
|
|
|
"lightgreen", |
|
|
|
"lightyellow", |
|
|
|
"lightyellow", |
|
|
|
"lightblue", |
|
|
|
"lightblue", |
|
|
|
"lightmagenta", |
|
|
|
"lightmagenta", |
|
|
|
"lightcyan", |
|
|
|
"lightcyan", |
|
|
|
"lightgray": |
|
|
|
"lightgray": |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
@ -78,13 +84,19 @@ func NewProfile(filename string) *Profile { |
|
|
|
profile.Colors.Gain = defaultGainColor |
|
|
|
profile.Colors.Gain = defaultGainColor |
|
|
|
profile.Colors.Loss = defaultLossColor |
|
|
|
profile.Colors.Loss = defaultLossColor |
|
|
|
profile.Colors.Tag = defaultTagColor |
|
|
|
profile.Colors.Tag = defaultTagColor |
|
|
|
|
|
|
|
profile.Colors.Header = defaultHeaderColor |
|
|
|
|
|
|
|
profile.Colors.Time = defaultTimeColor |
|
|
|
|
|
|
|
profile.Colors.Default = defaultColor |
|
|
|
profile.Save() |
|
|
|
profile.Save() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
json.Unmarshal(data, profile) |
|
|
|
json.Unmarshal(data, profile) |
|
|
|
|
|
|
|
|
|
|
|
InitColor(profile.Colors.Gain, defaultGainColor) |
|
|
|
InitColor(&profile.Colors.Gain, defaultGainColor) |
|
|
|
InitColor(profile.Colors.Loss, defaultLossColor) |
|
|
|
InitColor(&profile.Colors.Loss, defaultLossColor) |
|
|
|
InitColor(profile.Colors.Tag, defaultTagColor) |
|
|
|
InitColor(&profile.Colors.Tag, defaultTagColor) |
|
|
|
|
|
|
|
InitColor(&profile.Colors.Header, defaultHeaderColor) |
|
|
|
|
|
|
|
InitColor(&profile.Colors.Time, defaultTimeColor) |
|
|
|
|
|
|
|
InitColor(&profile.Colors.Default, defaultColor) |
|
|
|
|
|
|
|
|
|
|
|
profile.SetFilter(profile.Filter) |
|
|
|
profile.SetFilter(profile.Filter) |
|
|
|
} |
|
|
|
} |
|
|
@ -93,10 +105,10 @@ func NewProfile(filename string) *Profile { |
|
|
|
return profile |
|
|
|
return profile |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func InitColor(color string, defaultValue string) { |
|
|
|
func InitColor(color *string, defaultValue string) { |
|
|
|
color = strings.ToLower(color) |
|
|
|
*color = strings.ToLower(*color) |
|
|
|
if !IsSupportedColor(color) { |
|
|
|
if !IsSupportedColor(*color) { |
|
|
|
color = defaultValue; |
|
|
|
*color = defaultValue |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|