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

Move the utils.go file into the /utils directory

This commit is contained in:
Chris Cummer 2019-08-05 10:50:12 -07:00
parent 0bd2d176d8
commit 4e46fff145
57 changed files with 190 additions and 188 deletions

View File

@ -3,6 +3,7 @@ package app
import ( import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
@ -45,8 +46,8 @@ func (display *Display) add(widget wtf.Wtfable) {
} }
func (display *Display) build(widgets []wtf.Wtfable) *tview.Grid { func (display *Display) build(widgets []wtf.Wtfable) *tview.Grid {
cols := wtf.ToInts(display.config.UList("wtf.grid.columns")) cols := utils.ToInts(display.config.UList("wtf.grid.columns"))
rows := wtf.ToInts(display.config.UList("wtf.grid.rows")) rows := utils.ToInts(display.config.UList("wtf.grid.rows"))
display.Grid.SetColumns(cols...) display.Grid.SetColumns(cols...)
display.Grid.SetRows(rows...) display.Grid.SetRows(rows...)

View File

@ -18,7 +18,7 @@ import (
"github.com/wtfutil/wtf/app" "github.com/wtfutil/wtf/app"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/flags" "github.com/wtfutil/wtf/flags"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
var tviewApp *tview.Application var tviewApp *tview.Application
@ -62,7 +62,7 @@ func main() {
defer profile.Start(profile.MemProfile).Stop() defer profile.Start(profile.MemProfile).Stop()
} }
wtf.Init(config.UString("wtf.openFileUtil", "open")) utils.Init(config.UString("wtf.openFileUtil", "open"))
setTerm(config) setTerm(config)

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
@ -49,7 +50,7 @@ func (widget *Widget) Refresh() {
func (widget *Widget) contentFrom(items []Item) string { func (widget *Widget) contentFrom(items []Item) string {
if len(items) == 0 { if len(items) == 0 {
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 50)) return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
} }
str := "" str := ""

View File

@ -3,7 +3,7 @@ package clocks
import ( import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const defaultTitle = "Clocks" const defaultTitle = "Clocks"
@ -30,8 +30,8 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
settings := Settings{ settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
dateFormat: ymlConfig.UString("dateFormat", wtf.SimpleDateFormat), dateFormat: ymlConfig.UString("dateFormat", utils.SimpleDateFormat),
timeFormat: ymlConfig.UString("timeFormat", wtf.SimpleTimeFormat), timeFormat: ymlConfig.UString("timeFormat", utils.SimpleTimeFormat),
locations: ymlConfig.UMap("locations"), locations: ymlConfig.UMap("locations"),
sort: ymlConfig.UString("sort"), sort: ymlConfig.UString("sort"),
} }

View File

@ -3,7 +3,7 @@ package cmdrunner
import ( import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const defaultTitle = "CmdRunner" const defaultTitle = "CmdRunner"
@ -20,7 +20,7 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig
settings := Settings{ settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, moduleConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, moduleConfig, globalConfig),
args: wtf.ToStrs(moduleConfig.UList("args")), args: utils.ToStrs(moduleConfig.UList("args")),
cmd: moduleConfig.UString("cmd"), cmd: moduleConfig.UString("cmd"),
} }

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -61,5 +61,5 @@ func (widget *Widget) String() string {
func (widget *Widget) execute() string { func (widget *Widget) execute() string {
cmd := exec.Command(widget.cmd, widget.args...) cmd := exec.Command(widget.cmd, widget.args...)
return wtf.ExecuteCommand(cmd) return utils.ExecuteCommand(cmd)
} }

View File

@ -1,7 +1,7 @@
package datadog package datadog
import ( import (
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
datadog "github.com/zorkian/go-datadog-api" datadog "github.com/zorkian/go-datadog-api"
) )
@ -12,7 +12,7 @@ func (widget *Widget) Monitors() ([]datadog.Monitor, error) {
widget.settings.applicationKey, widget.settings.applicationKey,
) )
tags := wtf.ToStrs(widget.settings.tags) tags := utils.ToStrs(widget.settings.tags)
monitors, err := client.GetMonitorsByTags(tags) monitors, err := client.GetMonitorsByTags(tags)
if err != nil { if err != nil {

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
datadog "github.com/zorkian/go-datadog-api" datadog "github.com/zorkian/go-datadog-api"
) )
@ -84,7 +84,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string {
*triggeredMonitor.Name, *triggeredMonitor.Name,
widget.RowColor(idx), widget.RowColor(idx),
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name)) str += utils.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name))
} }
} else { } else {
str += fmt.Sprintf( str += fmt.Sprintf(
@ -101,6 +101,6 @@ func (widget *Widget) openItem() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.monitors != nil && sel < len(widget.monitors) { if sel >= 0 && widget.monitors != nil && sel < len(widget.monitors) {
item := &widget.monitors[sel] item := &widget.monitors[sel]
wtf.OpenFile(fmt.Sprintf("https://app.datadoghq.com/monitors/%d?q=*", *item.Id)) utils.OpenFile(fmt.Sprintf("https://app.datadoghq.com/monitors/%d?q=*", *item.Id))
} }
} }

View File

@ -3,7 +3,7 @@ package feedreader
import ( import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const ( const (
@ -23,7 +23,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
settings := &Settings{ settings := &Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
feeds: wtf.ToStrs(ymlConfig.UList("feeds")), feeds: utils.ToStrs(ymlConfig.UList("feeds")),
feedLimit: ymlConfig.UInt("feedLimit", -1), feedLimit: ymlConfig.UInt("feedLimit", -1),
} }

View File

@ -7,8 +7,8 @@ import (
"github.com/mmcdole/gofeed" "github.com/mmcdole/gofeed"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
const ( const (
@ -144,7 +144,7 @@ func (widget *Widget) contentFrom(data []*FeedItem) string {
feedItem.item.Title, feedItem.item.Title,
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(feedItem.item.Title)) str += utils.HighlightableHelper(widget.View, row, idx, len(feedItem.item.Title))
} }
return str return str
@ -169,6 +169,6 @@ func (widget *Widget) openStory() {
story := widget.stories[sel] story := widget.stories[sel]
story.viewed = true story.viewed = true
wtf.OpenFile(story.item.Link) utils.OpenFile(story.item.Link)
} }
} }

View File

@ -3,7 +3,7 @@ package gcal
import ( import (
"time" "time"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
"google.golang.org/api/calendar/v3" "google.golang.org/api/calendar/v3"
) )
@ -100,9 +100,9 @@ func (calEvent *CalEvent) Start() time.Time {
func (calEvent *CalEvent) Timestamp() string { func (calEvent *CalEvent) Timestamp() string {
if calEvent.AllDay() { if calEvent.AllDay() {
startTime, _ := time.ParseInLocation("2006-01-02", calEvent.event.Start.Date, time.Local) startTime, _ := time.ParseInLocation("2006-01-02", calEvent.event.Start.Date, time.Local)
return startTime.Format(wtf.FriendlyDateFormat) return startTime.Format(utils.FriendlyDateFormat)
} }
startTime, _ := time.Parse(time.RFC3339, calEvent.event.Start.DateTime) startTime, _ := time.Parse(time.RFC3339, calEvent.event.Start.DateTime)
return startTime.Format(wtf.MinimumTimeFormat) return startTime.Format(utils.MinimumTimeFormat)
} }

View File

@ -6,7 +6,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) { func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) {
@ -98,7 +98,7 @@ func (widget *Widget) dayDivider(event, prevEvent *CalEvent) string {
return fmt.Sprintf("[%s::b]", return fmt.Sprintf("[%s::b]",
widget.settings.colors.day) + widget.settings.colors.day) +
event.Start().Format(wtf.FullDateFormat) + event.Start().Format(utils.FullDateFormat) +
"\n" "\n"
} }
@ -169,7 +169,7 @@ func (widget *Widget) titleColor(calEvent *CalEvent) string {
color := widget.settings.colors.title color := widget.settings.colors.title
for _, untypedArr := range widget.settings.highlights { for _, untypedArr := range widget.settings.highlights {
highlightElements := wtf.ToStrs(untypedArr.([]interface{})) highlightElements := utils.ToStrs(untypedArr.([]interface{}))
match, _ := regexp.MatchString( match, _ := regexp.MatchString(
strings.ToLower(highlightElements[0]), strings.ToLower(highlightElements[0]),

View File

@ -8,8 +8,8 @@ import (
glb "github.com/andygrunwald/go-gerrit" glb "github.com/andygrunwald/go-gerrit"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -146,7 +146,7 @@ func (widget *Widget) openReview() {
} else { } else {
change = project.OutgoingReviews[sel-len(project.IncomingReviews)] change = project.OutgoingReviews[sel-len(project.IncomingReviews)]
} }
wtf.OpenFile(fmt.Sprintf("%s/%s/%d", widget.settings.domain, "#/c", change.Number)) utils.OpenFile(fmt.Sprintf("%s/%s/%d", widget.settings.domain, "#/c", change.Number))
} }
} }

View File

@ -5,7 +5,7 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
type GitRepo struct { type GitRepo struct {
@ -33,7 +33,7 @@ func (repo *GitRepo) branch() string {
arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--abbrev-ref", "HEAD"} arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--abbrev-ref", "HEAD"}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }
@ -42,7 +42,7 @@ func (repo *GitRepo) changedFiles() []string {
arg := []string{repo.gitDir(), repo.workTree(), "status", "--porcelain"} arg := []string{repo.gitDir(), repo.workTree(), "status", "--porcelain"}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
data := strings.Split(str, "\n") data := strings.Split(str, "\n")
@ -57,7 +57,7 @@ func (repo *GitRepo) commits(commitCount int, commitFormat, dateFormat string) [
arg := []string{repo.gitDir(), repo.workTree(), "log", dateStr, numStr, commitStr} arg := []string{repo.gitDir(), repo.workTree(), "log", dateStr, numStr, commitStr}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
data := strings.Split(str, "\n") data := strings.Split(str, "\n")
@ -67,21 +67,21 @@ func (repo *GitRepo) commits(commitCount int, commitFormat, dateFormat string) [
func (repo *GitRepo) repository() string { func (repo *GitRepo) repository() string {
arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--show-toplevel"} arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--show-toplevel"}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }
func (repo *GitRepo) pull() string { func (repo *GitRepo) pull() string {
arg := []string{repo.gitDir(), repo.workTree(), "pull"} arg := []string{repo.gitDir(), repo.workTree(), "pull"}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }
func (repo *GitRepo) checkout(branch string) string { func (repo *GitRepo) checkout(branch string) string {
arg := []string{repo.gitDir(), repo.workTree(), "checkout", branch} arg := []string{repo.gitDir(), repo.workTree(), "checkout", branch}
cmd := exec.Command("git", arg...) cmd := exec.Command("git", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }

View File

@ -8,8 +8,8 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
const offscreen = -1000 const offscreen = -1000
@ -76,7 +76,7 @@ func (widget *Widget) Pull() {
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
repoPaths := wtf.ToStrs(widget.settings.repositories) repoPaths := utils.ToStrs(widget.settings.repositories)
widget.GitRepos = widget.gitRepos(repoPaths) widget.GitRepos = widget.gitRepos(repoPaths)
sort.Slice(widget.GitRepos, func(i, j int) bool { sort.Slice(widget.GitRepos, func(i, j int) bool {

View File

@ -6,7 +6,7 @@ import (
"net/http" "net/http"
ghb "github.com/google/go-github/v26/github" ghb "github.com/google/go-github/v26/github"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -35,7 +35,7 @@ func NewGithubRepo(name, owner, apiKey, baseURL, uploadURL string) *GithubRepo {
} }
func (repo *GithubRepo) Open() { func (repo *GithubRepo) Open() {
wtf.OpenFile(*repo.RemoteRepo.HTMLURL) utils.OpenFile(*repo.RemoteRepo.HTMLURL)
} }
// Refresh reloads the github data via the Github API // Refresh reloads the github data via the Github API

View File

@ -6,7 +6,7 @@ import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const defaultTitle = "GitHub" const defaultTitle = "GitHub"
@ -57,7 +57,7 @@ func parseRepositories(ymlConfig *config.Config) []string {
return result return result
} }
result = wtf.ToStrs(ymlConfig.UList("repositories")) result = utils.ToStrs(ymlConfig.UList("repositories"))
return result return result
} }

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// A Widget represents a Gitter widget // A Widget represents a Gitter widget
@ -94,7 +94,7 @@ func (widget *Widget) contentFrom(messages []Message) string {
message.Sent.Format("Jan 02, 15:04 MST"), message.Sent.Format("Jan 02, 15:04 MST"),
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(message.Text)) str += utils.HighlightableHelper(widget.View, row, idx, len(message.Text))
} }
return str return str
@ -104,6 +104,6 @@ func (widget *Widget) openMessage() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.messages != nil && sel < len(widget.messages) { if sel >= 0 && widget.messages != nil && sel < len(widget.messages) {
message := &widget.messages[sel] message := &widget.messages[sel]
wtf.OpenFile(message.Text) utils.OpenFile(message.Text)
} }
} }

View File

@ -19,7 +19,6 @@ import (
"strings" "strings"
"github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"golang.org/x/oauth2/google" "golang.org/x/oauth2/google"
sheets "google.golang.org/api/sheets/v4" sheets "google.golang.org/api/sheets/v4"
@ -52,7 +51,7 @@ func (widget *Widget) Fetch() ([]*sheets.ValueRange, error) {
return nil, err return nil, err
} }
cells := wtf.ToStrs(widget.settings.cellAddresses) cells := utils.ToStrs(widget.settings.cellAddresses)
addresses := strings.Join(cells[:], ";") addresses := strings.Join(cells[:], ";")
responses := make([]*sheets.ValueRange, len(cells)) responses := make([]*sheets.ValueRange, len(cells))

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
sheets "google.golang.org/api/sheets/v4" sheets "google.golang.org/api/sheets/v4"
) )
@ -42,7 +42,7 @@ func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string {
res := "" res := ""
cells := wtf.ToStrs(widget.settings.cellNames) cells := utils.ToStrs(widget.settings.cellNames)
for i := 0; i < len(valueRanges); i++ { for i := 0; i < len(valueRanges); i++ {
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0]) res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, valueRanges[i].Values[0][0])
} }

View File

@ -6,8 +6,8 @@ import (
"strings" "strings"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -91,7 +91,7 @@ func (widget *Widget) contentFrom(stories []Story) string {
strings.TrimPrefix(u.Host, "www."), strings.TrimPrefix(u.Host, "www."),
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(story.Title)) str += utils.HighlightableHelper(widget.View, row, idx, len(story.Title))
} }
return str return str
@ -101,7 +101,7 @@ func (widget *Widget) openStory() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.stories != nil && sel < len(widget.stories) { if sel >= 0 && widget.stories != nil && sel < len(widget.stories) {
story := &widget.stories[sel] story := &widget.stories[sel]
wtf.OpenFile(story.URL) utils.OpenFile(story.URL)
} }
} }
@ -109,6 +109,6 @@ func (widget *Widget) openComments() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.stories != nil && sel < len(widget.stories) { if sel >= 0 && widget.stories != nil && sel < len(widget.stories) {
story := &widget.stories[sel] story := &widget.stories[sel]
wtf.OpenFile(fmt.Sprintf("https://news.ycombinator.com/item?id=%d", story.ID)) utils.OpenFile(fmt.Sprintf("https://news.ycombinator.com/item?id=%d", story.ID))
} }
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const ( const (
@ -34,7 +34,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig),
apiKey: ymlConfig.UString("apiKey", ""), apiKey: ymlConfig.UString("apiKey", ""),
accounts: wtf.ToStrs(ymlConfig.UList("accounts")), accounts: utils.ToStrs(ymlConfig.UList("accounts")),
since: ymlConfig.UString("since", ""), since: ymlConfig.UString("since", ""),
} }

View File

@ -5,8 +5,8 @@ import (
"regexp" "regexp"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -83,7 +83,7 @@ func (widget *Widget) contentFrom(view *View) string {
job.Name, job.Name,
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(job.Name)) str += utils.HighlightableHelper(widget.View, row, idx, len(job.Name))
} }
} }
@ -106,6 +106,6 @@ func (widget *Widget) openJob() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.view != nil && sel < len(widget.view.Jobs) { if sel >= 0 && widget.view != nil && sel < len(widget.view.Jobs) {
job := &widget.view.Jobs[sel] job := &widget.view.Jobs[sel]
wtf.OpenFile(job.Url) utils.OpenFile(job.Url)
} }
} }

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -68,7 +68,7 @@ func (widget *Widget) openItem() {
sel := widget.GetSelected() sel := widget.GetSelected()
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) { if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {
issue := &widget.result.Issues[sel] issue := &widget.result.Issues[sel]
wtf.OpenFile(widget.settings.domain + "/browse/" + issue.Key) utils.OpenFile(widget.settings.domain + "/browse/" + issue.Key)
} }
} }
@ -87,7 +87,7 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
issue.IssueFields.Summary, issue.IssueFields.Summary,
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary)) str += utils.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary))
} }
return str return str

View File

@ -7,7 +7,7 @@ import (
"path" "path"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
type MercurialRepo struct { type MercurialRepo struct {
@ -37,7 +37,7 @@ func (repo *MercurialRepo) branch() string {
arg := []string{"branch", repo.repoPath()} arg := []string{"branch", repo.repoPath()}
cmd := exec.Command("hg", arg...) cmd := exec.Command("hg", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }
@ -54,7 +54,7 @@ func (repo *MercurialRepo) changedFiles() []string {
arg := []string{"status", repo.repoPath()} arg := []string{"status", repo.repoPath()}
cmd := exec.Command("hg", arg...) cmd := exec.Command("hg", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
data := strings.Split(str, "\n") data := strings.Split(str, "\n")
@ -68,7 +68,7 @@ func (repo *MercurialRepo) commits(commitCount int, commitFormat string) []strin
arg := []string{"log", repo.repoPath(), numStr, commitStr} arg := []string{"log", repo.repoPath(), numStr, commitStr}
cmd := exec.Command("hg", arg...) cmd := exec.Command("hg", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
data := strings.Split(str, "\n") data := strings.Split(str, "\n")
@ -78,14 +78,14 @@ func (repo *MercurialRepo) commits(commitCount int, commitFormat string) []strin
func (repo *MercurialRepo) pull() string { func (repo *MercurialRepo) pull() string {
arg := []string{"pull", repo.repoPath()} arg := []string{"pull", repo.repoPath()}
cmd := exec.Command("hg", arg...) cmd := exec.Command("hg", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }
func (repo *MercurialRepo) checkout(branch string) string { func (repo *MercurialRepo) checkout(branch string) string {
arg := []string{"checkout", repo.repoPath(), branch} arg := []string{"checkout", repo.repoPath(), branch}
cmd := exec.Command("hg", arg...) cmd := exec.Command("hg", arg...)
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return str return str
} }

View File

@ -3,8 +3,8 @@ package mercurial
import ( import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
const offscreen = -1000 const offscreen = -1000
@ -73,7 +73,7 @@ func (widget *Widget) Pull() {
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
repoPaths := wtf.ToStrs(widget.settings.repositories) repoPaths := utils.ToStrs(widget.settings.repositories)
widget.Data = widget.mercurialRepos(repoPaths) widget.Data = widget.mercurialRepos(repoPaths)

View File

@ -9,8 +9,8 @@ import (
"time" "time"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// A Widget represents an NBA Score widget // A Widget represents an NBA Score widget
@ -79,7 +79,7 @@ func (widget *Widget) nbascore() string {
result := map[string]interface{}{} result := map[string]interface{}{}
json.Unmarshal(contents, &result) json.Unmarshal(contents, &result)
allGame := "" // store result in allgame allGame := "" // store result in allgame
allGame += (" " + "[red]" + (cur.Format(wtf.FriendlyDateFormat) + "\n\n") + "[white]") allGame += (" " + "[red]" + (cur.Format(utils.FriendlyDateFormat) + "\n\n") + "[white]")
for _, game := range result["games"].([]interface{}) { for _, game := range result["games"].([]interface{}) {
vTeam, hTeam, vScore, hScore := "", "", "", "" vTeam, hTeam, vScore, hScore := "", "", "", ""
quarter := 0. quarter := 0.

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
nr "github.com/yfronto/newrelic" nr "github.com/yfronto/newrelic"
@ -63,7 +64,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
revisions := []string{} revisions := []string{}
for _, deploy := range deploys { for _, deploy := range deploys {
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) { if (deploy.Revision != "") && utils.Exclude(revisions, deploy.Revision) {
lineColor := "white" lineColor := "white"
if wtf.IsToday(deploy.Timestamp) { if wtf.IsToday(deploy.Timestamp) {
lineColor = "lightblue" lineColor = "lightblue"
@ -79,7 +80,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string {
deploy.Revision[0:revLen], deploy.Revision[0:revLen],
lineColor, lineColor,
deploy.Timestamp.Format("Jan 02 15:04 MST"), deploy.Timestamp.Format("Jan 02 15:04 MST"),
wtf.NameFromEmail(deploy.User), utils.NameFromEmail(deploy.User),
) )
revisions = append(revisions, deploy.Revision) revisions = append(revisions, deploy.Revision)

View File

@ -5,8 +5,8 @@ import (
"strings" "strings"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -59,7 +59,7 @@ func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string {
if len(data.OnCallData.Recipients) == 0 { if len(data.OnCallData.Recipients) == 0 {
msg = " [gray]no one[white]\n\n" msg = " [gray]no one[white]\n\n"
} else { } else {
msg = fmt.Sprintf(" %s\n\n", strings.Join(wtf.NamesFromEmails(data.OnCallData.Recipients), ", ")) msg = fmt.Sprintf(" %s\n\n", strings.Join(utils.NamesFromEmails(data.OnCallData.Recipients), ", "))
} }
str += widget.cleanScheduleName(data.OnCallData.Parent.Name) str += widget.cleanScheduleName(data.OnCallData.Parent.Name)

View File

@ -6,8 +6,8 @@ import (
"github.com/PagerDuty/go-pagerduty" "github.com/PagerDuty/go-pagerduty"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -40,7 +40,7 @@ func (widget *Widget) Refresh() {
} }
if widget.settings.showSchedules { if widget.settings.showSchedules {
scheduleIDs := wtf.ToStrs(widget.settings.scheduleIDs) scheduleIDs := utils.ToStrs(widget.settings.scheduleIDs)
onCalls, err1 = GetOnCalls(widget.settings.apiKey, scheduleIDs) onCalls, err1 = GetOnCalls(widget.settings.apiKey, scheduleIDs)
} }

View File

@ -9,7 +9,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const TimeRegExp = "^(?:\\d|[01]\\d|2[0-3]):[0-5]\\d" const TimeRegExp = "^(?:\\d|[01]\\d|2[0-3]):[0-5]\\d"
@ -47,7 +47,7 @@ func (battery *Battery) String() string {
func (battery *Battery) execute() string { func (battery *Battery) execute() string {
cmd := exec.Command(battery.cmd, battery.args...) cmd := exec.Command(battery.cmd, battery.args...)
return wtf.ExecuteCommand(cmd) return utils.ExecuteCommand(cmd)
} }
func (battery *Battery) parse(data string) string { func (battery *Battery) parse(data string) string {

View File

@ -8,7 +8,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
var batteryState string var batteryState string
@ -41,7 +41,7 @@ func (battery *Battery) String() string {
func (battery *Battery) execute() string { func (battery *Battery) execute() string {
cmd := exec.Command("upower", "-e") cmd := exec.Command("upower", "-e")
lines := strings.Split(wtf.ExecuteCommand(cmd), "\n") lines := strings.Split(utils.ExecuteCommand(cmd), "\n")
var target string var target string
for _, l := range lines { for _, l := range lines {
if strings.Contains(l, "/battery") { if strings.Contains(l, "/battery") {
@ -50,7 +50,7 @@ func (battery *Battery) execute() string {
} }
} }
cmd = exec.Command("upower", "-i", target) cmd = exec.Command("upower", "-i", target)
return wtf.ExecuteCommand(cmd) return utils.ExecuteCommand(cmd)
} }
func (battery *Battery) parse(data string) string { func (battery *Battery) parse(data string) string {

View File

@ -7,7 +7,7 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const SingleQuotesRegExp = "'(.*)'" const SingleQuotesRegExp = "'(.*)'"
@ -16,7 +16,7 @@ const SingleQuotesRegExp = "'(.*)'"
// "AC Power" or "Battery Power" // "AC Power" or "Battery Power"
func powerSource() string { func powerSource() string {
cmd := exec.Command("pmset", []string{"-g", "ps"}...) cmd := exec.Command("pmset", []string{"-g", "ps"}...)
result := wtf.ExecuteCommand(cmd) result := utils.ExecuteCommand(cmd)
r, _ := regexp.Compile(SingleQuotesRegExp) r, _ := regexp.Compile(SingleQuotesRegExp)

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// A Widget represents a Rollbar widget // A Widget represents a Rollbar widget
@ -91,7 +91,7 @@ func (widget *Widget) contentFrom(result *Result) string {
"blue", "blue",
item.Environment, item.Environment,
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(item.Title)) str += utils.HighlightableHelper(widget.View, row, idx, len(item.Title))
} }
return str return str
@ -124,7 +124,7 @@ func (widget *Widget) openBuild() {
if widget.GetSelected() >= 0 && widget.items != nil && widget.GetSelected() < len(widget.items.Items) { if widget.GetSelected() >= 0 && widget.items != nil && widget.GetSelected() < len(widget.items.Items) {
item := &widget.items.Items[widget.GetSelected()] item := &widget.items.Items[widget.GetSelected()]
wtf.OpenFile( utils.OpenFile(
fmt.Sprintf( fmt.Sprintf(
"https://rollbar.com/%s/%s/%s/%d", "https://rollbar.com/%s/%s/%s/%d",
widget.settings.projectOwner, widget.settings.projectOwner,

View File

@ -5,7 +5,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
@ -28,7 +28,7 @@ func DnsServers() []string {
func dnsLinux() []string { func dnsLinux() []string {
// This may be very Ubuntu specific // This may be very Ubuntu specific
cmd := exec.Command("nmcli", "device", "show") cmd := exec.Command("nmcli", "device", "show")
out := wtf.ExecuteCommand(cmd) out := utils.ExecuteCommand(cmd)
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
@ -46,7 +46,7 @@ func dnsLinux() []string {
func dnsMacOS() []string { func dnsMacOS() []string {
cmdString := `scutil --dns | head -n 7 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'` cmdString := `scutil --dns | head -n 7 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
cmd := exec.Command("sh", "-c", cmdString) cmd := exec.Command("sh", "-c", cmdString)
out := wtf.ExecuteCommand(cmd) out := utils.ExecuteCommand(cmd)
lines := strings.Split(out, "\n") lines := strings.Split(out, "\n")
@ -61,5 +61,5 @@ func dnsWindows() []string {
cmd := exec.Command("powershell.exe", "-NoProfile", "Get-DnsClientServerAddress | Select-Object ExpandProperty ServerAddresses") cmd := exec.Command("powershell.exe", "-NoProfile", "Get-DnsClientServerAddress | Select-Object ExpandProperty ServerAddresses")
return []string{wtf.ExecuteCommand(cmd)} return []string{utils.ExecuteCommand(cmd)}
} }

View File

@ -7,7 +7,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw" const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw"
@ -66,35 +66,35 @@ func firewallStateLinux() string { // might be very Ubuntu specific
func firewallStateMacOS() string { func firewallStateMacOS() string {
cmd := exec.Command(osxFirewallCmd, "--getglobalstate") cmd := exec.Command(osxFirewallCmd, "--getglobalstate")
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return statusLabel(str) return statusLabel(str)
} }
func firewallStateWindows() string { func firewallStateWindows() string {
// The raw way to do this in PS, not using netsh, nor registry, is the following: // The raw way to do this in PS, not using netsh, nor registry, is the following:
// if (((Get-NetFirewallProfile | select name,enabled) // if (((Get-NetFirewallProfile | select name,enabled)
// | where { $_.Enabled -eq $True } | measure ).Count -eq 3) // | where { $_.Enabled -eq $True } | measure ).Count -eq 3)
// { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red } // { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red }
cmd := exec.Command("powershell.exe", "-NoProfile", cmd := exec.Command("powershell.exe", "-NoProfile",
"-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }") "-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }")
fwStat := wtf.ExecuteCommand(cmd) fwStat := utils.ExecuteCommand(cmd)
fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n" fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n"
//fmt.Printf("%d %q\n", len(fwStat), fwStat) //fmt.Printf("%d %q\n", len(fwStat), fwStat)
switch fwStat { switch fwStat {
case "3": case "3":
return "[green]Good[white] (3/3)" return "[green]Good[white] (3/3)"
case "2": case "2":
return "[orange]Poor[white] (2/3)" return "[orange]Poor[white] (2/3)"
case "1": case "1":
return "[yellow]Bad[white] (1/3)" return "[yellow]Bad[white] (1/3)"
case "0": case "0":
return "[red]Disabled[white]" return "[red]Disabled[white]"
default: default:
return "[white]N/A[white]" return "[white]N/A[white]"
} }
} }
@ -107,7 +107,7 @@ func firewallStealthStateLinux() string {
func firewallStealthStateMacOS() string { func firewallStealthStateMacOS() string {
cmd := exec.Command(osxFirewallCmd, "--getstealthmode") cmd := exec.Command(osxFirewallCmd, "--getstealthmode")
str := wtf.ExecuteCommand(cmd) str := utils.ExecuteCommand(cmd)
return statusLabel(str) return statusLabel(str)
} }
@ -116,7 +116,6 @@ func firewallStealthStateWindows() string {
return "[white]N/A[white]" return "[white]N/A[white]"
} }
func statusLabel(str string) string { func statusLabel(str string) string {
label := "off" label := "off"

View File

@ -7,7 +7,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
@ -51,7 +51,7 @@ func cleanUsers(users []string) []string {
func loggedInUsersLinux() []string { func loggedInUsersLinux() []string {
cmd := exec.Command("who", "-us") cmd := exec.Command("who", "-us")
users := wtf.ExecuteCommand(cmd) users := utils.ExecuteCommand(cmd)
cleaned := []string{} cleaned := []string{}
@ -77,24 +77,24 @@ func loggedInUsersLinux() []string {
func loggedInUsersMacOs() []string { func loggedInUsersMacOs() []string {
cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...) cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...)
users := wtf.ExecuteCommand(cmd) users := utils.ExecuteCommand(cmd)
return cleanUsers(strings.Split(users, "\n")) return cleanUsers(strings.Split(users, "\n"))
} }
func loggedInUsersWindows() []string { func loggedInUsersWindows() []string {
// We can use either one: // We can use either one:
// (Get-WMIObject -class Win32_ComputerSystem | select username).username // (Get-WMIObject -class Win32_ComputerSystem | select username).username
// [System.Security.Principal.WindowsIdentity]::GetCurrent().Name // [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
// The original was: // The original was:
// cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','") // cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','")
// But that didn't work! // But that didn't work!
// The real powershell command reads: // The real powershell command reads:
// powershell.exe -NoProfile -Command "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }" // powershell.exe -NoProfile -Command "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }"
// But we here have to write it as: // But we here have to write it as:
cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }") cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }")
// ToDo: Make list for multi-user systems // ToDo: Make list for multi-user systems
users := wtf.ExecuteCommand(cmd) users := utils.ExecuteCommand(cmd)
return cleanUsers(strings.Split(users, "\n")) return cleanUsers(strings.Split(users, "\n"))
} }

View File

@ -5,7 +5,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go // https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
@ -44,9 +44,9 @@ func WifiName() string {
func wifiEncryptionLinux() string { func wifiEncryptionLinux() string {
cmd := exec.Command("nmcli", "-t", "-f", "in-use,security", "dev", "wifi") cmd := exec.Command("nmcli", "-t", "-f", "in-use,security", "dev", "wifi")
out := wtf.ExecuteCommand(cmd) out := utils.ExecuteCommand(cmd)
name := wtf.FindMatch(`\*:(.+)`, out) name := utils.FindMatch(`\*:(.+)`, out)
if len(name) > 0 { if len(name) > 0 {
return name[0][1] return name[0][1]
@ -56,19 +56,19 @@ func wifiEncryptionLinux() string {
} }
func wifiEncryptionMacOS() string { func wifiEncryptionMacOS() string {
name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo()) name := utils.FindMatch(`s*auth: (.+)s*`, wifiInfo())
return matchStr(name) return matchStr(name)
} }
func wifiInfo() string { func wifiInfo() string {
cmd := exec.Command(osxWifiCmd, osxWifiArg) cmd := exec.Command(osxWifiCmd, osxWifiArg)
return wtf.ExecuteCommand(cmd) return utils.ExecuteCommand(cmd)
} }
func wifiNameLinux() string { func wifiNameLinux() string {
cmd := exec.Command("nmcli", "-t", "-f", "in-use,ssid", "dev", "wifi") cmd := exec.Command("nmcli", "-t", "-f", "in-use,ssid", "dev", "wifi")
out := wtf.ExecuteCommand(cmd) out := utils.ExecuteCommand(cmd)
name := wtf.FindMatch(`\*:(.+)`, out) name := utils.FindMatch(`\*:(.+)`, out)
if len(name) > 0 { if len(name) > 0 {
return name[0][1] return name[0][1]
} }
@ -76,7 +76,7 @@ func wifiNameLinux() string {
} }
func wifiNameMacOS() string { func wifiNameMacOS() string {
name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) name := utils.FindMatch(`s*SSID: (.+)s*`, wifiInfo())
return matchStr(name) return matchStr(name)
} }

View File

@ -5,8 +5,8 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/sticreations/spotigopher/spotigopher" "github.com/sticreations/spotigopher/spotigopher"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// A Widget represents a Spotify widget // A Widget represents a Spotify widget
@ -70,9 +70,9 @@ func (w *Widget) render() {
} }
func (w *Widget) createOutput() string { func (w *Widget) createOutput() string {
output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width) output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width)
return output return output
} }

View File

@ -7,8 +7,8 @@ import (
"os" "os"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
"github.com/zmb3/spotify" "github.com/zmb3/spotify"
) )
@ -111,7 +111,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
// The only solution would be to include quotes in the command, which is why I do here, but it doesn't work. // The only solution would be to include quotes in the command, which is why I do here, but it doesn't work.
// //
// If inconvenient, I'll remove this option and save the URL in a file or some other method. // If inconvenient, I'll remove this option and save the URL in a file or some other method.
wtf.OpenFile(`"` + authURL + `"`) utils.OpenFile(`"` + authURL + `"`)
widget.settings.common.RefreshInterval = 5 widget.settings.common.RefreshInterval = 5
@ -167,14 +167,14 @@ func (widget *Widget) HelpText() string {
} }
func (w *Widget) createOutput() string { func (w *Widget) createOutput() string {
output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width) output := utils.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width)
output += wtf.CenterText(fmt.Sprintf("[green]Album:[white] %v\n", w.Info.Album), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Album:[white] %v\n", w.Info.Album), w.CommonSettings().Width)
if w.playerState.ShuffleState { if w.playerState.ShuffleState {
output += wtf.CenterText(fmt.Sprintf("[green]Shuffle:[white] on\n"), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] on\n"), w.CommonSettings().Width)
} else { } else {
output += wtf.CenterText(fmt.Sprintf("[green]Shuffle:[white] off\n"), w.CommonSettings().Width) output += utils.CenterText(fmt.Sprintf("[green]Shuffle:[white] off\n"), w.CommonSettings().Width)
} }
return output return output
} }

View File

@ -7,7 +7,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
type SystemInfo struct { type SystemInfo struct {
@ -32,7 +32,7 @@ func NewSystemInfo() *SystemInfo {
cmd = exec.Command("sw_vers", arg...) cmd = exec.Command("sw_vers", arg...)
} }
raw := wtf.ExecuteCommand(cmd) raw := utils.ExecuteCommand(cmd)
for _, row := range strings.Split(raw, "\n") { for _, row := range strings.Split(raw, "\n") {
parts := strings.Split(row, ":") parts := strings.Split(row, ":")

View File

@ -5,8 +5,8 @@ import (
"time" "time"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -50,7 +50,7 @@ func (widget *Widget) Refresh() {
} }
func (widget *Widget) prettyDate() string { func (widget *Widget) prettyDate() string {
str, err := time.Parse(wtf.TimestampFormat, widget.Date) str, err := time.Parse(utils.TimestampFormat, widget.Date)
if err != nil { if err != nil {
return err.Error() return err.Error()

View File

@ -2,7 +2,7 @@ package textfile
import ( import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) initializeKeyboardControls() {
@ -18,5 +18,5 @@ func (widget *Widget) initializeKeyboardControls() {
func (widget *Widget) openFile() { func (widget *Widget) openFile() {
src := widget.CurrentSource() src := widget.CurrentSource()
wtf.OpenFile(src) utils.OpenFile(src)
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/checklist" "github.com/wtfutil/wtf/checklist"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) display() { func (widget *Widget) display() {
@ -54,5 +54,5 @@ func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem,
tview.Escape(item.Text), tview.Escape(item.Text),
) )
return wtf.HighlightableHelper(widget.View, row, idx, len(item.Text)) return utils.HighlightableHelper(widget.View, row, idx, len(item.Text))
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) initializeKeyboardControls() {
@ -50,7 +50,7 @@ func (widget *Widget) displayPrev() {
func (widget *Widget) openFile() { func (widget *Widget) openFile() {
confDir, _ := cfg.WtfConfigDir() confDir, _ := cfg.WtfConfigDir()
wtf.OpenFile(fmt.Sprintf("%s/%s", confDir, widget.filePath)) utils.OpenFile(fmt.Sprintf("%s/%s", confDir, widget.filePath))
} }
func (widget *Widget) promoteSelected() { func (widget *Widget) promoteSelected() {

View File

@ -8,6 +8,7 @@ import (
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/checklist" "github.com/wtfutil/wtf/checklist"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -108,7 +109,7 @@ func (widget *Widget) load() {
confDir, _ := cfg.WtfConfigDir() confDir, _ := cfg.WtfConfigDir()
filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath) filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath)
fileData, _ := wtf.ReadFileBytes(filePath) fileData, _ := utils.ReadFileBytes(filePath)
yaml.Unmarshal(fileData, &widget.list) yaml.Unmarshal(fileData, &widget.list)

View File

@ -4,7 +4,7 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) display() { func (widget *Widget) display() {
@ -25,7 +25,7 @@ func (widget *Widget) display() {
widget.RowColor(idx), widget.RowColor(idx),
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(item.Content)) str += utils.HighlightableHelper(widget.View, row, idx, len(item.Content))
} }
widget.ScrollableWidget.Redraw(title, str, false) widget.ScrollableWidget.Redraw(title, str, false)

View File

@ -6,7 +6,7 @@ import (
"github.com/hekmon/transmissionrpc" "github.com/hekmon/transmissionrpc"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string { func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
@ -24,7 +24,7 @@ func (widget *Widget) contentFrom(data []*transmissionrpc.Torrent) string {
tview.Escape(widget.prettyTorrentName(torrName)), tview.Escape(widget.prettyTorrentName(torrName)),
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(torrName)) str += utils.HighlightableHelper(widget.View, row, idx, len(torrName))
} }
return str return str

View File

@ -5,8 +5,8 @@ import (
"strings" "strings"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -78,7 +78,7 @@ func (widget *Widget) contentFrom(builds *Builds) string {
strings.Split(build.Commit.Message, "\n")[0], strings.Split(build.Commit.Message, "\n")[0],
build.CreatedBy.Login, build.CreatedBy.Login,
) )
str += wtf.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name)) str += utils.HighlightableHelper(widget.View, row, idx, len(build.Branch.Name))
} }
return str return str
@ -110,6 +110,6 @@ func (widget *Widget) openBuild() {
if sel >= 0 && widget.builds != nil && sel < len(widget.builds.Builds) { if sel >= 0 && widget.builds != nil && sel < len(widget.builds.Builds) {
build := &widget.builds.Builds[sel] build := &widget.builds.Builds[sel]
travisHost := TRAVIS_HOSTS[widget.settings.pro] travisHost := TRAVIS_HOSTS[widget.settings.pro]
wtf.OpenFile(fmt.Sprintf("https://%s/%s/%s/%d", travisHost, build.Repository.Slug, "builds", build.ID)) utils.OpenFile(fmt.Sprintf("https://%s/%s/%s/%d", travisHost, build.Repository.Slug, "builds", build.ID))
} }
} }

View File

@ -2,7 +2,7 @@ package twitter
import ( import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) initializeKeyboardControls() {
@ -19,5 +19,5 @@ func (widget *Widget) initializeKeyboardControls() {
func (widget *Widget) openFile() { func (widget *Widget) openFile() {
src := widget.currentSourceURI() src := widget.currentSourceURI()
wtf.OpenFile(src) utils.OpenFile(src)
} }

View File

@ -7,8 +7,8 @@ import (
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
type Widget struct { type Widget struct {
@ -68,7 +68,7 @@ func (widget *Widget) display() {
title := fmt.Sprintf("Twitter - [green]@%s[white]", widget.CurrentSource()) title := fmt.Sprintf("Twitter - [green]@%s[white]", widget.CurrentSource())
if len(tweets) == 0 { if len(tweets) == 0 {
str := fmt.Sprintf("\n\n\n%s", wtf.CenterText("[lightblue]No Tweets[white]", 50)) str := fmt.Sprintf("\n\n\n%s", utils.CenterText("[lightblue]No Tweets[white]", 50))
widget.Redraw(title, str, true) widget.Redraw(title, str, true)
return return
} }

View File

@ -3,8 +3,8 @@ package weather
import ( import (
owm "github.com/briandowns/openweathermap" owm "github.com/briandowns/openweathermap"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// Widget is the container for weather data. // Widget is the container for weather data.
@ -63,7 +63,7 @@ func (widget *Widget) Fetch(cityIDs []int) []*owm.CurrentWeatherData {
// widget's view for rendering // widget's view for rendering
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
if widget.apiKeyValid() { if widget.apiKeyValid() {
widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) widget.Data = widget.Fetch(utils.ToInts(widget.settings.cityIDs))
} }
widget.display() widget.display()

View File

@ -5,8 +5,8 @@ import (
"log" "log"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/view"
"github.com/wtfutil/wtf/wtf"
) )
// A Widget represents a Zendesk widget // A Widget represents a Zendesk widget
@ -99,6 +99,6 @@ func (widget *Widget) openTicket() {
if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) { if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) {
issue := &widget.result.Tickets[sel] issue := &widget.result.Tickets[sel]
ticketURL := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id) ticketURL := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id)
wtf.OpenFile(ticketURL) utils.OpenFile(ticketURL)
} }
} }

8
utils/init.go Normal file
View File

@ -0,0 +1,8 @@
package utils
var OpenFileUtil = "open"
// Init initializes global settings in the wtf package
func Init(openFileUtil string) {
OpenFileUtil = openFileUtil
}

View File

@ -1,4 +1,4 @@
package wtf package utils
import ( import (
"fmt" "fmt"
@ -10,7 +10,6 @@ import (
"strings" "strings"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
) )
const ( const (
@ -25,13 +24,6 @@ const (
TimestampFormat = "2006-01-02T15:04:05-0700" TimestampFormat = "2006-01-02T15:04:05-0700"
) )
var OpenFileUtil = "open"
// Init initializes global settings in the wtf package
func Init(openFileUtil string) {
OpenFileUtil = openFileUtil
}
// CenterText takes a string and a width and pads the left and right of the string with // CenterText takes a string and a width and pads the left and right of the string with
// empty spaces to ensure that the string is in the middle of the returned value // empty spaces to ensure that the string is in the middle of the returned value
// //
@ -143,7 +135,7 @@ func OpenFile(path string) {
default: default:
} }
} else { } else {
filePath, _ := utils.ExpandHomeDir(path) filePath, _ := ExpandHomeDir(path)
cmd := exec.Command(OpenFileUtil, filePath) cmd := exec.Command(OpenFileUtil, filePath)
ExecuteCommand(cmd) ExecuteCommand(cmd)
} }

View File

@ -1,4 +1,4 @@
package wtf package utils
import ( import (
"os/exec" "os/exec"

View File

@ -2,7 +2,7 @@ package view
import ( import (
"github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/utils"
) )
// MultiSourceWidget is a widget that supports displaying data from multiple sources // MultiSourceWidget is a widget that supports displaying data from multiple sources
@ -90,7 +90,7 @@ func (widget *MultiSourceWidget) loadSources() {
single := widget.moduleConfig.Config.UString(widget.singular, "") single := widget.moduleConfig.Config.UString(widget.singular, "")
multiple := widget.moduleConfig.Config.UList(widget.plural, empty) multiple := widget.moduleConfig.Config.UList(widget.plural, empty)
asStrs := wtf.ToStrs(multiple) asStrs := utils.ToStrs(multiple)
if single != "" { if single != "" {
asStrs = append(asStrs, single) asStrs = append(asStrs, single)