Skip to content

Commit

Permalink
feat: right aligned optional text lines
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Feb 14, 2021
1 parent d78c022 commit fb09ef1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
51 changes: 38 additions & 13 deletions internal/ui/component/watchlist/watchlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func extraInfoExchange(show bool, q Quote, targetCurrency string, width int) str
return "\n" + Line(
width,
Cell{
Text: tagText(currencyText) + " " + tagText(exchangeDelayText(q.ExchangeDelay)) + " " + tagText(q.ExchangeName),
Align: RightAlign,
Text: tagText(currencyText) + " " + tagText(exchangeDelayText(q.ExchangeDelay)) + " " + tagText(q.ExchangeName),
},
)
}
Expand All @@ -146,15 +147,28 @@ func extraInfoFundamentals(show bool, q Quote, width int) string {
return "\n" + Line(
width,
Cell{
Width: 25,
Text: StyleNeutralFaded("Prev Close: ") + StyleNeutral(ConvertFloatToString(q.RegularMarketPreviousClose)),
Text: dayRangeText(q.RegularMarketDayRange),
Align: RightAlign,
},
Cell{
Width: 20,
Text: StyleNeutralFaded("Open: ") + StyleNeutral(ConvertFloatToString(q.RegularMarketOpen)),
Width: 15,
Text: StyleNeutralFaded("Prev Close: "),
Align: RightAlign,
},
Cell{
Text: dayRangeText(q.RegularMarketDayRange),
Width: 10,
Text: StyleNeutral(ConvertFloatToString(q.RegularMarketPreviousClose)),
Align: RightAlign,
},
Cell{
Width: 15,
Text: StyleNeutralFaded("Open: "),
Align: RightAlign,
},
Cell{
Width: 10,
Text: StyleNeutral(ConvertFloatToString(q.RegularMarketOpen)),
Align: RightAlign,
},
)
}
Expand All @@ -167,21 +181,32 @@ func extraInfoHoldings(show bool, p Position, width int) string {
return "\n" + Line(
width,
Cell{
Text: "",
Text: StyleNeutralFaded("Weight: "),
Align: RightAlign,
},
Cell{
Width: 7,
Text: StyleNeutral(ConvertFloatToString(p.Weight)) + "%",
Align: RightAlign,
},
Cell{
Width: 15,
Text: StyleNeutralFaded("Avg. Cost: "),
Align: RightAlign,
},
Cell{
Width: 25,
Text: StyleNeutralFaded("Weight: ") + StyleNeutral(ConvertFloatToString(p.Weight)) + "%",
Width: 10,
Text: StyleNeutral(ConvertFloatToString(p.AverageCost)),
Align: RightAlign,
},
Cell{
Width: 25,
Text: StyleNeutralFaded("Avg. Cost: ") + StyleNeutral(ConvertFloatToString(p.AverageCost)),
Width: 15,
Text: StyleNeutralFaded("Quantity: "),
Align: RightAlign,
},
Cell{
Width: 25,
Text: StyleNeutralFaded("Quantity: ") + StyleNeutral(ConvertFloatToString(p.Quantity)),
Width: 10,
Text: StyleNeutral(ConvertFloatToString(p.Quantity)),
Align: RightAlign,
},
)
Expand Down
12 changes: 6 additions & 6 deletions internal/ui/component/watchlist/watchlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"BTC-USD ● 50000.00",
"Bitcoin ↑ 10000.00 (20.00%)",
" USD Real-Time Cryptocurrency ",
" USD Real-Time Cryptocurrency ",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down Expand Up @@ -401,7 +401,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"BTC-USD ● 50000.00",
"Bitcoin ↑ 10000.00 (20.00%)",
" USD Delayed 15min Cryptocurrency ",
" USD Delayed 15min Cryptocurrency ",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down Expand Up @@ -435,7 +435,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"APPL ● 5000.00",
"Apple, Inc ↑ 1000.00 (20.00%)",
" USD → EUR Real-Time NASDAQ ",
" USD → EUR Real-Time NASDAQ ",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down Expand Up @@ -472,7 +472,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"BTC-USD ● 50000.00",
"Bitcoin ↑ 10000.00 (20.00%)",
"Prev Close: 10000.00 Open: 10000.00 Day Range: 10000 - 10000 ",
" Day Range: 10000 - 10000 Prev Close: 10000.00 Open: 10000.00",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down Expand Up @@ -505,7 +505,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"BTC-USD ● 50000.00",
"Bitcoin ↑ 10000.00 (20.00%)",
"Prev Close: 10000.00 Open: 10000.00 ",
" Prev Close: 10000.00 Open: 10000.00",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down Expand Up @@ -550,7 +550,7 @@ var _ = Describe("Watchlist", func() {
expected := strings.Join([]string{
"PTON ● 105.00 100.00",
"Peloton ↑ 55.00 (110.00%) ↑ 10.00 (10.00%)",
" Weight: 0.00% Avg. Cost: 0.00 Quantity: 100.00",
" Weight: 0.00% Avg. Cost: 0.00 Quantity: 100.00",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})
Expand Down

0 comments on commit fb09ef1

Please sign in to comment.