mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add character identifiers to focusable widgets
When no widget has focus, press the letter key to focus on the widget assigned to that letter. Example: GitHub (d) Press "d" to focus on the GitHub widget.
This commit is contained in:
parent
749318ead6
commit
beb0c43b07
@ -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))
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
|
@ -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{}),
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)))
|
||||
}
|
||||
|
||||
|
8
main.go
8
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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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(),
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,8 @@ type Wtfable interface {
|
||||
|
||||
BorderColor() string
|
||||
Focusable() bool
|
||||
FocusChar() string
|
||||
SetFocusChar(string)
|
||||
TextView() *tview.TextView
|
||||
|
||||
Top() int
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user