aboutsummaryrefslogtreecommitdiffstats
path: root/ui.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-07-29 10:29:15 -0230
committerSam Anthony <sam@samanthony.xyz>2023-07-29 10:29:15 -0230
commit5b81647c27af77be3d35e10cb53cad1897a7f392 (patch)
tree0d6aab66a9675500b6df449ace25fadb612c86d4 /ui.go
parentfd46878cfa5978a081f1ffdb865394aff234dbc9 (diff)
downloadpfc-5b81647c27af77be3d35e10cb53cad1897a7f392.zip
negation command
Diffstat (limited to 'ui.go')
-rw-r--r--ui.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/ui.go b/ui.go
index 6596b77..85919c4 100644
--- a/ui.go
+++ b/ui.go
@@ -44,6 +44,8 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "C":
ui.calc.buf = ""
ui.calc.stack = ui.calc.stack[:0]
+ case "N":
+ ui.calc.negate()
case "+", "-", "*", "/", "%", "^":
if err := ui.calc.performOp(msg.String()[0]); err != nil {
panic(err)
@@ -71,7 +73,7 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (ui UI) View() string {
var s string
for _, f := range ui.calc.stack {
- s += printStackVal(f) + "\n"
+ s += printNum(f) + "\n"
}
s += boxTop(ui.windowWidth) + "\n"
s += fmt.Sprintf("%[1]c%-*s%[1]c\n", boxVertical, ui.windowWidth-2, ui.calc.buf)
@@ -79,7 +81,7 @@ func (ui UI) View() string {
return s
}
-func printStackVal(v float64) string {
+func printNum(v float64) string {
return fmt.Sprintf(" %.*g", sigDigs, v)
}