-
-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ad0d34
commit e288eef
Showing
9 changed files
with
359 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
title: "Todoist" | ||
date: 2018-07-05T22:55:55-03:00 | ||
draft: false | ||
--- | ||
|
||
Displays all itens on specified project. | ||
|
||
<img src="/imgs/modules/todoist.png" alt="todoist screenshot" /> | ||
|
||
## Source Code | ||
|
||
```bash | ||
wtf/todoist/ | ||
``` | ||
|
||
## Required ENV Variables | ||
|
||
<span class="caption">Key:</span> `WTF_TODOIST_TOKEN` <br /> | ||
<span class="caption">Value:</span> Your Todoist API Token. <br /> | ||
|
||
_You can get your API Token at: todoist.com/prefs/integrations._ | ||
|
||
## Keyboard Commands | ||
|
||
<span class="caption">Key:</span> `h` <br /> | ||
<span class="caption">Action:</span> Show the previous project. | ||
|
||
<span class="caption">Key:</span> `←` <br /> | ||
<span class="caption">Action:</span←> Show the previous project. | ||
|
||
<span class="caption">Key:</span> `l` <br /> | ||
<span class="caption">Action:</span←> Show the next project. | ||
|
||
<span class="caption">Key:</span> `→` <br /> | ||
<span class="caption">Action:</span> Show the next project. | ||
|
||
<span class="caption">Key:</span> `j` <br /> | ||
<span class="caption">Action:</span> Select the next item in the list. | ||
|
||
<span class="caption">Key:</span> `↓` <br /> | ||
<span class="caption">Action:</span> Select the next item in the list. | ||
|
||
<span class="caption">Key:</span> `k` <br /> | ||
<span class="caption">Action:</span> Select the previous item in the list. | ||
|
||
<span class="caption">Key:</span> `↑` <br /> | ||
<span class="caption">Action:</span> Select the previous item in the list. | ||
|
||
<span class="caption">Key:</span> `c` <br /> | ||
<span class="caption">Action:</span> Close current item. | ||
|
||
<span class="caption">Key:</span> `d` <br /> | ||
<span class="caption">Action:</span> Delete current item. | ||
|
||
<span class="caption">Key:</span> `r` <br /> | ||
<span class="caption">Action:</span> Reload all projects. | ||
|
||
## Configuration | ||
|
||
```yaml | ||
todoist: | ||
projects: | ||
- project_id | ||
enabled: true | ||
position: | ||
height: 1 | ||
left: 2 | ||
top: 0 | ||
width: 1 | ||
refreshInterval: 3600 | ||
``` | ||
### Attributes | ||
`enabled` <br /> | ||
Determines whether or not this module is executed and if its data displayed onscreen. <br /> | ||
Values: `true`, `false`. | ||
|
||
`projects` <br /> | ||
The todoist projects to fetch items from. <br /> | ||
|
||
`refreshInterval` <br /> | ||
How often, in seconds, this module will update its data. <br /> | ||
Values: A positive integer, `0..n`. | ||
|
||
`position` <br /> | ||
Where in the grid this module's widget will be displayed. <br /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package todoist | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gdamore/tcell" | ||
"github.com/rivo/tview" | ||
"github.com/senorprogrammer/wtf/wtf" | ||
) | ||
|
||
func (w *Widget) display() { | ||
if len(w.list) == 0 { | ||
return | ||
} | ||
list := w.list[w.idx] | ||
|
||
w.View.SetTitle(fmt.Sprintf("%s- [green]%s[white] ", w.Name, list.Project.Name)) | ||
str := wtf.SigilStr(len(w.list), w.idx, w.View) + "\n" | ||
|
||
for index, item := range list.items { | ||
if index == list.index { | ||
str = str + fmt.Sprintf("[%s]", wtf.Config.UString("wtf.colors.border.focused", "grey")) | ||
} | ||
str = str + fmt.Sprintf("| | %s[white]\n", tview.Escape(item.Content)) | ||
} | ||
|
||
w.View.Clear() | ||
w.View.SetText(str) | ||
} | ||
|
||
func (w *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { | ||
if len(w.list) == 0 { | ||
return event | ||
} | ||
|
||
switch string(event.Rune()) { | ||
case "r": | ||
w.Refresh() | ||
return nil | ||
case "d": | ||
w.Delete() | ||
return nil | ||
case "c": | ||
w.Close() | ||
return nil | ||
} | ||
|
||
switch fromVim(event) { | ||
case tcell.KeyLeft: | ||
w.Prev() | ||
return nil | ||
case tcell.KeyRight: | ||
w.Next() | ||
return nil | ||
case tcell.KeyUp: | ||
w.UP() | ||
return nil | ||
case tcell.KeyDown: | ||
w.Down() | ||
return nil | ||
} | ||
|
||
return event | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package todoist | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/darkSasori/todoist" | ||
) | ||
|
||
type List struct { | ||
todoist.Project | ||
items []todoist.Task | ||
index int | ||
} | ||
|
||
func NewList(id int) *List { | ||
project, err := todoist.GetProject(id) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
list := &List{ | ||
Project: project, | ||
index: -1, | ||
} | ||
list.loadItems() | ||
return list | ||
} | ||
|
||
func (l List) isFirst() bool { | ||
return l.index == 0 | ||
} | ||
|
||
func (l List) isLast() bool { | ||
return l.index >= len(l.items)-1 | ||
} | ||
|
||
func (l *List) up() { | ||
l.index = l.index - 1 | ||
if l.index < 0 { | ||
l.index = len(l.items) - 1 | ||
} | ||
} | ||
|
||
func (l *List) down() { | ||
if l.index == -1 { | ||
l.index = 0 | ||
return | ||
} | ||
|
||
l.index = l.index + 1 | ||
if l.index >= len(l.items) { | ||
l.index = 0 | ||
} | ||
} | ||
|
||
func (l *List) loadItems() { | ||
tasks, err := todoist.ListTask(todoist.QueryParam{"project_id": fmt.Sprintf("%d", l.ID)}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
l.items = tasks | ||
} | ||
|
||
func (l *List) close() { | ||
if err := l.items[l.index].Close(); err != nil { | ||
panic(err) | ||
} | ||
|
||
l.loadItems() | ||
} | ||
|
||
func (l *List) delete() { | ||
if err := l.items[l.index].Delete(); err != nil { | ||
panic(err) | ||
} | ||
|
||
l.loadItems() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package todoist | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/darkSasori/todoist" | ||
"github.com/gdamore/tcell" | ||
"github.com/rivo/tview" | ||
"github.com/senorprogrammer/wtf/wtf" | ||
) | ||
|
||
type Widget struct { | ||
wtf.TextWidget | ||
|
||
app *tview.Application | ||
pages *tview.Pages | ||
list []*List | ||
idx int | ||
} | ||
|
||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { | ||
widget := Widget{ | ||
TextWidget: wtf.NewTextWidget(" Todoist ", "todoist", true), | ||
|
||
app: app, | ||
pages: pages, | ||
} | ||
|
||
todoist.Token = os.Getenv("WTF_TODOIST_TOKEN") | ||
widget.list = loadProjects() | ||
widget.View.SetInputCapture(widget.keyboardIntercept) | ||
|
||
return &widget | ||
} | ||
|
||
func (w *Widget) Refresh() { | ||
if w.Disabled() || len(w.list) == 0 { | ||
return | ||
} | ||
|
||
w.UpdateRefreshedAt() | ||
w.display() | ||
} | ||
|
||
func (w *Widget) Next() { | ||
w.idx = w.idx + 1 | ||
if w.idx == len(w.list) { | ||
w.idx = 0 | ||
} | ||
|
||
w.display() | ||
} | ||
|
||
func (w *Widget) Prev() { | ||
w.idx = w.idx - 1 | ||
if w.idx < 0 { | ||
w.idx = len(w.list) - 1 | ||
} | ||
|
||
w.display() | ||
} | ||
|
||
func (w *Widget) Down() { | ||
w.list[w.idx].down() | ||
w.display() | ||
} | ||
|
||
func (w *Widget) UP() { | ||
w.list[w.idx].up() | ||
w.display() | ||
} | ||
|
||
func (w *Widget) Close() { | ||
w.list[w.idx].close() | ||
if w.list[w.idx].isLast() { | ||
w.UP() | ||
return | ||
} | ||
w.Down() | ||
} | ||
|
||
func (w *Widget) Delete() { | ||
w.list[w.idx].close() | ||
if w.list[w.idx].isLast() { | ||
w.UP() | ||
return | ||
} | ||
w.Down() | ||
} | ||
|
||
func loadProjects() []*List { | ||
lists := []*List{} | ||
for _, id := range wtf.Config.UList("wtf.mods.todoist.projects") { | ||
list := NewList(id.(int)) | ||
lists = append(lists, list) | ||
} | ||
|
||
return lists | ||
} | ||
|
||
func fromVim(event *tcell.EventKey) tcell.Key { | ||
switch string(event.Rune()) { | ||
case "h": | ||
return tcell.KeyLeft | ||
case "l": | ||
return tcell.KeyRight | ||
case "k": | ||
return tcell.KeyUp | ||
case "j": | ||
return tcell.KeyDown | ||
} | ||
return event.Key() | ||
} |
Oops, something went wrong.