|
|
@ -4,7 +4,6 @@ package mop |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"sort" |
|
|
|
|
|
|
|
"regexp" |
|
|
|
"regexp" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"github.com/nsf/termbox-go" |
|
|
|
"github.com/nsf/termbox-go" |
|
|
@ -138,37 +137,30 @@ func (self *LineEditor) done() { |
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func (self *LineEditor) execute() { |
|
|
|
func (self *LineEditor) execute() { |
|
|
|
switch self.command { |
|
|
|
switch self.command { |
|
|
|
case '+', '-': |
|
|
|
case '+': |
|
|
|
input := strings.ToUpper(strings.TrimSpace(self.input)) |
|
|
|
tickers := self.tokenize() |
|
|
|
tickers := regexp.MustCompile(`[,\s]+`).Split(input, -1) |
|
|
|
|
|
|
|
if len(tickers) > 0 { |
|
|
|
if len(tickers) > 0 { |
|
|
|
if self.command == '+' { |
|
|
|
self.profile.AddTickers(tickers) |
|
|
|
self.add_tickers(tickers) |
|
|
|
DrawQuotes(self.profile.Quotes()) |
|
|
|
} else { |
|
|
|
|
|
|
|
self.remove_tickers(tickers) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case '-': |
|
|
|
|
|
|
|
tickers := self.tokenize() |
|
|
|
|
|
|
|
if len(tickers) > 0 { |
|
|
|
|
|
|
|
before := len(self.profile.Tickers) |
|
|
|
|
|
|
|
self.profile.RemoveTickers(tickers) |
|
|
|
|
|
|
|
after := len(self.profile.Tickers) |
|
|
|
|
|
|
|
if after < before { |
|
|
|
|
|
|
|
DrawQuotes(self.profile.Quotes()) |
|
|
|
|
|
|
|
for i := before; i > after; i-- { |
|
|
|
|
|
|
|
ClearLine(0, i + 4) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func (self *LineEditor) add_tickers(tickers []string) { |
|
|
|
|
|
|
|
existing := make(map[string]bool) |
|
|
|
|
|
|
|
for _, ticker := range self.profile.Tickers { |
|
|
|
|
|
|
|
existing[ticker] = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, ticker := range tickers { |
|
|
|
|
|
|
|
if _, found := existing[ticker]; !found { |
|
|
|
|
|
|
|
self.profile.Tickers = append(self.profile.Tickers, ticker) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sort.Strings(self.profile.Tickers) |
|
|
|
|
|
|
|
self.profile.Save() |
|
|
|
|
|
|
|
DrawQuotes(self.profile.Quotes()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func (self *LineEditor) remove_tickers(tickers []string) { |
|
|
|
func (self *LineEditor) tokenize() []string { |
|
|
|
|
|
|
|
input := strings.ToUpper(strings.TrimSpace(self.input)) |
|
|
|
|
|
|
|
return regexp.MustCompile(`[,\s]+`).Split(input, -1) |
|
|
|
} |
|
|
|
} |
|
|
|