aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--calculator.go10
-rw-r--r--ui.go16
2 files changed, 13 insertions, 13 deletions
diff --git a/calculator.go b/calculator.go
index 30cc7ec..08193b4 100644
--- a/calculator.go
+++ b/calculator.go
@@ -5,8 +5,8 @@ import "strconv"
type Stack []float64
type Calculator struct {
- stack Stack
- buffer string
+ stack Stack
+ buf string
}
// add performs addition when the user inputs the '+' operator.
@@ -14,13 +14,13 @@ func (c *Calculator) add() {
if len(c.stack) < 1 {
return
}
- if con := parseConstant(c.buffer); con != nil {
+ if con := parseConstant(c.buf); con != nil {
c.stack[len(c.stack)-1] += *con
- } else if f, err := strconv.ParseFloat(c.buffer, 64); err == nil {
+ } else if f, err := strconv.ParseFloat(c.buf, 64); err == nil {
c.stack[len(c.stack)-1] += f
} else if len(c.stack) > 1 {
c.stack[len(c.stack)-2] += c.stack[len(c.stack)-1]
c.stack = c.stack[:len(c.stack)-1]
}
- c.buffer = ""
+ c.buf = ""
}
diff --git a/ui.go b/ui.go
index e32d20f..931e8a5 100644
--- a/ui.go
+++ b/ui.go
@@ -40,20 +40,20 @@ func (ui UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "+":
ui.calc.add()
case "backspace":
- if len(ui.calc.buffer) > 0 {
- ui.calc.buffer = ui.calc.buffer[:len(ui.calc.buffer)-1]
+ if len(ui.calc.buf) > 0 {
+ ui.calc.buf = ui.calc.buf[:len(ui.calc.buf)-1]
}
case "enter":
- if fn := parseFunction(ui.calc.buffer); fn != nil {
+ if fn := parseFunction(ui.calc.buf); fn != nil {
fn(ui.calc.stack)
- } else if con := parseConstant(ui.calc.buffer); con != nil {
+ } else if con := parseConstant(ui.calc.buf); con != nil {
ui.calc.stack = append(ui.calc.stack, *con)
- } else if f, err := strconv.ParseFloat(ui.calc.buffer, 64); err == nil {
+ } else if f, err := strconv.ParseFloat(ui.calc.buf, 64); err == nil {
ui.calc.stack = append(ui.calc.stack, f)
}
- ui.calc.buffer = ""
+ ui.calc.buf = ""
default:
- ui.calc.buffer += msg.String()
+ ui.calc.buf += msg.String()
}
}
return ui, nil
@@ -65,7 +65,7 @@ func (ui UI) View() string {
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)
+ s += fmt.Sprintf("%[1]c%-*s%[1]c\n", boxVertical, ui.windowWidth-2, ui.calc.buf)
s += boxBottom(ui.windowWidth)
return s
}