add: wait command

This commit is contained in:
ShuheiKubota 2019-11-18 14:48:49 +09:00
parent a2d2db8027
commit 9f185f8fb2
2 changed files with 48 additions and 0 deletions

47
cmd_wait.go Normal file
View file

@ -0,0 +1,47 @@
package main
import (
"errors"
"strings"
"time"
"github.com/shu-go/gli"
)
type waitCmd struct {
_ struct{} `help:"[--wait] {Title}"`
Closed bool
Intervals gli.Duration `cli:"intervals,i=DURATION" default:"1s"`
}
func (c waitCmd) Run(args []string) error {
if len(args) != 1 {
return errors.New("not one target")
}
an := ancestors()
t := strings.ToLower(args[0])
for {
wins, err := listAllWindows()
if err != nil {
return err
}
win := findFirstTarget(t, wins, an)
if c.Closed {
if win == nil {
break
}
} else {
if win != nil {
break
}
}
time.Sleep(c.Intervals.Duration())
}
return nil
}

View file

@ -33,6 +33,7 @@ type globalCmd struct {
Resize resizeCmd `cli:"resize,move,mv" help:"resize/move"`
Alpha alphaCmd `cli:"alpha" help:"set alpha 0%(transparent) - 100%(opaque)"`
Topmost topmostCmd `cli:"topmost" help:"set always on top/restore"`
Wait waitCmd `cli:"wait"`
targetHandle syscall.Handle