diff --git a/app/display.go b/app/display.go index 0801c879..acd3de9f 100644 --- a/app/display.go +++ b/app/display.go @@ -3,6 +3,7 @@ package app import ( "github.com/olebedev/config" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "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 { - cols := wtf.ToInts(display.config.UList("wtf.grid.columns")) - rows := wtf.ToInts(display.config.UList("wtf.grid.rows")) + cols := utils.ToInts(display.config.UList("wtf.grid.columns")) + rows := utils.ToInts(display.config.UList("wtf.grid.rows")) display.Grid.SetColumns(cols...) display.Grid.SetRows(rows...) diff --git a/main.go b/main.go index 84726545..c62c5116 100644 --- a/main.go +++ b/main.go @@ -18,7 +18,7 @@ import ( "github.com/wtfutil/wtf/app" "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/flags" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) var tviewApp *tview.Application @@ -62,7 +62,7 @@ func main() { defer profile.Start(profile.MemProfile).Stop() } - wtf.Init(config.UString("wtf.openFileUtil", "open")) + utils.Init(config.UString("wtf.openFileUtil", "open")) setTerm(config) diff --git a/modules/bamboohr/widget.go b/modules/bamboohr/widget.go index 8dd16ee9..48a21329 100644 --- a/modules/bamboohr/widget.go +++ b/modules/bamboohr/widget.go @@ -5,6 +5,7 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) @@ -49,7 +50,7 @@ func (widget *Widget) Refresh() { func (widget *Widget) contentFrom(items []Item) string { 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 := "" diff --git a/modules/clocks/settings.go b/modules/clocks/settings.go index af672430..1e601845 100644 --- a/modules/clocks/settings.go +++ b/modules/clocks/settings.go @@ -3,7 +3,7 @@ package clocks import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const defaultTitle = "Clocks" @@ -30,8 +30,8 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co settings := Settings{ common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), - dateFormat: ymlConfig.UString("dateFormat", wtf.SimpleDateFormat), - timeFormat: ymlConfig.UString("timeFormat", wtf.SimpleTimeFormat), + dateFormat: ymlConfig.UString("dateFormat", utils.SimpleDateFormat), + timeFormat: ymlConfig.UString("timeFormat", utils.SimpleTimeFormat), locations: ymlConfig.UMap("locations"), sort: ymlConfig.UString("sort"), } diff --git a/modules/cmdrunner/settings.go b/modules/cmdrunner/settings.go index a7894eb1..ffcd8dbb 100644 --- a/modules/cmdrunner/settings.go +++ b/modules/cmdrunner/settings.go @@ -3,7 +3,7 @@ package cmdrunner import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const defaultTitle = "CmdRunner" @@ -20,7 +20,7 @@ func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig settings := Settings{ common: cfg.NewCommonSettingsFromModule(name, defaultTitle, moduleConfig, globalConfig), - args: wtf.ToStrs(moduleConfig.UList("args")), + args: utils.ToStrs(moduleConfig.UList("args")), cmd: moduleConfig.UString("cmd"), } diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index 4f2aca20..367ed76e 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -61,5 +61,5 @@ func (widget *Widget) String() string { func (widget *Widget) execute() string { cmd := exec.Command(widget.cmd, widget.args...) - return wtf.ExecuteCommand(cmd) + return utils.ExecuteCommand(cmd) } diff --git a/modules/datadog/client.go b/modules/datadog/client.go index ce9a2406..33156cd4 100644 --- a/modules/datadog/client.go +++ b/modules/datadog/client.go @@ -1,7 +1,7 @@ package datadog import ( - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" datadog "github.com/zorkian/go-datadog-api" ) @@ -12,7 +12,7 @@ func (widget *Widget) Monitors() ([]datadog.Monitor, error) { widget.settings.applicationKey, ) - tags := wtf.ToStrs(widget.settings.tags) + tags := utils.ToStrs(widget.settings.tags) monitors, err := client.GetMonitorsByTags(tags) if err != nil { diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index d14ae877..b1cf5e23 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" datadog "github.com/zorkian/go-datadog-api" ) @@ -84,7 +84,7 @@ func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string { *triggeredMonitor.Name, widget.RowColor(idx), ) - str += wtf.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name)) + str += utils.HighlightableHelper(widget.View, row, idx, len(*triggeredMonitor.Name)) } } else { str += fmt.Sprintf( @@ -101,6 +101,6 @@ func (widget *Widget) openItem() { sel := widget.GetSelected() if sel >= 0 && widget.monitors != nil && sel < len(widget.monitors) { 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)) } } diff --git a/modules/feedreader/settings.go b/modules/feedreader/settings.go index b6d45a86..af9db630 100644 --- a/modules/feedreader/settings.go +++ b/modules/feedreader/settings.go @@ -3,7 +3,7 @@ package feedreader import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const ( @@ -23,7 +23,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co settings := &Settings{ common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), - feeds: wtf.ToStrs(ymlConfig.UList("feeds")), + feeds: utils.ToStrs(ymlConfig.UList("feeds")), feedLimit: ymlConfig.UInt("feedLimit", -1), } diff --git a/modules/feedreader/widget.go b/modules/feedreader/widget.go index f3b20ba9..85eb77d8 100644 --- a/modules/feedreader/widget.go +++ b/modules/feedreader/widget.go @@ -7,8 +7,8 @@ import ( "github.com/mmcdole/gofeed" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) const ( @@ -144,7 +144,7 @@ func (widget *Widget) contentFrom(data []*FeedItem) string { 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 @@ -169,6 +169,6 @@ func (widget *Widget) openStory() { story := widget.stories[sel] story.viewed = true - wtf.OpenFile(story.item.Link) + utils.OpenFile(story.item.Link) } } diff --git a/modules/gcal/cal_event.go b/modules/gcal/cal_event.go index 99525f23..ff0cd82e 100644 --- a/modules/gcal/cal_event.go +++ b/modules/gcal/cal_event.go @@ -3,7 +3,7 @@ package gcal import ( "time" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" "google.golang.org/api/calendar/v3" ) @@ -100,9 +100,9 @@ func (calEvent *CalEvent) Start() time.Time { func (calEvent *CalEvent) Timestamp() string { if calEvent.AllDay() { 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) - return startTime.Format(wtf.MinimumTimeFormat) + return startTime.Format(utils.MinimumTimeFormat) } diff --git a/modules/gcal/display.go b/modules/gcal/display.go index 3b245d59..4d1d45ed 100644 --- a/modules/gcal/display.go +++ b/modules/gcal/display.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) sortedEvents() ([]*CalEvent, []*CalEvent) { @@ -98,7 +98,7 @@ func (widget *Widget) dayDivider(event, prevEvent *CalEvent) string { return fmt.Sprintf("[%s::b]", widget.settings.colors.day) + - event.Start().Format(wtf.FullDateFormat) + + event.Start().Format(utils.FullDateFormat) + "\n" } @@ -169,7 +169,7 @@ func (widget *Widget) titleColor(calEvent *CalEvent) string { color := widget.settings.colors.title for _, untypedArr := range widget.settings.highlights { - highlightElements := wtf.ToStrs(untypedArr.([]interface{})) + highlightElements := utils.ToStrs(untypedArr.([]interface{})) match, _ := regexp.MatchString( strings.ToLower(highlightElements[0]), diff --git a/modules/gerrit/widget.go b/modules/gerrit/widget.go index bb9c0f36..d7f8baa1 100644 --- a/modules/gerrit/widget.go +++ b/modules/gerrit/widget.go @@ -8,8 +8,8 @@ import ( glb "github.com/andygrunwald/go-gerrit" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -146,7 +146,7 @@ func (widget *Widget) openReview() { } else { 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)) } } diff --git a/modules/git/git_repo.go b/modules/git/git_repo.go index b53e6ed4..691d86b2 100644 --- a/modules/git/git_repo.go +++ b/modules/git/git_repo.go @@ -5,7 +5,7 @@ import ( "os/exec" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) type GitRepo struct { @@ -33,7 +33,7 @@ func (repo *GitRepo) branch() string { arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--abbrev-ref", "HEAD"} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } @@ -42,7 +42,7 @@ func (repo *GitRepo) changedFiles() []string { arg := []string{repo.gitDir(), repo.workTree(), "status", "--porcelain"} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) 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} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) data := strings.Split(str, "\n") @@ -67,21 +67,21 @@ func (repo *GitRepo) commits(commitCount int, commitFormat, dateFormat string) [ func (repo *GitRepo) repository() string { arg := []string{repo.gitDir(), repo.workTree(), "rev-parse", "--show-toplevel"} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } func (repo *GitRepo) pull() string { arg := []string{repo.gitDir(), repo.workTree(), "pull"} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } func (repo *GitRepo) checkout(branch string) string { arg := []string{repo.gitDir(), repo.workTree(), "checkout", branch} cmd := exec.Command("git", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } diff --git a/modules/git/widget.go b/modules/git/widget.go index de80781f..f015e747 100644 --- a/modules/git/widget.go +++ b/modules/git/widget.go @@ -8,8 +8,8 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) const offscreen = -1000 @@ -76,7 +76,7 @@ func (widget *Widget) Pull() { } func (widget *Widget) Refresh() { - repoPaths := wtf.ToStrs(widget.settings.repositories) + repoPaths := utils.ToStrs(widget.settings.repositories) widget.GitRepos = widget.gitRepos(repoPaths) sort.Slice(widget.GitRepos, func(i, j int) bool { diff --git a/modules/github/github_repo.go b/modules/github/github_repo.go index 9a0f1d7b..5a4bd011 100644 --- a/modules/github/github_repo.go +++ b/modules/github/github_repo.go @@ -6,7 +6,7 @@ import ( "net/http" ghb "github.com/google/go-github/v26/github" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" "golang.org/x/oauth2" ) @@ -35,7 +35,7 @@ func NewGithubRepo(name, owner, apiKey, baseURL, uploadURL string) *GithubRepo { } func (repo *GithubRepo) Open() { - wtf.OpenFile(*repo.RemoteRepo.HTMLURL) + utils.OpenFile(*repo.RemoteRepo.HTMLURL) } // Refresh reloads the github data via the Github API diff --git a/modules/github/settings.go b/modules/github/settings.go index c8b2f884..dcc6c263 100644 --- a/modules/github/settings.go +++ b/modules/github/settings.go @@ -6,7 +6,7 @@ import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const defaultTitle = "GitHub" @@ -57,7 +57,7 @@ func parseRepositories(ymlConfig *config.Config) []string { return result } - result = wtf.ToStrs(ymlConfig.UList("repositories")) + result = utils.ToStrs(ymlConfig.UList("repositories")) return result } diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 12c0fb26..db8c55e4 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // 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"), ) - str += wtf.HighlightableHelper(widget.View, row, idx, len(message.Text)) + str += utils.HighlightableHelper(widget.View, row, idx, len(message.Text)) } return str @@ -104,6 +104,6 @@ func (widget *Widget) openMessage() { sel := widget.GetSelected() if sel >= 0 && widget.messages != nil && sel < len(widget.messages) { message := &widget.messages[sel] - wtf.OpenFile(message.Text) + utils.OpenFile(message.Text) } } diff --git a/modules/gspreadsheets/client.go b/modules/gspreadsheets/client.go index e4adf75f..14cf85c7 100644 --- a/modules/gspreadsheets/client.go +++ b/modules/gspreadsheets/client.go @@ -19,7 +19,6 @@ import ( "strings" "github.com/wtfutil/wtf/utils" - "github.com/wtfutil/wtf/wtf" "golang.org/x/oauth2" "golang.org/x/oauth2/google" sheets "google.golang.org/api/sheets/v4" @@ -52,7 +51,7 @@ func (widget *Widget) Fetch() ([]*sheets.ValueRange, error) { return nil, err } - cells := wtf.ToStrs(widget.settings.cellAddresses) + cells := utils.ToStrs(widget.settings.cellAddresses) addresses := strings.Join(cells[:], ";") responses := make([]*sheets.ValueRange, len(cells)) diff --git a/modules/gspreadsheets/widget.go b/modules/gspreadsheets/widget.go index 0cbb34d4..5915ad99 100644 --- a/modules/gspreadsheets/widget.go +++ b/modules/gspreadsheets/widget.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" sheets "google.golang.org/api/sheets/v4" ) @@ -42,7 +42,7 @@ func (widget *Widget) contentFrom(valueRanges []*sheets.ValueRange) string { res := "" - cells := wtf.ToStrs(widget.settings.cellNames) + cells := utils.ToStrs(widget.settings.cellNames) 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]) } diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index 6274e339..d25b357c 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -6,8 +6,8 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -91,7 +91,7 @@ func (widget *Widget) contentFrom(stories []Story) string { 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 @@ -101,7 +101,7 @@ func (widget *Widget) openStory() { sel := widget.GetSelected() if sel >= 0 && widget.stories != nil && sel < len(widget.stories) { story := &widget.stories[sel] - wtf.OpenFile(story.URL) + utils.OpenFile(story.URL) } } @@ -109,6 +109,6 @@ func (widget *Widget) openComments() { sel := widget.GetSelected() if sel >= 0 && widget.stories != nil && sel < len(widget.stories) { 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)) } } diff --git a/modules/hibp/settings.go b/modules/hibp/settings.go index 16f0005e..a62c91d7 100644 --- a/modules/hibp/settings.go +++ b/modules/hibp/settings.go @@ -5,7 +5,7 @@ import ( "github.com/olebedev/config" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const ( @@ -34,7 +34,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *co common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), apiKey: ymlConfig.UString("apiKey", ""), - accounts: wtf.ToStrs(ymlConfig.UList("accounts")), + accounts: utils.ToStrs(ymlConfig.UList("accounts")), since: ymlConfig.UString("since", ""), } diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index a4579e5b..28b5eb0c 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -5,8 +5,8 @@ import ( "regexp" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -83,7 +83,7 @@ func (widget *Widget) contentFrom(view *View) string { 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() if sel >= 0 && widget.view != nil && sel < len(widget.view.Jobs) { job := &widget.view.Jobs[sel] - wtf.OpenFile(job.Url) + utils.OpenFile(job.Url) } } diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 7ffbb52d..002158ee 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -68,7 +68,7 @@ func (widget *Widget) openItem() { sel := widget.GetSelected() if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) { 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, ) - str += wtf.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary)) + str += utils.HighlightableHelper(widget.View, row, idx, len(issue.IssueFields.Summary)) } return str diff --git a/modules/mercurial/hg_repo.go b/modules/mercurial/hg_repo.go index ae53a21f..ecefaf34 100644 --- a/modules/mercurial/hg_repo.go +++ b/modules/mercurial/hg_repo.go @@ -7,7 +7,7 @@ import ( "path" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) type MercurialRepo struct { @@ -37,7 +37,7 @@ func (repo *MercurialRepo) branch() string { arg := []string{"branch", repo.repoPath()} cmd := exec.Command("hg", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } @@ -54,7 +54,7 @@ func (repo *MercurialRepo) changedFiles() []string { arg := []string{"status", repo.repoPath()} cmd := exec.Command("hg", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) 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} cmd := exec.Command("hg", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) data := strings.Split(str, "\n") @@ -78,14 +78,14 @@ func (repo *MercurialRepo) commits(commitCount int, commitFormat string) []strin func (repo *MercurialRepo) pull() string { arg := []string{"pull", repo.repoPath()} cmd := exec.Command("hg", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } func (repo *MercurialRepo) checkout(branch string) string { arg := []string{"checkout", repo.repoPath(), branch} cmd := exec.Command("hg", arg...) - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return str } diff --git a/modules/mercurial/widget.go b/modules/mercurial/widget.go index 42b993ba..53141daf 100644 --- a/modules/mercurial/widget.go +++ b/modules/mercurial/widget.go @@ -3,8 +3,8 @@ package mercurial import ( "github.com/gdamore/tcell" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) const offscreen = -1000 @@ -73,7 +73,7 @@ func (widget *Widget) Pull() { } func (widget *Widget) Refresh() { - repoPaths := wtf.ToStrs(widget.settings.repositories) + repoPaths := utils.ToStrs(widget.settings.repositories) widget.Data = widget.mercurialRepos(repoPaths) diff --git a/modules/nbascore/widget.go b/modules/nbascore/widget.go index ff764806..68bc476f 100644 --- a/modules/nbascore/widget.go +++ b/modules/nbascore/widget.go @@ -9,8 +9,8 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // A Widget represents an NBA Score widget @@ -79,7 +79,7 @@ func (widget *Widget) nbascore() string { result := map[string]interface{}{} json.Unmarshal(contents, &result) 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{}) { vTeam, hTeam, vScore, hScore := "", "", "", "" quarter := 0. diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 6d0e974e..21bb0f59 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" nr "github.com/yfronto/newrelic" @@ -63,7 +64,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revisions := []string{} for _, deploy := range deploys { - if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) { + if (deploy.Revision != "") && utils.Exclude(revisions, deploy.Revision) { lineColor := "white" if wtf.IsToday(deploy.Timestamp) { lineColor = "lightblue" @@ -79,7 +80,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { deploy.Revision[0:revLen], lineColor, deploy.Timestamp.Format("Jan 02 15:04 MST"), - wtf.NameFromEmail(deploy.User), + utils.NameFromEmail(deploy.User), ) revisions = append(revisions, deploy.Revision) diff --git a/modules/opsgenie/widget.go b/modules/opsgenie/widget.go index 70075673..33ec957d 100644 --- a/modules/opsgenie/widget.go +++ b/modules/opsgenie/widget.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -59,7 +59,7 @@ func (widget *Widget) contentFrom(onCallResponses []*OnCallResponse) string { if len(data.OnCallData.Recipients) == 0 { msg = " [gray]no one[white]\n\n" } 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) diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index fbf0b314..9fb93a99 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -6,8 +6,8 @@ import ( "github.com/PagerDuty/go-pagerduty" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -40,7 +40,7 @@ func (widget *Widget) Refresh() { } if widget.settings.showSchedules { - scheduleIDs := wtf.ToStrs(widget.settings.scheduleIDs) + scheduleIDs := utils.ToStrs(widget.settings.scheduleIDs) onCalls, err1 = GetOnCalls(widget.settings.apiKey, scheduleIDs) } diff --git a/modules/power/battery.go b/modules/power/battery.go index 053f4e3d..f0ea53ba 100644 --- a/modules/power/battery.go +++ b/modules/power/battery.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) 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 { cmd := exec.Command(battery.cmd, battery.args...) - return wtf.ExecuteCommand(cmd) + return utils.ExecuteCommand(cmd) } func (battery *Battery) parse(data string) string { diff --git a/modules/power/battery_linux.go b/modules/power/battery_linux.go index 51db6123..51f9f807 100644 --- a/modules/power/battery_linux.go +++ b/modules/power/battery_linux.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) var batteryState string @@ -41,7 +41,7 @@ func (battery *Battery) String() string { func (battery *Battery) execute() string { cmd := exec.Command("upower", "-e") - lines := strings.Split(wtf.ExecuteCommand(cmd), "\n") + lines := strings.Split(utils.ExecuteCommand(cmd), "\n") var target string for _, l := range lines { if strings.Contains(l, "/battery") { @@ -50,7 +50,7 @@ func (battery *Battery) execute() string { } } cmd = exec.Command("upower", "-i", target) - return wtf.ExecuteCommand(cmd) + return utils.ExecuteCommand(cmd) } func (battery *Battery) parse(data string) string { diff --git a/modules/power/source.go b/modules/power/source.go index 105b69b3..623922cf 100644 --- a/modules/power/source.go +++ b/modules/power/source.go @@ -7,7 +7,7 @@ import ( "regexp" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const SingleQuotesRegExp = "'(.*)'" @@ -16,7 +16,7 @@ const SingleQuotesRegExp = "'(.*)'" // "AC Power" or "Battery Power" func powerSource() string { cmd := exec.Command("pmset", []string{"-g", "ps"}...) - result := wtf.ExecuteCommand(cmd) + result := utils.ExecuteCommand(cmd) r, _ := regexp.Compile(SingleQuotesRegExp) diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 1d58f940..64ca8bca 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -4,8 +4,8 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Rollbar widget @@ -91,7 +91,7 @@ func (widget *Widget) contentFrom(result *Result) string { "blue", item.Environment, ) - str += wtf.HighlightableHelper(widget.View, row, idx, len(item.Title)) + str += utils.HighlightableHelper(widget.View, row, idx, len(item.Title)) } return str @@ -124,7 +124,7 @@ func (widget *Widget) openBuild() { if widget.GetSelected() >= 0 && widget.items != nil && widget.GetSelected() < len(widget.items.Items) { item := &widget.items.Items[widget.GetSelected()] - wtf.OpenFile( + utils.OpenFile( fmt.Sprintf( "https://rollbar.com/%s/%s/%s/%d", widget.settings.projectOwner, diff --git a/modules/security/dns.go b/modules/security/dns.go index b6afdefe..8cf21a0f 100644 --- a/modules/security/dns.go +++ b/modules/security/dns.go @@ -5,7 +5,7 @@ import ( "runtime" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) /* -------------------- Exported Functions -------------------- */ @@ -28,7 +28,7 @@ func DnsServers() []string { func dnsLinux() []string { // This may be very Ubuntu specific cmd := exec.Command("nmcli", "device", "show") - out := wtf.ExecuteCommand(cmd) + out := utils.ExecuteCommand(cmd) lines := strings.Split(out, "\n") @@ -46,7 +46,7 @@ func dnsLinux() []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\}'` cmd := exec.Command("sh", "-c", cmdString) - out := wtf.ExecuteCommand(cmd) + out := utils.ExecuteCommand(cmd) lines := strings.Split(out, "\n") @@ -61,5 +61,5 @@ func dnsWindows() []string { cmd := exec.Command("powershell.exe", "-NoProfile", "Get-DnsClientServerAddress | Select-Object –ExpandProperty ServerAddresses") - return []string{wtf.ExecuteCommand(cmd)} + return []string{utils.ExecuteCommand(cmd)} } diff --git a/modules/security/firewall.go b/modules/security/firewall.go index 5e246e27..3049a944 100644 --- a/modules/security/firewall.go +++ b/modules/security/firewall.go @@ -7,7 +7,7 @@ import ( "runtime" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) const osxFirewallCmd = "/usr/libexec/ApplicationFirewall/socketfilterfw" @@ -66,35 +66,35 @@ func firewallStateLinux() string { // might be very Ubuntu specific func firewallStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getglobalstate") - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return statusLabel(str) } func firewallStateWindows() string { - // The raw way to do this in PS, not using netsh, nor registry, is the following: - // if (((Get-NetFirewallProfile | select name,enabled) - // | where { $_.Enabled -eq $True } | measure ).Count -eq 3) - // { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red } + // The raw way to do this in PS, not using netsh, nor registry, is the following: + // if (((Get-NetFirewallProfile | select name,enabled) + // | where { $_.Enabled -eq $True } | measure ).Count -eq 3) + // { Write-Host "OK" -ForegroundColor Green} else { Write-Host "OFF" -ForegroundColor Red } - cmd := exec.Command("powershell.exe", "-NoProfile", - "-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }") + cmd := exec.Command("powershell.exe", "-NoProfile", + "-Command", "& { ((Get-NetFirewallProfile | select name,enabled) | where { $_.Enabled -eq $True } | measure ).Count }") - fwStat := wtf.ExecuteCommand(cmd) - fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n" + fwStat := utils.ExecuteCommand(cmd) + fwStat = strings.TrimSpace(fwStat) // Always sanitize PowerShell output: "3\r\n" //fmt.Printf("%d %q\n", len(fwStat), fwStat) switch fwStat { - case "3": - return "[green]Good[white] (3/3)" - case "2": - return "[orange]Poor[white] (2/3)" - case "1": - return "[yellow]Bad[white] (1/3)" - case "0": - return "[red]Disabled[white]" - default: - return "[white]N/A[white]" + case "3": + return "[green]Good[white] (3/3)" + case "2": + return "[orange]Poor[white] (2/3)" + case "1": + return "[yellow]Bad[white] (1/3)" + case "0": + return "[red]Disabled[white]" + default: + return "[white]N/A[white]" } } @@ -107,7 +107,7 @@ func firewallStealthStateLinux() string { func firewallStealthStateMacOS() string { cmd := exec.Command(osxFirewallCmd, "--getstealthmode") - str := wtf.ExecuteCommand(cmd) + str := utils.ExecuteCommand(cmd) return statusLabel(str) } @@ -116,7 +116,6 @@ func firewallStealthStateWindows() string { return "[white]N/A[white]" } - func statusLabel(str string) string { label := "off" diff --git a/modules/security/users.go b/modules/security/users.go index 88b08658..2c6d2356 100644 --- a/modules/security/users.go +++ b/modules/security/users.go @@ -7,7 +7,7 @@ import ( "runtime" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) /* -------------------- Exported Functions -------------------- */ @@ -51,7 +51,7 @@ func cleanUsers(users []string) []string { func loggedInUsersLinux() []string { cmd := exec.Command("who", "-us") - users := wtf.ExecuteCommand(cmd) + users := utils.ExecuteCommand(cmd) cleaned := []string{} @@ -77,24 +77,24 @@ func loggedInUsersLinux() []string { func loggedInUsersMacOs() []string { cmd := exec.Command("dscl", []string{".", "-list", "/Users"}...) - users := wtf.ExecuteCommand(cmd) + users := utils.ExecuteCommand(cmd) return cleanUsers(strings.Split(users, "\n")) } func loggedInUsersWindows() []string { - // We can use either one: - // (Get-WMIObject -class Win32_ComputerSystem | select username).username - // [System.Security.Principal.WindowsIdentity]::GetCurrent().Name - // The original was: - // cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','") - // But that didn't work! + // We can use either one: + // (Get-WMIObject -class Win32_ComputerSystem | select username).username + // [System.Security.Principal.WindowsIdentity]::GetCurrent().Name + // The original was: + // cmd := exec.Command("powershell.exe", "(query user) -replace '\\s{2,}', ','") + // But that didn't work! // The real powershell command reads: // powershell.exe -NoProfile -Command "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }" - // But we here have to write it as: - cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }") - // ToDo: Make list for multi-user systems + // But we here have to write it as: + cmd := exec.Command("powershell.exe", "-NoProfile", "-Command", "& { [System.Security.Principal.WindowsIdentity]::GetCurrent().Name }") + // ToDo: Make list for multi-user systems - users := wtf.ExecuteCommand(cmd) - return cleanUsers(strings.Split(users, "\n")) + users := utils.ExecuteCommand(cmd) + return cleanUsers(strings.Split(users, "\n")) } diff --git a/modules/security/wifi.go b/modules/security/wifi.go index 3899adc4..3f1a3868 100644 --- a/modules/security/wifi.go +++ b/modules/security/wifi.go @@ -5,7 +5,7 @@ import ( "runtime" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) // https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go @@ -44,9 +44,9 @@ func WifiName() string { func wifiEncryptionLinux() string { 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 { return name[0][1] @@ -56,19 +56,19 @@ func wifiEncryptionLinux() string { } func wifiEncryptionMacOS() string { - name := wtf.FindMatch(`s*auth: (.+)s*`, wifiInfo()) + name := utils.FindMatch(`s*auth: (.+)s*`, wifiInfo()) return matchStr(name) } func wifiInfo() string { cmd := exec.Command(osxWifiCmd, osxWifiArg) - return wtf.ExecuteCommand(cmd) + return utils.ExecuteCommand(cmd) } func wifiNameLinux() string { cmd := exec.Command("nmcli", "-t", "-f", "in-use,ssid", "dev", "wifi") - out := wtf.ExecuteCommand(cmd) - name := wtf.FindMatch(`\*:(.+)`, out) + out := utils.ExecuteCommand(cmd) + name := utils.FindMatch(`\*:(.+)`, out) if len(name) > 0 { return name[0][1] } @@ -76,7 +76,7 @@ func wifiNameLinux() string { } func wifiNameMacOS() string { - name := wtf.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) + name := utils.FindMatch(`s*SSID: (.+)s*`, wifiInfo()) return matchStr(name) } diff --git a/modules/spotify/widget.go b/modules/spotify/widget.go index a81fc3d4..1e957326 100644 --- a/modules/spotify/widget.go +++ b/modules/spotify/widget.go @@ -5,8 +5,8 @@ import ( "github.com/rivo/tview" "github.com/sticreations/spotigopher/spotigopher" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Spotify widget @@ -70,9 +70,9 @@ func (w *Widget) render() { } func (w *Widget) createOutput() string { - output := wtf.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 += wtf.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]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artist), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]%v:[white] %v\n", w.Info.TrackNumber, w.Info.Album), w.CommonSettings().Width) return output } diff --git a/modules/spotifyweb/widget.go b/modules/spotifyweb/widget.go index cbbf416c..00149488 100644 --- a/modules/spotifyweb/widget.go +++ b/modules/spotifyweb/widget.go @@ -7,8 +7,8 @@ import ( "os" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" "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. // // 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 @@ -167,14 +167,14 @@ func (widget *Widget) HelpText() string { } func (w *Widget) createOutput() string { - output := wtf.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 += wtf.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]Now %v [white]\n", w.Info.Status), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]Artist:[white] %v\n", w.Info.Artists), w.CommonSettings().Width) + output += utils.CenterText(fmt.Sprintf("[green]Album:[white] %v\n", w.Info.Album), w.CommonSettings().Width) 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 { - 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 } diff --git a/modules/system/system_info.go b/modules/system/system_info.go index 4fa28be4..1b7db267 100644 --- a/modules/system/system_info.go +++ b/modules/system/system_info.go @@ -7,7 +7,7 @@ import ( "runtime" "strings" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) type SystemInfo struct { @@ -32,7 +32,7 @@ func NewSystemInfo() *SystemInfo { cmd = exec.Command("sw_vers", arg...) } - raw := wtf.ExecuteCommand(cmd) + raw := utils.ExecuteCommand(cmd) for _, row := range strings.Split(raw, "\n") { parts := strings.Split(row, ":") diff --git a/modules/system/widget.go b/modules/system/widget.go index b12ce398..b6b4923a 100644 --- a/modules/system/widget.go +++ b/modules/system/widget.go @@ -5,8 +5,8 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -50,7 +50,7 @@ func (widget *Widget) Refresh() { } func (widget *Widget) prettyDate() string { - str, err := time.Parse(wtf.TimestampFormat, widget.Date) + str, err := time.Parse(utils.TimestampFormat, widget.Date) if err != nil { return err.Error() diff --git a/modules/textfile/keyboard.go b/modules/textfile/keyboard.go index 21bffa62..e5dba8d5 100644 --- a/modules/textfile/keyboard.go +++ b/modules/textfile/keyboard.go @@ -2,7 +2,7 @@ package textfile import ( "github.com/gdamore/tcell" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) initializeKeyboardControls() { @@ -18,5 +18,5 @@ func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) openFile() { src := widget.CurrentSource() - wtf.OpenFile(src) + utils.OpenFile(src) } diff --git a/modules/todo/display.go b/modules/todo/display.go index 43df353e..cb4dc4b2 100644 --- a/modules/todo/display.go +++ b/modules/todo/display.go @@ -5,7 +5,7 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/checklist" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) display() { @@ -54,5 +54,5 @@ func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, tview.Escape(item.Text), ) - return wtf.HighlightableHelper(widget.View, row, idx, len(item.Text)) + return utils.HighlightableHelper(widget.View, row, idx, len(item.Text)) } diff --git a/modules/todo/keyboard.go b/modules/todo/keyboard.go index fad85952..faa7b437 100644 --- a/modules/todo/keyboard.go +++ b/modules/todo/keyboard.go @@ -5,7 +5,7 @@ import ( "github.com/gdamore/tcell" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) initializeKeyboardControls() { @@ -50,7 +50,7 @@ func (widget *Widget) displayPrev() { func (widget *Widget) openFile() { 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() { diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 70b73a91..9ec8c636 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -8,6 +8,7 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/checklist" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" "gopkg.in/yaml.v2" @@ -108,7 +109,7 @@ func (widget *Widget) load() { confDir, _ := cfg.WtfConfigDir() filePath := fmt.Sprintf("%s/%s", confDir, widget.filePath) - fileData, _ := wtf.ReadFileBytes(filePath) + fileData, _ := utils.ReadFileBytes(filePath) yaml.Unmarshal(fileData, &widget.list) diff --git a/modules/todoist/display.go b/modules/todoist/display.go index 1c24df64..81d707dd 100644 --- a/modules/todoist/display.go +++ b/modules/todoist/display.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) display() { @@ -25,7 +25,7 @@ func (widget *Widget) display() { 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) diff --git a/modules/transmission/display.go b/modules/transmission/display.go index 5c642c30..5d0849bd 100644 --- a/modules/transmission/display.go +++ b/modules/transmission/display.go @@ -6,7 +6,7 @@ import ( "github.com/hekmon/transmissionrpc" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) 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)), ) - str += wtf.HighlightableHelper(widget.View, row, idx, len(torrName)) + str += utils.HighlightableHelper(widget.View, row, idx, len(torrName)) } return str diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index a5e5d582..b85592b9 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -5,8 +5,8 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -78,7 +78,7 @@ func (widget *Widget) contentFrom(builds *Builds) string { strings.Split(build.Commit.Message, "\n")[0], 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 @@ -110,6 +110,6 @@ func (widget *Widget) openBuild() { if sel >= 0 && widget.builds != nil && sel < len(widget.builds.Builds) { build := &widget.builds.Builds[sel] 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)) } } diff --git a/modules/twitter/keyboard.go b/modules/twitter/keyboard.go index 897a91f8..93d40439 100644 --- a/modules/twitter/keyboard.go +++ b/modules/twitter/keyboard.go @@ -2,7 +2,7 @@ package twitter import ( "github.com/gdamore/tcell" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/utils" ) func (widget *Widget) initializeKeyboardControls() { @@ -19,5 +19,5 @@ func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) openFile() { src := widget.currentSourceURI() - wtf.OpenFile(src) + utils.OpenFile(src) } diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index f023a6a8..766f837c 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -7,8 +7,8 @@ import ( "github.com/dustin/go-humanize" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) type Widget struct { @@ -68,7 +68,7 @@ func (widget *Widget) display() { title := fmt.Sprintf("Twitter - [green]@%s[white]", widget.CurrentSource()) 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) return } diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index 5fa52ff6..f7450a4f 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -3,8 +3,8 @@ package weather import ( owm "github.com/briandowns/openweathermap" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // Widget is the container for weather data. @@ -63,7 +63,7 @@ func (widget *Widget) Fetch(cityIDs []int) []*owm.CurrentWeatherData { // widget's view for rendering func (widget *Widget) Refresh() { if widget.apiKeyValid() { - widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) + widget.Data = widget.Fetch(utils.ToInts(widget.settings.cityIDs)) } widget.display() diff --git a/modules/zendesk/widget.go b/modules/zendesk/widget.go index 3b1f4cdc..9c3ae53f 100644 --- a/modules/zendesk/widget.go +++ b/modules/zendesk/widget.go @@ -5,8 +5,8 @@ import ( "log" "github.com/rivo/tview" + "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/view" - "github.com/wtfutil/wtf/wtf" ) // 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) { issue := &widget.result.Tickets[sel] ticketURL := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id) - wtf.OpenFile(ticketURL) + utils.OpenFile(ticketURL) } } diff --git a/utils/init.go b/utils/init.go new file mode 100644 index 00000000..86267333 --- /dev/null +++ b/utils/init.go @@ -0,0 +1,8 @@ +package utils + +var OpenFileUtil = "open" + +// Init initializes global settings in the wtf package +func Init(openFileUtil string) { + OpenFileUtil = openFileUtil +} diff --git a/wtf/utils.go b/utils/utils.go similarity index 95% rename from wtf/utils.go rename to utils/utils.go index 4c64da19..5adda457 100644 --- a/wtf/utils.go +++ b/utils/utils.go @@ -1,4 +1,4 @@ -package wtf +package utils import ( "fmt" @@ -10,7 +10,6 @@ import ( "strings" "github.com/rivo/tview" - "github.com/wtfutil/wtf/utils" ) const ( @@ -25,13 +24,6 @@ const ( 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 // empty spaces to ensure that the string is in the middle of the returned value // @@ -143,7 +135,7 @@ func OpenFile(path string) { default: } } else { - filePath, _ := utils.ExpandHomeDir(path) + filePath, _ := ExpandHomeDir(path) cmd := exec.Command(OpenFileUtil, filePath) ExecuteCommand(cmd) } diff --git a/wtf/utils_test.go b/utils/utils_test.go similarity index 99% rename from wtf/utils_test.go rename to utils/utils_test.go index 3e5b2aed..208583e0 100644 --- a/wtf/utils_test.go +++ b/utils/utils_test.go @@ -1,4 +1,4 @@ -package wtf +package utils import ( "os/exec" diff --git a/view/multisource_widget.go b/view/multisource_widget.go index f3f818e7..711770d9 100644 --- a/view/multisource_widget.go +++ b/view/multisource_widget.go @@ -2,7 +2,7 @@ package view import ( "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 @@ -90,7 +90,7 @@ func (widget *MultiSourceWidget) loadSources() { single := widget.moduleConfig.Config.UString(widget.singular, "") multiple := widget.moduleConfig.Config.UList(widget.plural, empty) - asStrs := wtf.ToStrs(multiple) + asStrs := utils.ToStrs(multiple) if single != "" { asStrs = append(asStrs, single)