Skip to content

Commit

Permalink
+ show command
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas von Dein committed Nov 6, 2023
1 parent 16cfc5f commit 8e9eeda
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Calc struct {
const Help string = `Available commands:
batch toggle batch mode
debug toggle debug output
show show the last 5 items of the stack
dump display the stack contents
clear clear the whole stack
shift remove the last element of the stack
Expand Down Expand Up @@ -82,7 +83,7 @@ median median of all values`
// commands, constants and operators, defined here to feed completion
// and our mode switch in Eval() dynamically
const (
Commands string = `dump reverse debug undebug clear batch shift undo help history manual exit quit swap`
Commands string = `dump reverse debug undebug clear batch shift undo help history manual exit quit swap show`
Constants string = `Pi Phi Sqrt2 SqrtE SqrtPi SqrtPhi Ln2 Log2E Ln10 Log10E`
)

Expand Down Expand Up @@ -163,6 +164,10 @@ func (c *Calc) ToggleStdin() {
c.stdin = !c.stdin
}

func (c *Calc) ToggleShow() {
c.showstack = !c.showstack
}

func (c *Calc) Prompt() string {
p := "\033[31m»\033[0m "
b := ""
Expand Down Expand Up @@ -275,6 +280,8 @@ func (c *Calc) Eval(line string) {
for _, entry := range c.history {
fmt.Println(entry)
}
case "show":
c.ToggleShow()
case "exit":
fallthrough
case "quit":
Expand Down

0 comments on commit 8e9eeda

Please sign in to comment.