diff --git a/cfg/common_settings.go b/cfg/common_settings.go index 8d7a8c39..e51e8bd5 100644 --- a/cfg/common_settings.go +++ b/cfg/common_settings.go @@ -1,6 +1,9 @@ package cfg import ( + "fmt" + "strings" + "github.com/olebedev/config" ) @@ -10,10 +13,16 @@ type Colors struct { BorderFocused string BorderNormal string Checked string + Foreground string HighlightFore string HighlightBack string Text string Title string + + Rows struct { + Even string + Odd string + } } type Module struct { @@ -29,8 +38,14 @@ type Position struct { } type Sigils struct { - CheckedIcon string - UncheckedIcon string + Checkbox struct { + Checked string + Unchecked string + } + Paging struct { + Normal string + Selected string + } } type Common struct { @@ -53,11 +68,12 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) common := Common{ Colors: Colors{ - Background: ymlConfig.UString(modulePath+".colors.background", ymlConfig.UString(colorsPath+".background", "black")), + Background: ymlConfig.UString(modulePath+".background", ymlConfig.UString(colorsPath+".background", "black")), BorderFocusable: ymlConfig.UString(colorsPath+".border.focusable", "red"), BorderFocused: ymlConfig.UString(colorsPath+".border.focused", "orange"), BorderNormal: ymlConfig.UString(colorsPath+".border.normal", "gray"), Checked: ymlConfig.UString(colorsPath+".checked", "white"), + Foreground: ymlConfig.UString(modulePath+".foreground", ymlConfig.UString(colorsPath+".foreground", "white")), HighlightFore: ymlConfig.UString(colorsPath+".highlight.fore", "black"), HighlightBack: ymlConfig.UString(colorsPath+".highlight.back", "green"), Text: ymlConfig.UString(modulePath+".colors.text", ymlConfig.UString(colorsPath+".text", "white")), @@ -76,16 +92,54 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) Width: ymlConfig.UInt(positionPath + ".width"), }, - Sigils: Sigils{ - CheckedIcon: ymlConfig.UString(sigilsPath+".checkedIcon", "x"), - UncheckedIcon: ymlConfig.UString(sigilsPath+".uncheckedIcon", " "), - }, - Enabled: ymlConfig.UBool(modulePath+".enabled", false), FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1), RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300), Title: ymlConfig.UString(modulePath+".title", name), } + common.Colors.Rows.Even = ymlConfig.UString(modulePath+".colors.rows.even", ymlConfig.UString(colorsPath+".rows.even", "white")) + common.Colors.Rows.Odd = ymlConfig.UString(modulePath+".colors.rows.even", ymlConfig.UString(colorsPath+".rows.odd", "lightblue")) + + common.Sigils.Checkbox.Checked = ymlConfig.UString(sigilsPath+".Checkbox.Checked", "x") + common.Sigils.Checkbox.Unchecked = ymlConfig.UString(sigilsPath+".Checkbox.Unchecked", " ") + + common.Sigils.Paging.Normal = ymlConfig.UString(sigilsPath+".Paging.Normal", ymlConfig.UString("wtf.paging.pageSigil", "*")) + common.Sigils.Paging.Selected = ymlConfig.UString(sigilsPath+".Paging.Select", ymlConfig.UString("wtf.paging.selectedSigil", "_")) + return &common } + +func (common *Common) DefaultFocussedRowColor() string { + return fmt.Sprintf("%s:%s", common.Colors.HighlightFore, common.Colors.HighlightBack) +} + +func (common *Common) DefaultRowColor() string { + return fmt.Sprintf("%s:%s", common.Colors.Foreground, common.Colors.Background) +} + +func (common *Common) RowColor(idx int) string { + if idx%2 == 0 { + return common.Colors.Rows.Even + } + + return common.Colors.Rows.Odd +} + +func (common *Common) RightAlignFormat(width int) string { + return fmt.Sprintf("%%%ds", width-1) +} + +func (common *Common) SigilStr(len, pos int, width int) string { + sigils := "" + + if len > 1 { + sigils = strings.Repeat(common.Sigils.Paging.Normal, pos) + sigils = sigils + common.Sigils.Paging.Selected + sigils = sigils + strings.Repeat(common.Sigils.Paging.Normal, len-1-pos) + + sigils = "[lightblue]" + fmt.Sprintf(common.RightAlignFormat(width), sigils) + "[white]" + } + + return sigils +} diff --git a/generator/textwidget.tpl b/generator/textwidget.tpl index e3ebd214..f1fe45b4 100644 --- a/generator/textwidget.tpl +++ b/generator/textwidget.tpl @@ -23,7 +23,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), - TextWidget: wtf.NewTextWidget(app, "{{(Title .Name)}}", "{{(Lower .Name)}}", true), + TextWidget: wtf.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/gerrit/display.go b/modules/gerrit/display.go index fc320013..083cb644 100644 --- a/modules/gerrit/display.go +++ b/modules/gerrit/display.go @@ -2,8 +2,6 @@ package gerrit import ( "fmt" - - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display() { @@ -16,7 +14,8 @@ func (widget *Widget) display() { widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s- %s", widget.Name(), widget.title(project)))) - str := wtf.SigilStr(len(widget.GerritProjects), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n" str = str + " [red]Stats[white]\n" str = str + widget.displayStats(project) str = str + "\n" @@ -64,11 +63,12 @@ func (widget *Widget) displayStats(project *GerritProject) string { return str } -func (widget *Widget) rowColor(index int) string { - if widget.View.HasFocus() && (index == widget.selected) { - return wtf.DefaultFocussedRowColor() +func (widget *Widget) rowColor(idx int) string { + if widget.View.HasFocus() && (idx == widget.selected) { + widget.settings.common.DefaultFocussedRowColor() } - return wtf.RowColor("gerrit", index) + + return widget.settings.common.RowColor(idx) } func (widget *Widget) title(project *GerritProject) string { diff --git a/modules/git/display.go b/modules/git/display.go index 546b3f6e..994b6118 100644 --- a/modules/git/display.go +++ b/modules/git/display.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" "unicode/utf8" - - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display() { @@ -18,7 +16,8 @@ func (widget *Widget) display() { title := fmt.Sprintf("%s - [green]%s[white]", widget.Name(), repoData.Repository) widget.View.SetTitle(widget.ContextualTitle(title)) - str := wtf.SigilStr(len(widget.GitRepos), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.GitRepos), widget.Idx, width) + "\n" str = str + " [red]Branch[white]\n" str = str + fmt.Sprintf(" %s", repoData.Branch) str = str + "\n" diff --git a/modules/github/display.go b/modules/github/display.go index 1819efa2..df236ebf 100644 --- a/modules/github/display.go +++ b/modules/github/display.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/google/go-github/github" - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display() { @@ -16,7 +15,8 @@ func (widget *Widget) display() { widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), widget.title(repo)))) - str := wtf.SigilStr(len(widget.GithubRepos), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.GithubRepos), widget.Idx, width) + "\n" str = str + " [red]Stats[white]\n" str = str + widget.displayStats(repo) str = str + "\n" diff --git a/modules/gitlab/display.go b/modules/gitlab/display.go index 51cdfcc9..0d5ad39e 100644 --- a/modules/gitlab/display.go +++ b/modules/gitlab/display.go @@ -2,8 +2,6 @@ package gitlab import ( "fmt" - - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display() { @@ -16,7 +14,8 @@ func (widget *Widget) display() { widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.Name(), widget.title(project))) - str := wtf.SigilStr(len(widget.GitlabProjects), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.GitlabProjects), widget.Idx, width) + "\n" str = str + " [red]Stats[white]\n" str = str + widget.displayStats(project) str = str + "\n" diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 3411e67f..a0dab800 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -116,10 +116,10 @@ func (widget *Widget) contentFrom(messages []Message) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - return wtf.RowColor("gitter", idx) + return widget.settings.common.RowColor(idx) } func (widget *Widget) next() { diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index d9798d25..5ca9daf5 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -123,10 +123,10 @@ func (widget *Widget) contentFrom(stories []Story) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - return wtf.RowColor("hackernews", idx) + return widget.settings.common.RowColor(idx) } func (widget *Widget) next() { diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index 145c397b..907a9d33 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -112,10 +112,10 @@ func (widget *Widget) contentFrom(view *View) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - return wtf.DefaultRowColor() + return widget.settings.common.RowColor(idx) } func (widget *Widget) jobColor(job *Job) string { diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 91047552..8a8713c8 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -138,14 +138,10 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - if idx%2 == 0 { - return widget.settings.colors.rows.even - } - - return widget.settings.colors.rows.odd + return widget.settings.common.RowColor(idx) } func (widget *Widget) issueTypeColor(issue *Issue) string { diff --git a/modules/mercurial/display.go b/modules/mercurial/display.go index 724baddb..37a42f28 100644 --- a/modules/mercurial/display.go +++ b/modules/mercurial/display.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" "unicode/utf8" - - "github.com/wtfutil/wtf/wtf" ) func (widget *Widget) display() { @@ -18,7 +16,8 @@ func (widget *Widget) display() { title := fmt.Sprintf("%s - [green]%s[white]", widget.Name(), repoData.Repository) widget.View.SetTitle(widget.ContextualTitle(title)) - str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" str = str + " [red]Branch:Bookmark[white]\n" str = str + fmt.Sprintf(" %s:%s\n", repoData.Branch, repoData.Bookmark) str = str + "\n" diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 985b7079..ba8f5b37 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -110,9 +110,10 @@ func (widget *Widget) contentFrom(result *Result) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - return "white" + + return widget.settings.common.RowColor(idx) } func statusColor(item *Item) string { diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index c0d01778..c4e29f80 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -76,7 +76,8 @@ func (widget *Widget) display() { title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource()) title = widget.ContextualTitle(title) - text := wtf.SigilStr(len(widget.Sources), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + text := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n" if widget.settings.format { text = text + widget.formattedText() diff --git a/modules/todo/display.go b/modules/todo/display.go index 2471438c..dae2a963 100644 --- a/modules/todo/display.go +++ b/modules/todo/display.go @@ -14,8 +14,8 @@ const checkWidth = 4 func (widget *Widget) display() { str := "" newList := checklist.NewChecklist( - widget.settings.common.Sigils.CheckedIcon, - widget.settings.common.Sigils.UncheckedIcon, + widget.settings.common.Sigils.Checkbox.Checked, + widget.settings.common.Sigils.Checkbox.Unchecked, ) offset := 0 diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 51367b38..efc6c158 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -54,7 +54,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * app: app, settings: settings, filePath: settings.filePath, - list: checklist.NewChecklist(settings.common.Sigils.CheckedIcon, settings.common.Sigils.UncheckedIcon), + list: checklist.NewChecklist(settings.common.Sigils.Checkbox.Checked, settings.common.Sigils.Checkbox.Unchecked), pages: pages, } @@ -234,8 +234,8 @@ func (widget *Widget) persist() { // items have the correct checked/unchecked icon per the user's preferences func (widget *Widget) setItemChecks() { for _, item := range widget.list.Items { - item.CheckedIcon = widget.settings.common.CheckedIcon - item.UncheckedIcon = widget.settings.common.UncheckedIcon + item.CheckedIcon = widget.settings.common.Checkbox.Checked + item.UncheckedIcon = widget.settings.common.Checkbox.Unchecked } } diff --git a/modules/todoist/display.go b/modules/todoist/display.go index 56c5be64..fbd7d3f2 100644 --- a/modules/todoist/display.go +++ b/modules/todoist/display.go @@ -19,7 +19,8 @@ func (widget *Widget) display() { title := fmt.Sprintf("[green]%s[white]", proj.Project.Name) widget.View.SetTitle(widget.ContextualTitle(title)) - str := wtf.SigilStr(len(widget.projects), widget.idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.projects), widget.idx, width) + "\n" maxLen := proj.LongestLine() diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index 1265c176..bea587a5 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -102,9 +102,10 @@ func (widget *Widget) contentFrom(builds *Builds) string { func (widget *Widget) rowColor(idx int) string { if widget.View.HasFocus() && (idx == widget.selected) { - return wtf.DefaultFocussedRowColor() + widget.settings.common.DefaultFocussedRowColor() } - return "White" + + return widget.settings.common.RowColor(idx) } func buildColor(build *Build) string { diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index b2056932..16383ac1 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -79,7 +79,8 @@ func (widget *Widget) display() { return } - str := wtf.SigilStr(len(widget.Sources), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + str := widget.settings.common.SigilStr(len(widget.Sources), widget.Idx, width) + "\n" for _, tweet := range tweets { str = str + widget.format(tweet) } diff --git a/modules/weatherservices/weather/display.go b/modules/weatherservices/weather/display.go index 929e4b57..cc357cc2 100644 --- a/modules/weatherservices/weather/display.go +++ b/modules/weatherservices/weather/display.go @@ -27,7 +27,8 @@ func (widget *Widget) display() { widget.View.SetTitle(widget.title(cityData)) - content := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n" + _, _, width, _ := widget.View.GetRect() + content := widget.settings.common.SigilStr(len(widget.Data), widget.Idx, width) + "\n" content = content + widget.description(cityData) + "\n\n" content = content + widget.temperatures(cityData) + "\n" content = content + widget.sunInfo(cityData) diff --git a/wtf/utils.go b/wtf/utils.go index 49726e8b..a802f6cc 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -7,8 +7,6 @@ import ( "regexp" "runtime" "strings" - - "github.com/rivo/tview" ) const SimpleDateFormat = "Jan 2" @@ -27,20 +25,6 @@ func CenterText(str string, width int) string { return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str)) } -func DefaultFocussedRowColor() string { - foreColor := Config.UString("wtf.colors.highlight.fore", "black") - backColor := Config.UString("wtf.colors.highlight.back", "orange") - - return fmt.Sprintf("%s:%s", foreColor, backColor) -} - -func DefaultRowColor() string { - foreColor := Config.UString("wtf.colors.foreground", "white") - backColor := Config.UString("wtf.colors.background", "black") - - return fmt.Sprintf("%s:%s", foreColor, backColor) -} - func ExecuteCommand(cmd *exec.Cmd) string { stdout, err := cmd.StdoutPipe() if err != nil { @@ -134,37 +118,6 @@ func ReadFileBytes(filePath string) ([]byte, error) { return fileData, nil } -func RightAlignFormat(view *tview.TextView) string { - _, _, w, _ := view.GetInnerRect() - - return fmt.Sprintf("%%%ds", w-1) -} - -func RowColor(module string, idx int) string { - evenKey := fmt.Sprintf("wtf.mods.%s.colors.rows.even", module) - oddKey := fmt.Sprintf("wtf.mods.%s.colors.rows.odd", module) - - if idx%2 == 0 { - return Config.UString(evenKey, "white") - } - - return Config.UString(oddKey, "lightblue") -} - -func SigilStr(len, pos int, view *tview.TextView) string { - sigils := "" - - if len > 1 { - sigils = strings.Repeat(Config.UString("wtf.paging.pageSigil", "*"), pos) - sigils = sigils + Config.UString("wtf.paging.selectedSigil", "_") - sigils = sigils + strings.Repeat(Config.UString("wtf.paging.pageSigil", "*"), len-1-pos) - - sigils = "[lightblue]" + fmt.Sprintf(RightAlignFormat(view), sigils) + "[white]" - } - - return sigils -} - /* -------------------- Map Conversion -------------------- */ func MapToStrs(aMap map[string]interface{}) map[string]string {