1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

The /wtf directory is now in source control

This commit is contained in:
Chris Cummer 2018-04-02 08:43:42 -07:00 committed by Chris Cummer
parent 0b8a063487
commit 176a821079
4 changed files with 70 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
DS_Store
gcal/client_secret.json
wtf

16
wtf/base_widget.go Normal file
View File

@ -0,0 +1,16 @@
package wtf
import (
//"fmt"
"time"
)
type BaseWidget struct {
Name string
RefreshedAt time.Time
RefreshInt int
}
func (widget *BaseWidget) RefreshInterval() int {
return widget.RefreshInt
}

25
wtf/refresher.go Normal file
View File

@ -0,0 +1,25 @@
package wtf
import (
"time"
)
type Refresher interface {
Refresh()
RefreshInterval() int
}
func Refresh(widget Refresher) {
tick := time.NewTicker(time.Duration(widget.RefreshInterval()) * time.Second)
quit := make(chan struct{})
for {
select {
case <-tick.C:
widget.Refresh()
case <-quit:
tick.Stop()
return
}
}
}

29
wtf/utils.go Normal file
View File

@ -0,0 +1,29 @@
package wtf
import (
"fmt"
"io/ioutil"
"os/exec"
)
func CenterText(str string, width int) string {
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
}
func ExecuteCommand(cmd *exec.Cmd) string {
stdout, err := cmd.StdoutPipe()
if err != nil {
return fmt.Sprintf("A: %v\n", err)
}
if err := cmd.Start(); err != nil {
return fmt.Sprintf("B: %v\n", err)
}
var str string
if b, err := ioutil.ReadAll(stdout); err == nil {
str += string(b)
}
return str
}