-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added summary of all positions i.e. totals
- Loading branch information
1 parent
f406226
commit fc8ba9f
Showing
9 changed files
with
223 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package summary | ||
|
||
import ( | ||
"strings" | ||
"ticker/internal/position" | ||
. "ticker/internal/ui/util" | ||
) | ||
|
||
type Model struct { | ||
Width int | ||
Summary position.PositionSummary | ||
} | ||
|
||
// NewModel returns a model with default values. | ||
func NewModel() Model { | ||
return Model{ | ||
Width: 80, | ||
} | ||
} | ||
|
||
func (m Model) View() string { | ||
|
||
if m.Width < 80 { | ||
return "" | ||
} | ||
|
||
return strings.Join([]string{ | ||
StyleNeutralFaded("Day:"), | ||
quoteChangeText(m.Summary.DayChange, m.Summary.DayChangePercent), | ||
StyleNeutralFaded("•"), | ||
StyleNeutralFaded("Change:"), | ||
quoteChangeText(m.Summary.Change, m.Summary.ChangePercent), | ||
StyleNeutralFaded("•"), | ||
StyleNeutralFaded("Value:"), | ||
ValueText(m.Summary.Value), | ||
}, " ") + "\n" + StyleLine(strings.Repeat("━", m.Width)) | ||
|
||
} | ||
|
||
func quoteChangeText(change float64, changePercent float64) string { | ||
if change == 0.0 { | ||
return StyleNeutralFaded(ConvertFloatToString(change) + " (" + ConvertFloatToString(changePercent) + "%)") | ||
} | ||
|
||
if change > 0.0 { | ||
return StylePricePositive(changePercent)("↑ " + ConvertFloatToString(change) + " (" + ConvertFloatToString(changePercent) + "%)") | ||
} | ||
|
||
return StylePriceNegative(changePercent)("↓ " + ConvertFloatToString(change) + " (" + ConvertFloatToString(changePercent) + "%)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package summary_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/format" | ||
) | ||
|
||
func TestSummary(t *testing.T) { | ||
format.TruncatedDiff = false | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Summary Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package summary_test | ||
|
||
import ( | ||
"strings" | ||
"ticker/internal/position" | ||
. "ticker/internal/ui/component/summary" | ||
|
||
"github.com/acarl005/stripansi" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func removeFormatting(text string) string { | ||
return stripansi.Strip(text) | ||
} | ||
|
||
var _ = Describe("Summary", func() { | ||
|
||
It("should render a summary", func() { | ||
m := NewModel() | ||
m.Summary = position.PositionSummary{ | ||
Value: 10000, | ||
Cost: 1000, | ||
Change: 9000, | ||
DayChange: 100.0, | ||
ChangePercent: 1000.0, | ||
DayChangePercent: 10.0, | ||
} | ||
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{ | ||
"Day: ↑ 100.00 (10.00%) • Change: ↑ 9000.00 (1000.00%) • Value: 10000.00", | ||
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", | ||
}, "\n"))) | ||
}) | ||
|
||
When("no quotes are set", func() { | ||
It("should render an empty summary", func() { | ||
m := NewModel() | ||
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{ | ||
"Day: 0.00 (0.00%) • Change: 0.00 (0.00%) • Value: ", | ||
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━", | ||
}, "\n"))) | ||
}) | ||
}) | ||
|
||
When("the window width is less than the minimum", func() { | ||
It("should render an empty summary", func() { | ||
m := NewModel() | ||
m.Width = 10 | ||
Expect(m.View()).To(Equal("")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.