-
Notifications
You must be signed in to change notification settings - Fork 16
/
example_test.go
55 lines (47 loc) · 1.1 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package i3_test
import (
"fmt"
"log"
"strings"
"go.i3wm.org/i3/v4"
)
func ExampleIsUnsuccessful() {
cr, err := i3.RunCommand("norp")
// “norp” is not implemented, so this command is expected to fail.
if err != nil && !i3.IsUnsuccessful(err) {
log.Fatal(err)
}
log.Printf("error for norp: %v", cr[0].Error)
}
func ExampleSubscribe() {
recv := i3.Subscribe(i3.WindowEventType)
for recv.Next() {
ev := recv.Event().(*i3.WindowEvent)
log.Printf("change: %s", ev.Change)
}
log.Fatal(recv.Close())
}
func ExampleGetTree() {
// Focus or start Google Chrome on the focused workspace.
tree, err := i3.GetTree()
if err != nil {
log.Fatal(err)
}
ws := tree.Root.FindFocused(func(n *i3.Node) bool {
return n.Type == i3.WorkspaceNode
})
if ws == nil {
log.Fatalf("could not locate workspace")
}
chrome := ws.FindChild(func(n *i3.Node) bool {
return strings.HasSuffix(n.Name, "- Google Chrome")
})
if chrome != nil {
_, err = i3.RunCommand(fmt.Sprintf(`[con_id="%d"] focus`, chrome.ID))
} else {
_, err = i3.RunCommand(`exec google-chrome`)
}
if err != nil {
log.Fatal(err)
}
}