Compare commits

2 Commits

Author SHA1 Message Date
28abd79961 bump version 2023-12-07 13:46:34 +01:00
dd14e7ec35 don't show shortcuts in help (clutters it) 2023-12-07 13:43:45 +01:00
3 changed files with 25 additions and 29 deletions

36
calc.go
View File

@@ -261,7 +261,7 @@ func (c *Calc) Eval(line string) {
continue
}
if exists(c.Funcalls, item) {
if _, ok := c.Funcalls[item]; ok {
if err := c.DoFuncall(item); err != nil {
fmt.Println(err)
} else {
@@ -270,18 +270,20 @@ func (c *Calc) Eval(line string) {
continue
}
if exists(c.BatchFuncalls, item) {
if !c.batch {
if c.batch {
if _, ok := c.BatchFuncalls[item]; ok {
if err := c.DoFuncall(item); err != nil {
fmt.Println(err)
} else {
c.Result()
}
continue
}
} else {
if _, ok := c.BatchFuncalls[item]; ok {
fmt.Println("only supported in batch mode")
continue
}
if err := c.DoFuncall(item); err != nil {
fmt.Println(err)
} else {
c.Result()
}
continue
}
if contains(c.LuaFunctions, item) {
@@ -302,22 +304,22 @@ func (c *Calc) Eval(line string) {
}
// internal commands
if exists(c.Commands, item) {
if _, ok := c.Commands[item]; ok {
c.Commands[item].Func(c)
continue
}
if exists(c.ShowCommands, item) {
if _, ok := c.ShowCommands[item]; ok {
c.ShowCommands[item].Func(c)
continue
}
if exists(c.StackCommands, item) {
if _, ok := c.StackCommands[item]; ok {
c.StackCommands[item].Func(c)
continue
}
if exists(c.SettingsCommands, item) {
if _, ok := c.SettingsCommands[item]; ok {
c.SettingsCommands[item].Func(c)
continue
}
@@ -505,7 +507,7 @@ func (c *Calc) PutVar(name string) {
}
func (c *Calc) GetVar(name string) {
if exists(c.Vars, name) {
if _, ok := c.Vars[name]; ok {
c.Debug(fmt.Sprintf("retrieve %.2f from %s", c.Vars[name], name))
c.stack.Backup()
c.stack.Push(c.Vars[name])
@@ -518,7 +520,9 @@ func sortcommands(hash Commands) []string {
keys := make([]string, 0, len(hash))
for key := range hash {
keys = append(keys, key)
if len(key) > 1 {
keys = append(keys, key)
}
}
sort.Strings(keys)

View File

@@ -30,7 +30,7 @@ import (
lua "github.com/yuin/gopher-lua"
)
const VERSION string = "2.0.11"
const VERSION string = "2.0.12"
const Usage string = `This is rpn, a reverse polish notation calculator cli.

16
util.go
View File

@@ -23,24 +23,16 @@ import (
"strings"
)
// find an item in a list, generic variant
func contains[E comparable](s []E, v E) bool {
for _, vs := range s {
if v == vs {
// find an item in a list
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// look if a key in a map exists, generic variant
func exists[K comparable, V any](m map[K]V, v K) bool {
if _, ok := m[v]; ok {
return true
}
return false
}
func const2num(name string) float64 {
switch name {
case "Pi":