From 6817d5861986084f55785842b07639f7aeaacf0a Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Sat, 4 Oct 2025 13:56:56 -0400 Subject: accept e-notation --- ui.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'ui.go') diff --git a/ui.go b/ui.go index cea51e7..02f2bb1 100644 --- a/ui.go +++ b/ui.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "github.com/charmbracelet/bubbletea" ) @@ -52,9 +53,22 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { ui.calc.angleMode = !ui.calc.angleMode case "N": ui.calc.negate() - case "+", "-", "*", "/", "%", "^": - operator := msg.String()[0] - ui.calc.performOperation(operator) + case "+", "-": + if isENotation(ui.calc.buf) { + ui.calc.buf += msg.String() + } else { + op, err := parseOperator(msg.String()[0]) + if err != nil { + panic(err) + } + ui.calc.operate(op) + } + case "*", "/", "%", "^": + op, err := parseOperator(msg.String()[0]) + if err != nil { + panic(err) + } + ui.calc.operate(op) case "backspace": if len(ui.calc.buf) > 0 { ui.calc.buf = ui.calc.buf[:len(ui.calc.buf)-1] @@ -75,6 +89,10 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return ui, nil } +func isENotation(s string) bool { + return strings.ContainsRune(s, 'e') +} + func (ui UI) View() string { s := padding(ui) -- cgit v1.2.3