From 4f9e220638ea62443db25d252c4e12ede2c7f9c5 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sun, 1 Oct 2023 20:02:22 -0400 Subject: error handling and tidying --- ui.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'ui.go') diff --git a/ui.go b/ui.go index 46f748e..d98577a 100644 --- a/ui.go +++ b/ui.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strconv" "github.com/charmbracelet/bubbletea" ) @@ -54,7 +53,8 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "N": ui.calc.negate() case "+", "-", "*", "/", "%", "^": - if err := ui.calc.performOp(msg.String()[0]); err != nil { + operator := msg.String()[0] + if err := ui.calc.performOperation(operator); err != nil { panic(err) } case "backspace": @@ -64,10 +64,8 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "enter": if fn := parseFunction(ui.calc.buf); fn != nil { fn(ui.calc) - } else if con := parseConstant(ui.calc.buf); con != nil { - ui.calc.stack.push(*con) - } else if f, err := strconv.ParseFloat(ui.calc.buf, 64); err == nil { - ui.calc.stack.push(f) + } else if v, err := ui.calc.parseBuffer(); err == nil { + ui.calc.stack.push(v) } ui.calc.buf = "" default: -- cgit v1.2.3