-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclark.go
More file actions
54 lines (44 loc) · 1.22 KB
/
clark.go
File metadata and controls
54 lines (44 loc) · 1.22 KB
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
/*
clark is a daemon implementing the i3bar protocol.
*/
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/jameswelchman/clark/clarkio"
"github.com/jameswelchman/clark/conf"
"github.com/jameswelchman/clark/protocol"
)
func main() {
// Hold our channels
// clickChannels is a map where the keys are block name/instance
// the values are the click channels which the individual packages
// may listen on.
clickChannels := map[string]chan<- *protocol.Click{}
blockChannels := []<-chan *protocol.Block{}
// Build the channels
for _, block := range conf.AllBlocks {
c := make(chan *protocol.Click, 4)
b := make(chan *protocol.Block, 4)
key := block.Name + "_" + block.Instance
clickChannels[key] = c
blockChannels = append(blockChannels, b)
go clarkio.RunBlock(block.Run, c, b)
}
// Start listening on stdin
go func() {
clarkio.ReadClicks(os.Stdin, clickChannels)
fmt.Fprintln(os.Stderr, "routine listening on stdin closed")
}()
// Start wrting on stdout
go func() {
clarkio.WriteBlocks(os.Stdout, blockChannels)
fmt.Fprintln(os.Stderr, "routine writing on stdout closed")
}()
// Run until we get a SIGINT
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT)
<-sigs
}