-
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
4 changed files
with
58 additions
and
54 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
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,52 @@ | ||
package i3status | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type BaseWidget struct { | ||
Output chan Message | ||
Input chan Entry | ||
Refresh time.Duration | ||
Instance int | ||
} | ||
|
||
func (w *BaseWidget) SetChannels(out chan Message, in chan Entry) { | ||
w.Output = out | ||
w.Input = in | ||
} | ||
|
||
func NewBaseWidget() *BaseWidget { | ||
instanceCount++ | ||
w := BaseWidget{ | ||
Output: nil, | ||
Input: nil, | ||
Refresh: 1000, | ||
Instance: instanceCount, | ||
} | ||
return &w | ||
} | ||
|
||
func (w *BaseWidget) basicLoop() { | ||
msg := NewMessage() | ||
msg.FullText = "Basic Widget" | ||
msg.Name = "Basic" | ||
msg.Color = "#ffffff" | ||
msg.Instance = strconv.Itoa(w.Instance) | ||
for { | ||
w.Output <- *msg | ||
time.Sleep(w.Refresh * time.Millisecond) | ||
} | ||
} | ||
|
||
func (w *BaseWidget) readLoop() { | ||
for { | ||
<-w.Input | ||
} | ||
} | ||
|
||
func (w *BaseWidget) Start() { | ||
go w.basicLoop() | ||
go w.readLoop() | ||
} |
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 |
---|---|---|
@@ -1,54 +1,8 @@ | ||
package i3status | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type BaseWidget struct { | ||
Output chan Message | ||
Input chan Entry | ||
Refresh time.Duration | ||
Instance int | ||
type Widget interface { | ||
Start() | ||
SetChannels(chan Message, chan Entry) | ||
} | ||
|
||
var instanceCount int | ||
|
||
func (w *BaseWidget) SetChannels(out chan Message, in chan Entry) { | ||
w.Output = out | ||
w.Input = in | ||
} | ||
|
||
func NewBaseWidget() *BaseWidget { | ||
instanceCount++ | ||
w := BaseWidget{ | ||
Output: nil, | ||
Input: nil, | ||
Refresh: 1000, | ||
Instance: instanceCount, | ||
} | ||
return &w | ||
} | ||
|
||
func (w *BaseWidget) basicLoop() { | ||
msg := NewMessage() | ||
msg.FullText = "Basic Widget" | ||
msg.Name = "Basic" | ||
msg.Color = "#ffffff" | ||
msg.Instance = strconv.Itoa(w.Instance) | ||
for { | ||
w.Output <- *msg | ||
time.Sleep(w.Refresh * time.Millisecond) | ||
} | ||
} | ||
|
||
func (w *BaseWidget) readLoop() { | ||
for { | ||
<-w.Input | ||
} | ||
} | ||
|
||
func (w *BaseWidget) Start() { | ||
go w.basicLoop() | ||
go w.readLoop() | ||
} |
File renamed without changes.