mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Closes #37. Help into Git and Github modules
This commit is contained in:
parent
c7ff101e08
commit
5353d6ddf7
@ -47,8 +47,9 @@ func Fetch() (*calendar.Events, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := fromMidnight().Format(time.RFC3339)
|
||||
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(t).MaxResults(int64(Config.UInt("wtf.mods.gcal.eventCount", 10))).OrderBy("startTime").Do()
|
||||
startTime := fromMidnight().Format(time.RFC3339)
|
||||
eventLimit := int64(Config.UInt("wtf.mods.gcal.eventCount", 10))
|
||||
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(startTime).MaxResults(eventLimit).OrderBy("startTime").Do()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -79,10 +79,11 @@ func (widget *Widget) contentFrom(events *calendar.Events) string {
|
||||
conflict := widget.conflicts(event, events)
|
||||
|
||||
str = str + fmt.Sprintf(
|
||||
"%s [%s]%s[white]\n [%s]%s %s[white]\n\n",
|
||||
"%s [%s]%s[white]\n %s[%s]%s %s[white]\n\n",
|
||||
widget.dayDivider(event, prevEvent),
|
||||
widget.titleColor(event),
|
||||
widget.eventSummary(event, conflict),
|
||||
widget.location(event),
|
||||
widget.descriptionColor(event),
|
||||
widget.eventTimestamp(event),
|
||||
widget.until(event),
|
||||
@ -176,6 +177,22 @@ func (widget *Widget) titleColor(event *calendar.Event) string {
|
||||
return color
|
||||
}
|
||||
|
||||
func (widget *Widget) location(event *calendar.Event) string {
|
||||
if Config.UBool("wtf.mods.gcal.withLocation", true) == false {
|
||||
return ""
|
||||
}
|
||||
|
||||
if event.Location == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"[%s]%s\n ",
|
||||
widget.descriptionColor(event),
|
||||
event.Location,
|
||||
)
|
||||
}
|
||||
|
||||
// until returns the number of hours or days until the event
|
||||
// If the event is in the past, returns nil
|
||||
func (widget *Widget) until(event *calendar.Event) string {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
@ -15,8 +16,8 @@ const helpText = `
|
||||
Keyboard commands for Git:
|
||||
|
||||
/: Show/hide this help window
|
||||
h: Previous git repository
|
||||
l: Next git repository
|
||||
h: Previous git repository
|
||||
l: Next git repository
|
||||
|
||||
arrow left: Previous git repository
|
||||
arrow right: Next git repository
|
||||
@ -25,14 +26,19 @@ const helpText = `
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
Data []*GitRepo
|
||||
Idx int
|
||||
app *tview.Application
|
||||
Data []*GitRepo
|
||||
Idx int
|
||||
pages *tview.Pages
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(" Git ", "git", true),
|
||||
|
||||
app: app,
|
||||
Idx: 0,
|
||||
pages: pages,
|
||||
}
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
@ -99,6 +105,9 @@ func (widget *Widget) gitRepos(repoPaths []string) []*GitRepo {
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.showHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
@ -118,3 +127,15 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) showHelp() {
|
||||
closeFunc := func() {
|
||||
widget.pages.RemovePage("help")
|
||||
widget.app.SetFocus(widget.View)
|
||||
}
|
||||
|
||||
modal := wtf.NewBillboardModal(helpText, closeFunc)
|
||||
|
||||
widget.pages.AddPage("help", modal, false, true)
|
||||
widget.app.SetFocus(modal)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/olebedev/config"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
@ -12,12 +13,12 @@ import (
|
||||
var Config *config.Config
|
||||
|
||||
const helpText = `
|
||||
Keyboard commands for Git:
|
||||
Keyboard commands for Github:
|
||||
|
||||
/: Show/hide this help window
|
||||
h: Previous git repository
|
||||
l: Next git repository
|
||||
r: Refresh the data
|
||||
h: Previous git repository
|
||||
l: Next git repository
|
||||
r: Refresh the data
|
||||
|
||||
arrow left: Previous git repository
|
||||
arrow right: Next git repository
|
||||
@ -26,14 +27,19 @@ const helpText = `
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
Data []*GithubRepo
|
||||
Idx int
|
||||
app *tview.Application
|
||||
Data []*GithubRepo
|
||||
Idx int
|
||||
pages *tview.Pages
|
||||
}
|
||||
|
||||
func NewWidget() *Widget {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(" Github ", "github", true),
|
||||
Idx: 0,
|
||||
|
||||
app: app,
|
||||
Idx: 0,
|
||||
pages: pages,
|
||||
}
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
@ -99,6 +105,9 @@ func (widget *Widget) currentData() *GithubRepo {
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.showHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
@ -121,3 +130,15 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) showHelp() {
|
||||
closeFunc := func() {
|
||||
widget.pages.RemovePage("help")
|
||||
widget.app.SetFocus(widget.View)
|
||||
}
|
||||
|
||||
modal := wtf.NewBillboardModal(helpText, closeFunc)
|
||||
|
||||
widget.pages.AddPage("help", modal, false, true)
|
||||
widget.app.SetFocus(modal)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user