Skip to content

Commit

Permalink
docs: added docs for ui, summary, watchlist, format, style, and http
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Aug 14, 2021
1 parent 90fc63b commit 5890bbd
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 105 deletions.
16 changes: 9 additions & 7 deletions internal/ui/component/summary/summary.go
Expand Up @@ -7,25 +7,27 @@ import (
c "github.com/achannarasappa/ticker/internal/common"
"github.com/achannarasappa/ticker/internal/position"

. "github.com/achannarasappa/ticker/internal/ui/util"
u "github.com/achannarasappa/ticker/internal/ui/util"
"github.com/muesli/reflow/ansi"
)

// Model for summary section
type Model struct {
Width int
Summary position.PositionSummary
Context c.Context
styles c.Styles
}

// NewModel returns a model with default values.
// NewModel returns a model with default values
func NewModel(ctx c.Context) Model {
return Model{
Width: 80,
styles: ctx.Reference.Styles,
}
}

// View rendering hook for bubbletea
func (m Model) View() string {

if m.Width < 80 {
Expand All @@ -37,10 +39,10 @@ func (m Model) View() string {
m.styles.TextLabel("Change: ") + quoteChangeText(m.Summary.Change, m.Summary.ChangePercent, m.styles)
widthChange := ansi.PrintableRuneWidth(textChange)
textValue := m.styles.TextLabel(" • ") +
m.styles.TextLabel("Value: ") + ValueText(m.Summary.Value, m.styles)
m.styles.TextLabel("Value: ") + u.ValueText(m.Summary.Value, m.styles)
widthValue := ansi.PrintableRuneWidth(textValue)
textCost := m.styles.TextLabel(" • ") +
m.styles.TextLabel("Cost: ") + ValueText(m.Summary.Cost, m.styles)
m.styles.TextLabel("Cost: ") + u.ValueText(m.Summary.Cost, m.styles)
widthCost := ansi.PrintableRuneWidth(textValue)

return grid.Render(grid.Grid{
Expand Down Expand Up @@ -78,12 +80,12 @@ func (m Model) View() string {

func quoteChangeText(change float64, changePercent float64, styles c.Styles) string {
if change == 0.0 {
return styles.TextLabel(ConvertFloatToString(change, false) + " (" + ConvertFloatToString(changePercent, false) + "%)")
return styles.TextLabel(u.ConvertFloatToString(change, false) + " (" + u.ConvertFloatToString(changePercent, false) + "%)")
}

if change > 0.0 {
return styles.TextPrice(changePercent, "↑ "+ConvertFloatToString(change, false)+" ("+ConvertFloatToString(changePercent, false)+"%)")
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
}

return styles.TextPrice(changePercent, "↓ "+ConvertFloatToString(change, false)+" ("+ConvertFloatToString(changePercent, false)+"%)")
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
}

0 comments on commit 5890bbd

Please sign in to comment.