Skip to content

Commit

Permalink
calc: add 'require_number' option, defaults to true
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Nov 14, 2024
1 parent f326a4c commit de1fe36
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.10-git
0.8.10
1 change: 1 addition & 0 deletions internal/config/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"show_generic": false
},
"calc": {
"require_number": true,
"weight": 5,
"name": "calc",
"icon": "accessories-calculator",
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Builtins struct {

type Calc struct {
GeneralModule `mapstructure:",squash"`
RequireNumber bool `mapstructure:"require_number"`
}

type CustomCommands struct {
Expand Down
19 changes: 17 additions & 2 deletions internal/modules/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import (
"log"
"os/exec"
"strings"
"unicode"

"github.com/abenz1267/walker/internal/config"
"github.com/abenz1267/walker/internal/util"
)

type Calc struct {
general config.GeneralModule
hasClip bool
general config.GeneralModule
requireNumber bool
hasClip bool
}

func (c *Calc) General() *config.GeneralModule {
Expand All @@ -35,6 +37,7 @@ func (c *Calc) Setup(cfg *config.Config) bool {

c.general = cfg.Builtins.Calc.GeneralModule
c.general.IsSetup = true
c.requireNumber = cfg.Builtins.Calc.RequireNumber

// to update exchange rates
cmd := exec.Command("qalc", "-e", "1+1")
Expand All @@ -46,6 +49,18 @@ func (c *Calc) Setup(cfg *config.Config) bool {
func (c *Calc) SetupData(cfg *config.Config, ctx context.Context) {}

func (c Calc) Entries(ctx context.Context, term string) []util.Entry {
hasNumber := false

for _, c := range term {
if unicode.IsDigit(c) {
hasNumber = true
}
}

if !hasNumber {
return []util.Entry{}
}

entries := []util.Entry{}

cmd := exec.Command("qalc", "-t", term)
Expand Down

0 comments on commit de1fe36

Please sign in to comment.