aboutsummaryrefslogtreecommitdiffstats
path: root/ui.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-07-23 12:24:32 -0230
committerSam Anthony <sam@samanthony.xyz>2023-07-23 12:24:32 -0230
commit3951f8c09b3f49253cf0d354df708069223d0316 (patch)
tree6392fad888bfde768008c83b58dd1575f6c87f9f /ui.go
parent4a585fba1ac08cd9f184627a4a8b781d0b52efcb (diff)
downloadpfc-3951f8c09b3f49253cf0d354df708069223d0316.zip
constant and function parsing skeleton
Diffstat (limited to 'ui.go')
-rw-r--r--ui.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/ui.go b/ui.go
index 2768c43..886b4c3 100644
--- a/ui.go
+++ b/ui.go
@@ -2,6 +2,7 @@ package main
import (
"fmt"
+ "strconv"
"github.com/charmbracelet/bubbletea"
)
@@ -40,6 +41,15 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if len(ui.calc.buffer) > 0 {
ui.calc.buffer = ui.calc.buffer[:len(ui.calc.buffer)-1]
}
+ case "enter":
+ if fn := parseFunction(ui.calc.buffer); fn != nil {
+ fn(ui.calc.stack)
+ } else if con := parseConstant(ui.calc.buffer); con != nil {
+ ui.calc.stack = append(ui.calc.stack, *con)
+ } else if f, err := strconv.ParseFloat(ui.calc.buffer, 64); err != nil {
+ ui.calc.stack = append(ui.calc.stack, f)
+ }
+ ui.calc.buffer = ""
default:
ui.calc.buffer += msg.String()
}
@@ -50,7 +60,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 += fmt.Sprintf("%.*g\n", sigDigs, f)
+ s += fmt.Sprintf(" %.*g\n", sigDigs, f)
}
s += boxTop(ui.windowWidth) + "\n"
s += fmt.Sprintf("%[1]c%-*s%[1]c\n", boxVertical, ui.windowWidth-2, ui.calc.buffer)