diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-07-22 22:17:32 -0230 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-07-22 22:17:32 -0230 |
| commit | a1e02a94f69f06af62af137212da1534c460c756 (patch) | |
| tree | 5d39f503c235ad40d1b86e5cf76fb4970d9e889a /ui.go | |
| parent | 4e17a27eb8d36868bcf7e1edf32affd84412a1f4 (diff) | |
| download | pfc-a1e02a94f69f06af62af137212da1534c460c756.zip | |
ui skeleton
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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 +} |