forked from skanehira/docui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.go
121 lines (97 loc) · 2.14 KB
/
tasks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package gui
import (
"context"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
)
var (
success = "Success"
executing = "Executing"
cancel = "canceled"
)
type task struct {
Name string
Status string
Created string
Func func(ctx context.Context) error
Ctx context.Context
Cancel context.CancelFunc
}
type tasks struct {
*tview.Table
tasks chan *task
}
func newTasks(g *Gui) *tasks {
tasks := &tasks{
Table: tview.NewTable().SetSelectable(true, false).Select(0, 0).SetFixed(1, 1),
tasks: make(chan *task),
}
tasks.SetTitle("tasks").SetTitleAlign(tview.AlignLeft)
tasks.SetBorder(true)
tasks.setEntries(g)
tasks.setKeybinding(g)
return tasks
}
func (t *tasks) name() string {
return "tasks"
}
func (t *tasks) setKeybinding(g *Gui) {
t.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
g.setGlobalKeybinding(event)
// TODO cancel task
switch event.Key() {
}
switch event.Rune() {
}
return event
})
}
func (t *tasks) entries(g *Gui) {
// do nothing
}
func (t *tasks) setEntries(g *Gui) {
t.entries(g)
table := t.Clear()
headers := []string{
"Name",
"Status",
"Created",
}
for i, header := range headers {
table.SetCell(0, i, &tview.TableCell{
Text: header,
NotSelectable: true,
Align: tview.AlignLeft,
Color: tcell.ColorWhite,
BackgroundColor: tcell.ColorDefault,
Attributes: tcell.AttrBold,
})
}
for i, task := range g.state.resources.tasks {
table.SetCell(i+1, 0, tview.NewTableCell(task.Name).
SetTextColor(tcell.ColorLightGreen).
SetMaxWidth(1).
SetExpansion(1))
table.SetCell(i+1, 1, tview.NewTableCell(task.Status).
SetTextColor(tcell.ColorLightGreen).
SetMaxWidth(1).
SetExpansion(1))
table.SetCell(i+1, 2, tview.NewTableCell(task.Created).
SetTextColor(tcell.ColorLightGreen).
SetMaxWidth(1).
SetExpansion(1))
}
}
func (t *tasks) focus(g *Gui) {
t.SetSelectable(true, false)
g.app.SetFocus(t)
}
func (t *tasks) unfocus() {
t.SetSelectable(false, false)
}
func (t *tasks) setFilterWord(word string) {
// do nothings
}
func (t *tasks) updateEntries(g *Gui) {
// do nothings
}