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:
parent
0bd2d176d8
commit
4e46fff145
@ -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...)
|
||||
|
4
main.go
4
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)
|
||||
|
||||
|
@ -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 := ""
|
||||
|
@ -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"),
|
||||
}
|
||||
|
@ -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"),
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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]),
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
|
@ -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])
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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", ""),
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)}
|
||||
}
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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, ":")
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
8
utils/init.go
Normal file
8
utils/init.go
Normal file
@ -0,0 +1,8 @@
|
||||
package utils
|
||||
|
||||
var OpenFileUtil = "open"
|
||||
|
||||
// Init initializes global settings in the wtf package
|
||||
func Init(openFileUtil string) {
|
||||
OpenFileUtil = openFileUtil
|
||||
}
|
@ -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)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package wtf
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os/exec"
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user