mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #525 from wtfutil/20190805-utils-into-utils
20190805 utils into utils
This commit is contained in:
commit
97ca61ac97
@ -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.DoesNotInclude(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)
|
||||
}
|
||||
}
|
||||
|
47
utils/conversions.go
Normal file
47
utils/conversions.go
Normal file
@ -0,0 +1,47 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
/* -------------------- Map Conversion -------------------- */
|
||||
|
||||
// MapToStrs takes a map of interfaces and returns a map of strings
|
||||
func MapToStrs(aMap map[string]interface{}) map[string]string {
|
||||
results := make(map[string]string)
|
||||
|
||||
for key, val := range aMap {
|
||||
results[key] = val.(string)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
/* -------------------- Slice Conversion -------------------- */
|
||||
|
||||
// ToInts takes a slice of interfaces and returns a slice of ints
|
||||
func ToInts(slice []interface{}) []int {
|
||||
results := []int{}
|
||||
|
||||
for _, val := range slice {
|
||||
results = append(results, val.(int))
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// ToStrs takes a slice of interfaces and returns a slice of strings
|
||||
func ToStrs(slice []interface{}) []string {
|
||||
results := []string{}
|
||||
|
||||
for _, val := range slice {
|
||||
switch val.(type) {
|
||||
case int:
|
||||
results = append(results, strconv.Itoa(val.(int)))
|
||||
case string:
|
||||
results = append(results, val.(string))
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
44
utils/conversions_test.go
Normal file
44
utils/conversions_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_MapToStrs(t *testing.T) {
|
||||
expected := map[string]string{
|
||||
"a": "a",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
}
|
||||
|
||||
source := make(map[string]interface{})
|
||||
for _, val := range expected {
|
||||
source[val] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, MapToStrs(source))
|
||||
}
|
||||
|
||||
func Test_ToInts(t *testing.T) {
|
||||
expected := []int{1, 2, 3}
|
||||
|
||||
source := make([]interface{}, len(expected))
|
||||
for idx, val := range expected {
|
||||
source[idx] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, ToInts(source))
|
||||
}
|
||||
|
||||
func Test_ToStrs(t *testing.T) {
|
||||
expected := []string{"cat", "dog", "rat"}
|
||||
|
||||
source := make([]interface{}, len(expected))
|
||||
for idx, val := range expected {
|
||||
source[idx] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, ToStrs(source))
|
||||
}
|
35
utils/email_addresses.go
Normal file
35
utils/email_addresses.go
Normal file
@ -0,0 +1,35 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// NameFromEmail takes an email address and returns the part that comes before the @ symbol
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// NameFromEmail("test_user@example.com")
|
||||
// > "Test_user"
|
||||
//
|
||||
func NameFromEmail(email string) string {
|
||||
parts := strings.Split(email, "@")
|
||||
return strings.Title(strings.Replace(parts[0], ".", " ", -1))
|
||||
}
|
||||
|
||||
// NamesFromEmails takes a slice of email addresses and returns a slice of the parts that
|
||||
// come before the @ symbol
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// NamesFromEmail("test_user@example.com", "other_user@example.com")
|
||||
// > []string{"Test_user", "Other_user"}
|
||||
//
|
||||
func NamesFromEmails(emails []string) []string {
|
||||
names := []string{}
|
||||
|
||||
for _, email := range emails {
|
||||
names = append(names, NameFromEmail(email))
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
22
utils/email_addresses_test.go
Normal file
22
utils/email_addresses_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_NameFromEmail(t *testing.T) {
|
||||
Equal(t, "", NameFromEmail(""))
|
||||
Equal(t, "Chris Cummer", NameFromEmail("chris.cummer@me.com"))
|
||||
}
|
||||
|
||||
func Test_NamesFromEmails(t *testing.T) {
|
||||
var result []string
|
||||
|
||||
result = NamesFromEmails([]string{})
|
||||
Equal(t, []string{}, result)
|
||||
|
||||
result = NamesFromEmails([]string{"chris.cummer@me.com", "chriscummer@me.com"})
|
||||
Equal(t, []string{"Chris Cummer", "Chriscummer"}, result)
|
||||
}
|
@ -10,47 +10,7 @@ import (
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
func lowercaseTitle(title string) string {
|
||||
if title == "" {
|
||||
return ""
|
||||
}
|
||||
r, n := utf8.DecodeRuneInString(title)
|
||||
return string(unicode.ToLower(r)) + title[n:]
|
||||
}
|
||||
|
||||
var (
|
||||
openColorRegex = regexp.MustCompile(`\[.*?\]`)
|
||||
)
|
||||
|
||||
func StripColorTags(input string) string {
|
||||
return openColorRegex.ReplaceAllString(input, "")
|
||||
}
|
||||
|
||||
func helpFromValue(field reflect.StructField) string {
|
||||
result := ""
|
||||
|
||||
optional, err := strconv.ParseBool(field.Tag.Get("optional"))
|
||||
if err != nil {
|
||||
optional = false
|
||||
}
|
||||
|
||||
help := field.Tag.Get("help")
|
||||
if optional {
|
||||
help = "Optional " + help
|
||||
}
|
||||
|
||||
values := field.Tag.Get("values")
|
||||
if help != "" {
|
||||
result += "\n\n " + lowercaseTitle(field.Name)
|
||||
result += "\n " + help
|
||||
|
||||
if values != "" {
|
||||
result += "\n Values: " + values
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func HelpFromInterface(item interface{}) string {
|
||||
result := ""
|
||||
@ -78,3 +38,45 @@ func HelpFromInterface(item interface{}) string {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// StripColorTags removes tcell color tags from a given string
|
||||
func StripColorTags(input string) string {
|
||||
openColorRegex := regexp.MustCompile(`\[.*?\]`)
|
||||
return openColorRegex.ReplaceAllString(input, "")
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func helpFromValue(field reflect.StructField) string {
|
||||
result := ""
|
||||
|
||||
optional, err := strconv.ParseBool(field.Tag.Get("optional"))
|
||||
if err != nil {
|
||||
optional = false
|
||||
}
|
||||
|
||||
help := field.Tag.Get("help")
|
||||
if optional {
|
||||
help = "Optional " + help
|
||||
}
|
||||
|
||||
values := field.Tag.Get("values")
|
||||
if help != "" {
|
||||
result += "\n\n " + lowercaseTitle(field.Name)
|
||||
result += "\n " + help
|
||||
|
||||
if values != "" {
|
||||
result += "\n Values: " + values
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func lowercaseTitle(title string) string {
|
||||
if title == "" {
|
||||
return ""
|
||||
}
|
||||
r, n := utf8.DecodeRuneInString(title)
|
||||
return string(unicode.ToLower(r)) + title[n:]
|
||||
}
|
||||
|
@ -10,21 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Dir returns the home directory for the executing user.
|
||||
// An error is returned if a home directory cannot be detected.
|
||||
func Home() (string, error) {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if currentUser.HomeDir == "" {
|
||||
return "", errors.New("cannot find user-specific home dir")
|
||||
}
|
||||
|
||||
return currentUser.HomeDir, nil
|
||||
}
|
||||
|
||||
// Expand expands the path to include the home directory if the path
|
||||
// ExpandHomeDir expands the path to include the home directory if the path
|
||||
// is prefixed with `~`. If it isn't prefixed with `~`, the path is
|
||||
// returned as-is.
|
||||
func ExpandHomeDir(path string) (string, error) {
|
||||
@ -47,3 +33,18 @@ func ExpandHomeDir(path string) (string, error) {
|
||||
|
||||
return filepath.Join(dir, path[1:]), nil
|
||||
}
|
||||
|
||||
// Home returns the home directory for the executing user.
|
||||
// An error is returned if a home directory cannot be detected.
|
||||
func Home() (string, error) {
|
||||
currentUser, err := user.Current()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if currentUser.HomeDir == "" {
|
||||
return "", errors.New("cannot find user-specific home dir")
|
||||
}
|
||||
|
||||
return currentUser.HomeDir, nil
|
||||
}
|
||||
|
9
utils/init.go
Normal file
9
utils/init.go
Normal file
@ -0,0 +1,9 @@
|
||||
package utils
|
||||
|
||||
// OpenFileUtil defines the system utility to use to open files
|
||||
var OpenFileUtil = "open"
|
||||
|
||||
// Init initializes global settings in the wtf package
|
||||
func Init(openFileUtil string) {
|
||||
OpenFileUtil = openFileUtil
|
||||
}
|
12
utils/init_test.go
Normal file
12
utils/init_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Init(t *testing.T) {
|
||||
Init("cats")
|
||||
Equal(t, OpenFileUtil, "cats")
|
||||
}
|
48
utils/text.go
Normal file
48
utils/text.go
Normal file
@ -0,0 +1,48 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
// 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
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// x := CenterText("cat", 11)
|
||||
// > " cat "
|
||||
//
|
||||
func CenterText(str string, width int) string {
|
||||
if width < 0 {
|
||||
width = 0
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
||||
}
|
||||
|
||||
// HighlightableHelper pads the given text with blank spaces to the width of the view
|
||||
// containing it. This is helpful for extending row highlighting across the entire width
|
||||
// of the view
|
||||
func HighlightableHelper(view *tview.TextView, input string, idx, offset int) string {
|
||||
fmtStr := fmt.Sprintf(`["%d"][""]`, idx)
|
||||
_, _, w, _ := view.GetInnerRect()
|
||||
fmtStr += input
|
||||
fmtStr += RowPadding(offset, w+1)
|
||||
fmtStr += `[""]` + "\n"
|
||||
return fmtStr
|
||||
}
|
||||
|
||||
// RowPadding returns a padding for a row to make it the full width of the containing widget.
|
||||
// Useful for ensurig row highlighting spans the full width (I suspect tcell has a better
|
||||
// way to do this, but I haven't yet found it)
|
||||
func RowPadding(offset int, max int) string {
|
||||
padSize := max - offset
|
||||
if padSize < 0 {
|
||||
padSize = 0
|
||||
}
|
||||
|
||||
return strings.Repeat(" ", padSize)
|
||||
}
|
24
utils/text_test.go
Normal file
24
utils/text_test.go
Normal file
@ -0,0 +1,24 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_CenterText(t *testing.T) {
|
||||
Equal(t, "cat", CenterText("cat", -9))
|
||||
Equal(t, "cat", CenterText("cat", 0))
|
||||
Equal(t, " cat ", CenterText("cat", 9))
|
||||
}
|
||||
|
||||
func Test_HighlightableHelper(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func Test_RowPadding(t *testing.T) {
|
||||
Equal(t, "", RowPadding(0, 0))
|
||||
Equal(t, "", RowPadding(5, 2))
|
||||
Equal(t, " ", RowPadding(1, 2))
|
||||
Equal(t, " ", RowPadding(0, 5))
|
||||
}
|
106
utils/utils.go
Normal file
106
utils/utils.go
Normal file
@ -0,0 +1,106 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
SimpleDateFormat = "Jan 2"
|
||||
SimpleTimeFormat = "15:04 MST"
|
||||
MinimumTimeFormat = "15:04"
|
||||
|
||||
FullDateFormat = "Monday, Jan 2"
|
||||
FriendlyDateFormat = "Mon, Jan 2"
|
||||
FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
||||
|
||||
TimestampFormat = "2006-01-02T15:04:05-0700"
|
||||
)
|
||||
|
||||
// DoesNotInclude takes a slice of strings and a target string and returns
|
||||
// TRUE if the slice does not include the target, FALSE if it does
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// x := DoesNotInclude([]string{"cat", "dog", "rat"}, "dog")
|
||||
// > false
|
||||
//
|
||||
// x := DoesNotInclude([]string{"cat", "dog", "rat"}, "pig")
|
||||
// > true
|
||||
//
|
||||
func DoesNotInclude(strs []string, val string) bool {
|
||||
for _, str := range strs {
|
||||
if val == str {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ExecuteCommand executes an external command on the local machine as the current user
|
||||
func ExecuteCommand(cmd *exec.Cmd) string {
|
||||
if cmd == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
// FindMatch takes a regex pattern and a string of data and returns back all the matches
|
||||
// in that string
|
||||
func FindMatch(pattern string, data string) [][]string {
|
||||
r := regexp.MustCompile(pattern)
|
||||
return r.FindAllStringSubmatch(data, -1)
|
||||
}
|
||||
|
||||
// OpenFile opens the file defined in `path` via the operating system
|
||||
func OpenFile(path string) {
|
||||
if (strings.HasPrefix(path, "http://")) || (strings.HasPrefix(path, "https://")) {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
exec.Command("xdg-open", path).Start()
|
||||
case "windows":
|
||||
exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start()
|
||||
case "darwin":
|
||||
exec.Command("open", path).Start()
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
filePath, _ := ExpandHomeDir(path)
|
||||
cmd := exec.Command(OpenFileUtil, filePath)
|
||||
ExecuteCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
// ReadFileBytes reads the contents of a file and returns those contents as a slice of bytes
|
||||
func ReadFileBytes(filePath string) ([]byte, error) {
|
||||
fileData, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return fileData, nil
|
||||
}
|
75
utils/utils_test.go
Normal file
75
utils/utils_test.go
Normal file
@ -0,0 +1,75 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_DoesNotInclude(t *testing.T) {
|
||||
Equal(t, true, DoesNotInclude([]string{"cat", "dog", "rat"}, "bat"))
|
||||
Equal(t, false, DoesNotInclude([]string{"cat", "dog", "rat"}, "dog"))
|
||||
}
|
||||
|
||||
func Test_ExecuteCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cmd *exec.Cmd
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "with nil command",
|
||||
cmd: nil,
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "with defined command",
|
||||
cmd: exec.Command("echo", "cats"),
|
||||
expected: "cats\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
actual := ExecuteCommand(tt.cmd)
|
||||
|
||||
if tt.expected != actual {
|
||||
t.Errorf("\nexpected: %s\n got: %s", tt.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FindMatch(t *testing.T) {
|
||||
var result [][]string
|
||||
|
||||
expected := [][]string([][]string{[]string{"SSID: 7E5B5C", "7E5B5C"}})
|
||||
result = FindMatch(`s*SSID: (.+)s*`, "SSID: 7E5B5C")
|
||||
Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func Test_ReadFileBytes(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
file string
|
||||
expected []byte
|
||||
}{
|
||||
{
|
||||
name: "with non-existant file",
|
||||
file: "/tmp/junk-daa6bf613f4c.md",
|
||||
expected: []byte{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
actual, _ := ReadFileBytes(tt.file)
|
||||
|
||||
if reflect.DeepEqual(tt.expected, actual) == false {
|
||||
t.Errorf("\nexpected: %q\n got: %q", tt.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
223
wtf/utils.go
223
wtf/utils.go
@ -1,223 +0,0 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
SimpleDateFormat = "Jan 2"
|
||||
SimpleTimeFormat = "15:04 MST"
|
||||
MinimumTimeFormat = "15:04"
|
||||
|
||||
FullDateFormat = "Monday, Jan 2"
|
||||
FriendlyDateFormat = "Mon, Jan 2"
|
||||
FriendlyDateTimeFormat = "Mon, Jan 2, 15:04"
|
||||
|
||||
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
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// x := CenterText("cat", 11)
|
||||
// > " cat "
|
||||
//
|
||||
func CenterText(str string, width int) string {
|
||||
if width < 0 {
|
||||
width = 0
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))
|
||||
}
|
||||
|
||||
// ExecuteCommand executes an external command on the local machine as the current user
|
||||
func ExecuteCommand(cmd *exec.Cmd) string {
|
||||
if cmd == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
var str string
|
||||
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||
str += string(b)
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if err != nil {
|
||||
return fmt.Sprintf("%v\n", err)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
// Exclude takes a slice of strings and a target string and returns the contents of the original
|
||||
// slice of strings without the target string in it
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// x := Exclude([]string{"cat", "dog", "rat"}, "dog")
|
||||
// > []string{"cat", "rat"}
|
||||
//
|
||||
func Exclude(strs []string, val string) bool {
|
||||
for _, str := range strs {
|
||||
if val == str {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// FindMatch takes a regex pattern and a string of data and returns back all the matches
|
||||
// in that string
|
||||
func FindMatch(pattern string, data string) [][]string {
|
||||
r := regexp.MustCompile(pattern)
|
||||
return r.FindAllStringSubmatch(data, -1)
|
||||
}
|
||||
|
||||
// NameFromEmail takes an email address and returns the part that comes before the @ symbol
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// NameFromEmail("test_user@example.com")
|
||||
// > "Test_user"
|
||||
//
|
||||
func NameFromEmail(email string) string {
|
||||
parts := strings.Split(email, "@")
|
||||
return strings.Title(strings.Replace(parts[0], ".", " ", -1))
|
||||
}
|
||||
|
||||
// NamesFromEmails takes a slice of email addresses and returns a slice of the parts that
|
||||
// come before the @ symbol
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// NamesFromEmail("test_user@example.com", "other_user@example.com")
|
||||
// > []string{"Test_user", "Other_user"}
|
||||
//
|
||||
func NamesFromEmails(emails []string) []string {
|
||||
names := []string{}
|
||||
|
||||
for _, email := range emails {
|
||||
names = append(names, NameFromEmail(email))
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
// OpenFile opens the file defined in `path` via the operating system
|
||||
func OpenFile(path string) {
|
||||
if (strings.HasPrefix(path, "http://")) || (strings.HasPrefix(path, "https://")) {
|
||||
switch runtime.GOOS {
|
||||
case "linux":
|
||||
exec.Command("xdg-open", path).Start()
|
||||
case "windows":
|
||||
exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start()
|
||||
case "darwin":
|
||||
exec.Command("open", path).Start()
|
||||
default:
|
||||
}
|
||||
} else {
|
||||
filePath, _ := utils.ExpandHomeDir(path)
|
||||
cmd := exec.Command(OpenFileUtil, filePath)
|
||||
ExecuteCommand(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
// PadRow returns a padding for a row to make it the full width of the containing widget.
|
||||
// Useful for ensurig row highlighting spans the full width (I suspect tcell has a better
|
||||
// way to do this, but I haven't yet found it)
|
||||
func PadRow(offset int, max int) string {
|
||||
padSize := max - offset
|
||||
if padSize < 0 {
|
||||
padSize = 0
|
||||
}
|
||||
|
||||
return strings.Repeat(" ", padSize)
|
||||
}
|
||||
|
||||
// ReadFileBytes reads the contents of a file and returns those contents as a slice of bytes
|
||||
func ReadFileBytes(filePath string) ([]byte, error) {
|
||||
fileData, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
/* -------------------- Map Conversion -------------------- */
|
||||
|
||||
// MapToStrs takes a map of interfaces and returns a map of strings
|
||||
func MapToStrs(aMap map[string]interface{}) map[string]string {
|
||||
results := make(map[string]string)
|
||||
|
||||
for key, val := range aMap {
|
||||
results[key] = val.(string)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
/* -------------------- Slice Conversion -------------------- */
|
||||
|
||||
// ToInts takes a slice of interfaces and returns a slice of ints
|
||||
func ToInts(slice []interface{}) []int {
|
||||
results := []int{}
|
||||
|
||||
for _, val := range slice {
|
||||
results = append(results, val.(int))
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
// ToStrs takes a slice of interfaces and returns a slice of strings
|
||||
func ToStrs(slice []interface{}) []string {
|
||||
results := []string{}
|
||||
|
||||
for _, val := range slice {
|
||||
switch val.(type) {
|
||||
case int:
|
||||
results = append(results, strconv.Itoa(val.(int)))
|
||||
case string:
|
||||
results = append(results, val.(string))
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
func HighlightableHelper(view *tview.TextView, input string, idx, offset int) string {
|
||||
fmtStr := fmt.Sprintf(`["%d"][""]`, idx)
|
||||
_, _, w, _ := view.GetInnerRect()
|
||||
fmtStr += input
|
||||
fmtStr += PadRow(offset, w+1)
|
||||
fmtStr += `[""]` + "\n"
|
||||
return fmtStr
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
. "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Init(t *testing.T) {
|
||||
Init("cats")
|
||||
Equal(t, OpenFileUtil, "cats")
|
||||
}
|
||||
|
||||
func Test_CenterText(t *testing.T) {
|
||||
Equal(t, "cat", CenterText("cat", -9))
|
||||
Equal(t, "cat", CenterText("cat", 0))
|
||||
Equal(t, " cat ", CenterText("cat", 9))
|
||||
}
|
||||
|
||||
func Test_ExecuteCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cmd *exec.Cmd
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "with nil command",
|
||||
cmd: nil,
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "with defined command",
|
||||
cmd: exec.Command("echo", "cats"),
|
||||
expected: "cats\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
actual := ExecuteCommand(tt.cmd)
|
||||
|
||||
if tt.expected != actual {
|
||||
t.Errorf("\nexpected: %s\n got: %s", tt.expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FindMatch(t *testing.T) {
|
||||
var result [][]string
|
||||
|
||||
expected := [][]string([][]string{[]string{"SSID: 7E5B5C", "7E5B5C"}})
|
||||
result = FindMatch(`s*SSID: (.+)s*`, "SSID: 7E5B5C")
|
||||
Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func Test_ExcludeWhenTrue(t *testing.T) {
|
||||
Equal(t, true, Exclude([]string{"cat", "dog", "rat"}, "bat"))
|
||||
Equal(t, false, Exclude([]string{"cat", "dog", "rat"}, "dog"))
|
||||
}
|
||||
|
||||
func Test_NameFromEmail(t *testing.T) {
|
||||
Equal(t, "", NameFromEmail(""))
|
||||
Equal(t, "Chris Cummer", NameFromEmail("chris.cummer@me.com"))
|
||||
}
|
||||
|
||||
func Test_NamesFromEmails(t *testing.T) {
|
||||
var result []string
|
||||
|
||||
result = NamesFromEmails([]string{})
|
||||
Equal(t, []string{}, result)
|
||||
|
||||
result = NamesFromEmails([]string{"chris.cummer@me.com", "chriscummer@me.com"})
|
||||
Equal(t, []string{"Chris Cummer", "Chriscummer"}, result)
|
||||
}
|
||||
|
||||
func Test_PadRow(t *testing.T) {
|
||||
Equal(t, "", PadRow(0, 0))
|
||||
Equal(t, "", PadRow(5, 2))
|
||||
Equal(t, " ", PadRow(1, 2))
|
||||
}
|
||||
|
||||
func Test_MapToStrs(t *testing.T) {
|
||||
expected := map[string]string{
|
||||
"a": "a",
|
||||
"b": "b",
|
||||
"c": "c",
|
||||
}
|
||||
|
||||
source := make(map[string]interface{})
|
||||
for _, val := range expected {
|
||||
source[val] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, MapToStrs(source))
|
||||
}
|
||||
|
||||
func Test_ToInts(t *testing.T) {
|
||||
expected := []int{1, 2, 3}
|
||||
|
||||
source := make([]interface{}, len(expected))
|
||||
for idx, val := range expected {
|
||||
source[idx] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, ToInts(source))
|
||||
}
|
||||
|
||||
func Test_ToStrs(t *testing.T) {
|
||||
expected := []string{"cat", "dog", "rat"}
|
||||
|
||||
source := make([]interface{}, len(expected))
|
||||
for idx, val := range expected {
|
||||
source[idx] = val
|
||||
}
|
||||
|
||||
Equal(t, expected, ToStrs(source))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user