Skip to content

Commit

Permalink
Added scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Dec 27, 2020
1 parent ab9f14d commit 27f33b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ func main() {
"ESTC",
"ARKW",
"BTC-USD",
"NIO",
"GME",
"CMPS",
}

p := tea.NewProgram(ui.NewModel(symbols, quote.GetQuotes))

p.EnableMouseCellMotion()
p.EnterAltScreen()
err := p.Start()
p.ExitAltScreen()
p.DisableMouseCellMotion()

if err != nil {
log.Fatal(err)
Expand Down
6 changes: 3 additions & 3 deletions internal/ui/component/watchlist/watchlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var (
styleNeutral = util.NewStyle("#d4d4d4", "", false)
styleNeutralBold = util.NewStyle("#d4d4d4", "", true)
styleNeutralFaded = util.NewStyle("#616161", "", false)
stylePricePositive = newStyleFromGradient("#cae891", "#adff00")
stylePriceNegative = newStyleFromGradient("#f5a07d", "#ff5200")
stylePricePositive = newStyleFromGradient("#D8FF80", "#75BF00")
stylePriceNegative = newStyleFromGradient("#FFA780", "#BF3900")
)

const (
Expand Down Expand Up @@ -138,7 +138,7 @@ func newStyleFromGradient(startColorHex string, endColorHex string) func(float64
func getNormalizedPercentWithMax(percent float64, maxPercent float64) float64 {

absolutePercent := math.Abs(percent)
if absolutePercent > maxPercent {
if absolutePercent >= maxPercent {
return 1.0
}
return math.Abs(percent / maxPercent)
Expand Down
18 changes: 7 additions & 11 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ func NewModel(symbols []string, requestQuotes func([]string) []quote.Quote) Mode
}
}

// func temp(symbols []string) []quote.Quote {
// return []quote.Quote{
// {Symbol: "AAPL", ShortName: "Apple, Inc.", RegularMarketPrice: 1000.1, RegularMarketChange: 10.1, RegularMarketChangePercent: 1.1},
// {Symbol: "ABNB", ShortName: "AirBnB, Inc.", RegularMarketPrice: 645.1, RegularMarketChange: 4.1, RegularMarketChangePercent: 0.9},
// }
// }

func (m Model) Init() tea.Cmd {
m.watchlist = watchlist.NewModel()
return func() tea.Msg {
Expand All @@ -68,8 +61,9 @@ type QuoteMsg struct {
quotes []quote.Quote
}

func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {
switch msg := message.(type) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch msg := msg.(type) {

case tea.KeyMsg:
switch msg.String() {
Expand Down Expand Up @@ -105,6 +99,8 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) {

}

m.viewport, _ = m.viewport.Update(msg)

return m, nil
}

Expand All @@ -113,10 +109,10 @@ func (m Model) View() string {
return "\n Initalizing..."
}

return fmt.Sprintf("%s\n%s", m.viewport.View(), footer(m.viewport.Width))
return fmt.Sprintf("%s\n%s", m.viewport.View(), footer())
}

func footer(elementWidth int) string {
func footer() string {
return footerHighlightStyle(" 🚀 ticker-tape ") + helpStyle(" q: exit")
}

Expand Down

0 comments on commit 27f33b3

Please sign in to comment.