-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
103 lines (88 loc) · 2.32 KB
/
config.go
File metadata and controls
103 lines (88 loc) · 2.32 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"time"
"github.com/BurntSushi/toml"
"github.com/vhodges/flexstatus/widgets"
)
type widgetconfig struct {
Widget []widget
}
// defines a widget. Must contain a superset of fields a widget can have
type widget struct {
Kind string
Template string
Filename string
Sleep int64
Exec string
Command string
Args []string
DateFormat string
Value string
}
func get_widgets(filename string) []widgets.Widget {
active := make([]widgets.Widget, 0)
var conf widgetconfig
_, err := toml.DecodeFile(filename, &conf)
if err != nil {
fmt.Println(err)
return default_widgets(active)
}
for i := range conf.Widget {
w := conf.Widget[i]
switch w.Kind {
case "Desktop":
active = append(active, &widgets.Desktop{
BaseWidget: widgets.BaseWidget{Template: w.Template},
})
case "Clock":
active = append(active, &widgets.Clock{
BaseWidget: widgets.BaseWidget{Template: w.Template},
DateFormat: w.DateFormat,
Millis: time.Duration(w.Sleep),
})
case "PollCommand":
active = append(active, &widgets.Poller{
BaseWidget: widgets.BaseWidget{Template: w.Template},
Exec: w.Exec,
Command: w.Command,
Args: w.Args,
Millis: time.Duration(w.Sleep),
})
case "PollFile":
active = append(active, &widgets.Poller{
BaseWidget: widgets.BaseWidget{Template: w.Template},
Filename: w.Filename,
Millis: time.Duration(w.Sleep),
})
case "StreamCommand":
active = append(active, &widgets.Streamer{
BaseWidget: widgets.BaseWidget{Template: w.Template},
Exec: w.Exec,
Command: w.Command,
Args: w.Args,
})
case "StreamFile":
active = append(active, &widgets.Streamer{
BaseWidget: widgets.BaseWidget{Template: w.Template},
Filename: w.Filename,
})
case "Text":
active = append(active, &widgets.Text{
BaseWidget: widgets.BaseWidget{Template: w.Value},
})
}
}
return active
}
func default_widgets(active []widgets.Widget) []widgets.Widget {
active = append(active, &widgets.Clock{
BaseWidget: widgets.BaseWidget{Template: "{{.FormattedDateTime}} :: "},
DateFormat: "Mon 2 Jan, 15:04",
Millis: 1000,
})
active = append(active, &widgets.Text{
BaseWidget: widgets.BaseWidget{Template: "flexstatus v0.1.0"},
})
return active
}