-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package i3status | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type Entry struct { | ||
Name string `json:"name"` | ||
Instance string `json:"instance"` | ||
Button int `json:"button"` | ||
X int `json:"x"` | ||
Y int `json:"y"` | ||
} | ||
|
||
func NewEntry(str string) *Entry { | ||
var e Entry | ||
json.Unmarshal([]byte(str), &e) | ||
return &e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package i3status | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type OnOffWidget struct { | ||
BaseWidget | ||
Input chan Entry | ||
} | ||
|
||
func NewOnOffWidget(output chan Message, input chan Entry) *OnOffWidget { | ||
instanceCount++ | ||
w := OnOffWidget{ | ||
BaseWidget{ | ||
output, | ||
1000, | ||
instanceCount, | ||
}, | ||
input, | ||
} | ||
return &w | ||
} | ||
|
||
func (w *OnOffWidget) basicLoop() { | ||
msg := NewMessage() | ||
msg.Name = "Date" | ||
msg.Color = "#ffffff" | ||
msg.Instance = strconv.Itoa(w.Instance) | ||
for { | ||
msg.FullText = fmt.Sprintf("%s", time.Now()) | ||
w.Output <- *msg | ||
time.Sleep(w.Refresh * time.Millisecond) | ||
} | ||
} | ||
func (w *OnOffWidget) Start() { | ||
go w.basicLoop() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package i3status_test | ||
|
||
import ( | ||
"github.com/ghedamat/go-i3status/i3status" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"testing" | ||
) | ||
|
||
func TestEntry(t *testing.T) { | ||
Convey("Given a json string", t, func() { | ||
str := `{ | ||
"name": "ethernet", | ||
"instance": "eth0", | ||
"button": 1, | ||
"x": 1320, | ||
"y": 1400 | ||
}` | ||
Convey("When NewEntry is called", func() { | ||
e := i3status.NewEntry(str) | ||
Convey("a new Entry is created", func() { | ||
So(e.Name, ShouldEqual, "ethernet") | ||
So(e.Instance, ShouldEqual, "eth0") | ||
So(e.Button, ShouldEqual, 1) | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package i3status_test | ||
|
||
import ( | ||
"github.com/ghedamat/go-i3status/i3status" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"testing" | ||
) | ||
|
||
func TestOnOffWidgetConstructor(t *testing.T) { | ||
Convey("Given an input and an output channel", t, func() { | ||
c := make(chan i3status.Message) | ||
i := make(chan i3status.Entry) | ||
Convey("When OnOff is created", func() { | ||
w := i3status.NewOnOffWidget(c, i) | ||
Convey("input and output channel are available", func() { | ||
So(w.Input, ShouldEqual, i) | ||
So(w.Output, ShouldEqual, c) | ||
}) | ||
}) | ||
}) | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters