forked from marcusolsson/tui-go
/
main.go
89 lines (72 loc) · 1.63 KB
/
main.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
package main
import (
"github.com/marcusolsson/tui-go"
)
type mail struct {
from string
subject string
date string
body string
}
var mails = []mail{
{
from: "John Doe <john@doe.com>",
subject: "Vacation pictures",
date: "Yesterday",
body: `
Hey,
Where can I find the pictures from the diving trip?
Cheers,
John`,
},
{
from: "Jane Doe <jane@doe.com>",
subject: "Meeting notes",
date: "Yesterday",
body: `
Here are the notes from today's meeting.
/Jane`,
},
}
func main() {
inbox := tui.NewTable(0, 0)
inbox.SetColumnStretch(0, 3)
inbox.SetColumnStretch(1, 2)
inbox.SetColumnStretch(2, 1)
for _, m := range mails {
inbox.AppendRow(
tui.NewLabel(m.subject),
tui.NewLabel(m.from),
tui.NewLabel(m.date),
)
}
var (
from = tui.NewLabel("")
subject = tui.NewLabel("")
date = tui.NewLabel("")
)
info := tui.NewGrid(0, 0)
info.AppendRow(tui.NewLabel("From:"), from)
info.AppendRow(tui.NewLabel("Subject:"), subject)
info.AppendRow(tui.NewLabel("Date:"), date)
body := tui.NewLabel("")
body.SetSizePolicy(tui.Preferred, tui.Expanding)
mail := tui.NewVBox(info, body)
mail.SetSizePolicy(tui.Preferred, tui.Expanding)
inbox.OnSelectionChanged(func(t *tui.Table) {
m := mails[t.Selected()]
from.SetText(m.from)
subject.SetText(m.subject)
date.SetText(m.date)
body.SetText(m.body)
})
// Select first mail on startup.
inbox.Select(0)
root := tui.NewVBox(inbox, tui.NewLabel(""), mail)
ui := tui.New(root)
ui.SetKeybinding("Esc", func() { ui.Quit() })
ui.SetKeybinding("Shift+Alt+Up", func() { ui.Quit() })
if err := ui.Run(); err != nil {
panic(err)
}
}