diff options
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) |