aboutsummaryrefslogtreecommitdiffstats
path: root/ui.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2023-07-22 22:17:32 -0230
committerSam Anthony <sam@samanthony.xyz>2023-07-22 22:17:32 -0230
commita1e02a94f69f06af62af137212da1534c460c756 (patch)
tree5d39f503c235ad40d1b86e5cf76fb4970d9e889a /ui.go
parent4e17a27eb8d36868bcf7e1edf32affd84412a1f4 (diff)
downloadpfc-a1e02a94f69f06af62af137212da1534c460c756.zip
ui skeleton
Diffstat (limited to 'ui.go')
-rw-r--r--ui.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/ui.go b/ui.go
new file mode 100644
index 0000000..03286ec
--- /dev/null
+++ b/ui.go
@@ -0,0 +1,48 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/charmbracelet/bubbletea"
+)
+
+// Types
+
+type UI struct {
+ calc Calculator
+ windowWidth int // Width of the window measured in characters.
+}
+
+// Interface Implementations
+
+func (ui UI) Init() tea.Cmd {
+ return nil
+}
+
+func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
+ switch msg := msg.(type) {
+ case tea.WindowSizeMsg:
+ ui.windowWidth = msg.Width
+ case tea.KeyMsg:
+ switch msg.String() {
+ case "ctrl+c", "q":
+ return ui, tea.Quit
+ }
+ }
+ return ui, nil
+}
+
+func (ui UI) View() string {
+ var s string
+ for _, f := range ui.calc.stack {
+ s += fmt.Sprintf("%f\n", f)
+ }
+ horizBar := make([]byte, ui.windowWidth)
+ for i := range horizBar {
+ horizBar[i] = '-'
+ }
+ s += string(horizBar) + "\n"
+ s += fmt.Sprintf("| %*s |\n", ui.windowWidth-4, ui.calc.buffer)
+ s += string(horizBar)
+ return s
+}