diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-10-04 13:56:56 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-10-04 13:56:56 -0400 |
| commit | 6817d5861986084f55785842b07639f7aeaacf0a (patch) | |
| tree | 5cbe9f9867dbea5df99f168f6c350a84e58f11cd /ui.go | |
| parent | bc774798c0805af43558cf61152a65772fc8bbc6 (diff) | |
| download | pfc-6817d5861986084f55785842b07639f7aeaacf0a.zip | |
accept e-notation
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -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) |