diff --git a/bamboohr/widget.go b/bamboohr/widget.go index f464d49f..5d5e300a 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -12,7 +12,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" BambooHR ", "bamboohr", false), + TextWidget: wtf.NewTextWidget("BambooHR", "bamboohr", false), } return &widget @@ -29,7 +29,7 @@ func (widget *Widget) Refresh() { ) widget.UpdateRefreshedAt() - widget.View.SetTitle(fmt.Sprintf("%s (%d) ", widget.Name, len(todayItems))) + widget.View.SetTitle(widget.ContextualTitle(widget.Name)) widget.View.SetText(widget.contentFrom(todayItems)) } diff --git a/circleci/widget.go b/circleci/widget.go index 98dbf116..8323a786 100644 --- a/circleci/widget.go +++ b/circleci/widget.go @@ -11,7 +11,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" CircleCI ", "circleci", false), + TextWidget: wtf.NewTextWidget("CircleCI", "circleci", false), } return &widget diff --git a/clocks/widget.go b/clocks/widget.go index 2d124bcd..2b2678f0 100644 --- a/clocks/widget.go +++ b/clocks/widget.go @@ -15,7 +15,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" World Clocks ", "clocks", false), + TextWidget: wtf.NewTextWidget("World Clocks", "clocks", false), } widget.clockColl = widget.buildClockCollection(wtf.Config.UMap("wtf.mods.clocks.locations")) diff --git a/gcal/widget.go b/gcal/widget.go index 7ad4bc25..011215dc 100644 --- a/gcal/widget.go +++ b/gcal/widget.go @@ -17,7 +17,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Calendar ", "gcal", false), + TextWidget: wtf.NewTextWidget("Calendar", "gcal", false), ch: make(chan struct{}), } diff --git a/gerrit/widget.go b/gerrit/widget.go index af506257..0f3f2095 100644 --- a/gerrit/widget.go +++ b/gerrit/widget.go @@ -68,7 +68,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { } widget := Widget{ - TextWidget: wtf.NewTextWidget(" Gerrit ", "gerrit", true), + TextWidget: wtf.NewTextWidget("Gerrit", "gerrit", true), app: app, pages: pages, diff --git a/git/display.go b/git/display.go index 33842728..aedbf36c 100644 --- a/git/display.go +++ b/git/display.go @@ -15,8 +15,8 @@ func (widget *Widget) display() { return } - title := fmt.Sprintf("[green]%s[white]\n", repoData.Repository) - widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.Name, title)) + 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" str = str + " [red]Branch[white]\n" diff --git a/git/widget.go b/git/widget.go index 12a82e1d..166b20fc 100644 --- a/git/widget.go +++ b/git/widget.go @@ -34,7 +34,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Git ", "git", true), + TextWidget: wtf.NewTextWidget("Git", "git", true), app: app, Idx: 0, diff --git a/github/display.go b/github/display.go index a63bc66b..afe4409c 100644 --- a/github/display.go +++ b/github/display.go @@ -14,7 +14,7 @@ func (widget *Widget) display() { return } - widget.View.SetTitle(fmt.Sprintf("%s- %s ", widget.Name, widget.title(repo))) + 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" str = str + " [red]Stats[white]\n" diff --git a/github/widget.go b/github/widget.go index c86917cb..cd3e8b14 100644 --- a/github/widget.go +++ b/github/widget.go @@ -30,7 +30,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Github ", "github", true), + TextWidget: wtf.NewTextWidget("Github", "github", true), app: app, Idx: 0, diff --git a/gitlab/widget.go b/gitlab/widget.go index c7c3f96f..2a9324d5 100644 --- a/gitlab/widget.go +++ b/gitlab/widget.go @@ -42,7 +42,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { } widget := Widget{ - TextWidget: wtf.NewTextWidget(" Gitlab ", "gitlab", true), + TextWidget: wtf.NewTextWidget("Gitlab", "gitlab", true), app: app, pages: pages, diff --git a/gspreadsheets/widget.go b/gspreadsheets/widget.go index ddd246d9..ce71fde6 100644 --- a/gspreadsheets/widget.go +++ b/gspreadsheets/widget.go @@ -13,7 +13,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Google Spreadsheets ", "gspreadsheets", false), + TextWidget: wtf.NewTextWidget("Google Spreadsheets", "gspreadsheets", false), } return &widget diff --git a/ipaddresses/ipapi/widget.go b/ipaddresses/ipapi/widget.go index 42730662..f62bcf57 100644 --- a/ipaddresses/ipapi/widget.go +++ b/ipaddresses/ipapi/widget.go @@ -39,7 +39,7 @@ type ipinfo struct { // NewWidget constructor func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" IPInfo ", "ipapi", false), + TextWidget: wtf.NewTextWidget("IPInfo", "ipapi", false), } widget.View.SetWrap(false) diff --git a/ipaddresses/ipinfo/widget.go b/ipaddresses/ipinfo/widget.go index 031dc032..170983b7 100644 --- a/ipaddresses/ipinfo/widget.go +++ b/ipaddresses/ipinfo/widget.go @@ -32,7 +32,7 @@ type ipinfo struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" IPInfo ", "ipinfo", false), + TextWidget: wtf.NewTextWidget("IPInfo", "ipinfo", false), } widget.View.SetWrap(false) diff --git a/jira/widget.go b/jira/widget.go index 4bfe47fa..9627c075 100644 --- a/jira/widget.go +++ b/jira/widget.go @@ -16,7 +16,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Jira ", "jira", true), + TextWidget: wtf.NewTextWidget("Jira", "jira", true), } widget.unselect() @@ -54,13 +54,10 @@ func (widget *Widget) display() { return } widget.View.SetWrap(false) - widget.View.SetTitle( - fmt.Sprintf( - "%s- [green]%s[white] ", - widget.Name, - wtf.Config.UString("wtf.mods.jira.project"), - ), - ) + + str := fmt.Sprintf("%s- [green]%s[white]", widget.Name, wtf.Config.UString("wtf.mods.jira.project")) + + widget.View.SetTitle(widget.ContextualTitle(str)) widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result))) } diff --git a/main.go b/main.go index 526df1f4..1614ec19 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,8 @@ func initializeFocusTracker(app *tview.Application) { Idx: -1, Widgets: widgets, } + + focusTracker.AssignHotKeys() } func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { @@ -86,10 +88,12 @@ func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { focusTracker.Prev() case tcell.KeyEsc: focusTracker.None() - default: - return event + //default: + //return event } + focusTracker.FocusOn(string(event.Rune())) + return event } diff --git a/newrelic/widget.go b/newrelic/widget.go index 2ab2928a..8c4fd8b7 100644 --- a/newrelic/widget.go +++ b/newrelic/widget.go @@ -13,7 +13,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" New Relic ", "newrelic", false), + TextWidget: wtf.NewTextWidget("New Relic", "newrelic", false), } return &widget diff --git a/opsgenie/widget.go b/opsgenie/widget.go index 7ca23621..c95b7dcd 100644 --- a/opsgenie/widget.go +++ b/opsgenie/widget.go @@ -13,7 +13,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" OpsGenie ", "opsgenie", false), + TextWidget: wtf.NewTextWidget("OpsGenie", "opsgenie", false), } return &widget diff --git a/power/widget.go b/power/widget.go index 47e7d73c..823ea928 100644 --- a/power/widget.go +++ b/power/widget.go @@ -14,7 +14,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Power ", "power", false), + TextWidget: wtf.NewTextWidget("Power", "power", false), Battery: NewBattery(), } diff --git a/security/widget.go b/security/widget.go index b95e8354..e98645e0 100644 --- a/security/widget.go +++ b/security/widget.go @@ -15,7 +15,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Security ", "security", false), + TextWidget: wtf.NewTextWidget("Security", "security", false), } return &widget diff --git a/security/widget_windows.go b/security/widget_windows.go index c46dc6f7..dc73c194 100644 --- a/security/widget_windows.go +++ b/security/widget_windows.go @@ -15,7 +15,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Security ", "security", false), + TextWidget: wtf.NewTextWidget("Security", "security", false), } return &widget diff --git a/status/widget.go b/status/widget.go index 9fb1191b..43a4c440 100644 --- a/status/widget.go +++ b/status/widget.go @@ -12,7 +12,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Status ", "status", false), + TextWidget: wtf.NewTextWidget("Status", "status", false), CurrentIcon: 0, } diff --git a/system/widget.go b/system/widget.go index 39d1853a..67d69cbd 100644 --- a/system/widget.go +++ b/system/widget.go @@ -17,7 +17,7 @@ type Widget struct { func NewWidget(date, version string) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" System ", "system", false), + TextWidget: wtf.NewTextWidget("System", "system", false), Date: date, Version: version, diff --git a/textfile/widget.go b/textfile/widget.go index e929700e..d65b6192 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -31,7 +31,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Text File ", "textfile", true), + TextWidget: wtf.NewTextWidget("TextFile", "textfile", true), app: app, filePath: wtf.Config.UString("wtf.mods.textfile.filePath"), @@ -50,7 +50,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() - widget.View.SetTitle(fmt.Sprintf(" %s ", widget.fileName())) + widget.View.SetTitle(widget.ContextualTitle(widget.fileName())) filePath, _ := wtf.ExpandHomeDir(widget.filePath) diff --git a/todo/widget.go b/todo/widget.go index 4851a9f9..ffb8c415 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -46,7 +46,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Todo ", "todo", true), + TextWidget: wtf.NewTextWidget("Todo", "todo", true), app: app, filePath: wtf.Config.UString("wtf.mods.todo.filename"), @@ -68,6 +68,8 @@ func (widget *Widget) Refresh() { widget.UpdateRefreshedAt() widget.load() widget.display() + + widget.View.SetTitle(widget.ContextualTitle(widget.Name)) } func (widget *Widget) SetList(newList checklist.Checklist) { diff --git a/todoist/display.go b/todoist/display.go index 4584300d..a1412e69 100644 --- a/todoist/display.go +++ b/todoist/display.go @@ -16,7 +16,10 @@ func (widget *Widget) display() { return } - widget.View.SetTitle(fmt.Sprintf(" [green]%s[white] ", proj.Project.Name)) + //widget.View.SetTitle(fmt.Sprintf(" [green]%s[white] ", proj.Project.Name)) + + widget.View.SetTitle(widget.ContextualTitle(proj.Project.Name)) + str := wtf.SigilStr(len(widget.projects), widget.idx, widget.View) + "\n" maxLen := proj.LongestLine() diff --git a/todoist/widget.go b/todoist/widget.go index 8737d839..6ee4f202 100644 --- a/todoist/widget.go +++ b/todoist/widget.go @@ -38,7 +38,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Todoist ", "todoist", true), + TextWidget: wtf.NewTextWidget("Todoist", "todoist", true), app: app, pages: pages, diff --git a/travisci/widget.go b/travisci/widget.go index d4d01b5d..a22bdf3c 100644 --- a/travisci/widget.go +++ b/travisci/widget.go @@ -11,7 +11,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Travis CI", "travisci", false), + TextWidget: wtf.NewTextWidget("TravisCI", "travisci", false), } return &widget diff --git a/trello/widget.go b/trello/widget.go index 068e7377..2c2459a4 100644 --- a/trello/widget.go +++ b/trello/widget.go @@ -14,7 +14,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Trello ", "trello", false), + TextWidget: wtf.NewTextWidget("Trello", "trello", false), } return &widget diff --git a/weatherservices/prettyweather/widget.go b/weatherservices/prettyweather/widget.go index 9ea54b30..855ed368 100644 --- a/weatherservices/prettyweather/widget.go +++ b/weatherservices/prettyweather/widget.go @@ -19,7 +19,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Pretty Weather ", "prettyweather", false), + TextWidget: wtf.NewTextWidget("Pretty Weather", "prettyweather", false), } return &widget diff --git a/weatherservices/weather/display.go b/weatherservices/weather/display.go index 0648b45c..10ddd973 100644 --- a/weatherservices/weather/display.go +++ b/weatherservices/weather/display.go @@ -72,5 +72,6 @@ func (widget *Widget) temperatures(cityData *owm.CurrentWeatherData) string { } func (widget *Widget) title(cityData *owm.CurrentWeatherData) string { - return fmt.Sprintf(" %s %s ", widget.emojiFor(cityData), cityData.Name) + str := fmt.Sprintf("%s %s", widget.emojiFor(cityData), cityData.Name) + return widget.ContextualTitle(str) } diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index f58d7bed..48062285 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -38,7 +38,7 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { configKey := "weather" widget := Widget{ - TextWidget: wtf.NewTextWidget(" Weather ", configKey, true), + TextWidget: wtf.NewTextWidget("Weather", configKey, true), app: app, pages: pages, diff --git a/wtf/bargraph.go b/wtf/bargraph.go index 71af1f98..dcdf8537 100644 --- a/wtf/bargraph.go +++ b/wtf/bargraph.go @@ -72,10 +72,18 @@ func (widget *BarGraph) Focusable() bool { return widget.enabled && widget.focusable } +func (widget *BarGraph) FocusChar() string { + return "" +} + func (widget *BarGraph) RefreshInterval() int { return widget.RefreshInt } +func (widget *BarGraph) SetFocusChar(char string) { + return +} + func (widget *BarGraph) TextView() *tview.TextView { return widget.View } diff --git a/wtf/focus_tracker.go b/wtf/focus_tracker.go index 87f6c5a0..44703b18 100644 --- a/wtf/focus_tracker.go +++ b/wtf/focus_tracker.go @@ -22,6 +22,28 @@ type FocusTracker struct { /* -------------------- Exported Functions -------------------- */ +// AssignHotKeys assigns an alphabetic keyboard character to each focusable +// widget so that the widget can be brought into focus by pressing that keyboard key +func (tracker *FocusTracker) AssignHotKeys() { + i := 0 + + for _, focusable := range tracker.focusables() { + focusable.SetFocusChar(string('a' + i)) + i++ + } +} + +func (tracker *FocusTracker) FocusOn(char string) { + for idx, focusable := range tracker.focusables() { + if focusable.FocusChar() == char { + tracker.blur(tracker.Idx) + tracker.Idx = idx + tracker.focus(tracker.Idx) + break + } + } +} + // Next sets the focus on the next widget in the widget list. If the current widget is // the last widget, sets focus on the first widget. func (tracker *FocusTracker) Next() { diff --git a/wtf/text_widget.go b/wtf/text_widget.go index ea0b5ac9..b2944f10 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -13,6 +13,7 @@ var Config *config.Config type TextWidget struct { enabled bool focusable bool + focusChar string Name string RefreshedAt time.Time @@ -53,6 +54,14 @@ func (widget *TextWidget) BorderColor() string { return Config.UString("wtf.colors.border.normal", "gray") } +func (widget *TextWidget) ContextualTitle(defaultStr string) string { + if widget.FocusChar() == "" { + return fmt.Sprintf(" %s ", defaultStr) + } else { + return fmt.Sprintf(" %s [darkgray](%s)[white] ", defaultStr, widget.FocusChar()) + } +} + func (widget *TextWidget) Disable() { widget.enabled = false } @@ -69,10 +78,18 @@ func (widget *TextWidget) Focusable() bool { return widget.enabled && widget.focusable } +func (widget *TextWidget) FocusChar() string { + return widget.focusChar +} + func (widget *TextWidget) RefreshInterval() int { return widget.RefreshInt } +func (widget *TextWidget) SetFocusChar(char string) { + widget.focusChar = char +} + func (widget *TextWidget) TextView() *tview.TextView { return widget.View } @@ -86,7 +103,7 @@ func (widget *TextWidget) addView() { view.SetBorder(true) view.SetBorderColor(colorFor(widget.BorderColor())) view.SetDynamicColors(true) - view.SetTitle(widget.Name) + view.SetTitle(widget.ContextualTitle(widget.Name)) view.SetWrap(false) widget.View = view diff --git a/wtf/wtfable.go b/wtf/wtfable.go index 128582dd..973db6c6 100644 --- a/wtf/wtfable.go +++ b/wtf/wtfable.go @@ -10,6 +10,8 @@ type Wtfable interface { BorderColor() string Focusable() bool + FocusChar() string + SetFocusChar(string) TextView() *tview.TextView Top() int diff --git a/zendesk/widget.go b/zendesk/widget.go index c6ccd7bb..c2b57ab6 100644 --- a/zendesk/widget.go +++ b/zendesk/widget.go @@ -18,7 +18,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" Zendesk ", "zendesk", true), + TextWidget: wtf.NewTextWidget("Zendesk", "zendesk", true), } widget.View.SetInputCapture(widget.keyboardIntercept)