Skip to content

Commit

Permalink
Added executeCommand action
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 19, 2019
1 parent 0da9260 commit aeb60d5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions deck.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"fmt"
"log"
"os/exec"
"strings"
)

type Deck struct {
Expand All @@ -24,6 +26,15 @@ func LoadDeck(deck string) (*Deck, error) {
return &d, nil
}

// executes a command
func executeCommand(cmd string) {
args := strings.Split(cmd, " ")
c := exec.Command(args[0], args[1:]...)
if err := c.Start(); err != nil {
panic(err)
}
}

func (d *Deck) triggerAction(index uint8) {
for _, w := range d.Widgets {
if w.Key() == index {
Expand All @@ -43,6 +54,9 @@ func (d *Deck) triggerAction(index uint8) {
deck = d
deck.updateWidgets()
}
if a.Exec != "" {
executeCommand(a.Exec)
}
} else {
w.TriggerAction()
}
Expand Down

0 comments on commit aeb60d5

Please sign in to comment.