diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2023-07-29 10:20:07 -0230 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2023-07-29 10:20:07 -0230 |
| commit | a253229dbbef5e09449884febacdfbbd4de85d6d (patch) | |
| tree | 471552d43293a856d73aa8a08692b3bca7724dc3 /ui.go | |
| parent | 545f618f333a8e4d5d9c38266e14574eef542fcb (diff) | |
| download | pfc-a253229dbbef5e09449884febacdfbbd4de85d6d.zip | |
swap command
Diffstat (limited to 'ui.go')
| -rw-r--r-- | ui.go | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -37,6 +37,8 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg.String() { case "ctrl+c", "Q": return ui, tea.Quit + case "J", "K": + ui.calc.swap() case "+", "-", "*", "/", "%", "^": if err := ui.calc.performOp(msg.String()[0]); err != nil { panic(err) @@ -64,7 +66,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 += printStackVal(f) + "\n" } s += boxTop(ui.windowWidth) + "\n" s += fmt.Sprintf("%[1]c%-*s%[1]c\n", boxVertical, ui.windowWidth-2, ui.calc.buf) @@ -72,6 +74,10 @@ func (ui UI) View() string { return s } +func printStackVal(v float64) string { + return fmt.Sprintf(" %.*g", sigDigs, v) +} + // boxTop returns the top of a UTF-8 box, 'width' characters wide (including // corners). func boxTop(width int) string { |