summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--widgets/directories.go20
-rw-r--r--widgets/spinner.go80
-rw-r--r--worker/messages.go91
3 files changed, 190 insertions, 1 deletions
diff --git a/widgets/directories.go b/widgets/directories.go
index 13018bb..11fe2d6 100644
--- a/widgets/directories.go
+++ b/widgets/directories.go
@@ -17,13 +17,24 @@ type DirectoryList struct {
 	logger       *log.Logger
 	onInvalidate func(d ui.Drawable)
 	selected     string
+	spinner      *Spinner
 	worker       *types.Worker
 }
 
 func NewDirectoryList(conf *config.AccountConfig,
 	logger *log.Logger, worker *types.Worker) *DirectoryList {
 
-	return &DirectoryList{conf: conf, logger: logger, worker: worker}
+	dirlist := &DirectoryList{
+		conf:    conf,
+		logger:  logger,
+		spinner: NewSpinner(),
+		worker:  worker,
+	}
+	dirlist.spinner.OnInvalidate(func(_ ui.Drawable) {
+		dirlist.Invalidate()
+	})
+	dirlist.spinner.Start()
+	return dirlist
 }
 
 func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
@@ -37,6 +48,7 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
 			case *types.Done:
 				sort.Strings(dirs)
 				dirlist.dirs = dirs
+				dirlist.spinner.Stop()
 				dirlist.Invalidate()
 				if done != nil {
 					done(dirs)
@@ -63,6 +75,12 @@ func (dirlist *DirectoryList) Invalidate() {
 
 func (dirlist *DirectoryList) Draw(ctx *ui.Context) {
 	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+
+	if dirlist.spinner.IsRunning() {
+		dirlist.spinner.Draw(ctx)
+		return
+	}
+
 	row := 0
 	for _, name := range dirlist.dirs {
 		if row >= ctx.Height() {
diff --git a/widgets/spinner.go b/widgets/spinner.go
new file mode 100644
index 0000000..2e7e367
--- /dev/null
+++ b/widgets/spinner.go
@@ -0,0 +1,80 @@
+package widgets
+
+import (
+	"time"
+
+	"github.com/gdamore/tcell"
+
+	"git.sr.ht/~sircmpwn/aerc2/lib/ui"
+)
+
+var (
+	frames = []string{
+		"[..]    ",
+		" [..]   ",
+		"  [..]  ",
+		"   [..] ",
+		"    [..]",
+		"   [..] ",
+		"  [..]  ",
+		" [..]   ",
+	}
+)
+
+type Spinner struct {
+	frame        int
+	onInvalidate func(d ui.Drawable)
+	stop         chan interface{}
+}
+
+func NewSpinner() *Spinner {
+	spinner := Spinner{
+		stop:  make(chan interface{}),
+		frame: -1,
+	}
+	return &spinner
+}
+
+func (s *Spinner) Start() {
+	s.frame = 0
+	go func() {
+		for {
+			select {
+			case <-s.stop:
+				return
+			case <-time.After(200 * time.Millisecond):
+				s.frame++
+				if s.frame >= len(frames) {
+					s.frame = 0
+				}
+				s.Invalidate()
+			}
+		}
+	}()
+}
+
+func (s *Spinner) Stop() {
+	s.stop <- nil
+	s.frame = -1
+	s.Invalidate()
+}
+
+func (s *Spinner) IsRunning() bool {
+	return s.frame != -1
+}
+
+func (s *Spinner) Draw(ctx *ui.Context) {
+	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
+	col := ctx.Width()/2 - len(frames[0])/2 + 1
+	ctx.Printf(col, 0, tcell.StyleDefault, "%s", frames[s.frame])
+}
+
+func (s *Spinner) OnInvalidate(onInvalidate func(d ui.Drawable)) {
+	s.onInvalidate = onInvalidate
+}
+
+func (s *Spinner) Invalidate() {
+	if s.onInvalidate != nil {
+		s.onInvalidate(s)
+	}
+}
diff --git a/worker/messages.go b/worker/messages.go
new file mode 100644
index 0000000..90fcfa0
--- /dev/null
+++ b/worker/messages.go
@@ -0,0 +1,91 @@
+package worker
+
+import (
+	"crypto/x509"
+
+	"git.sr.ht/~sircmpwn/aerc2/config"
+)
+
+type WorkerMessage interface {
+	InResponseTo() WorkerMessage
+}
+
+type Message struct {
+	inResponseTo WorkerMessage
+}
+
+func RespondTo(msg WorkerMessage) Message {
+	return Message{
+		inResponseTo: msg,
+	}
+}
+
+func (m Message) InResponseTo() WorkerMessage {
+	return m.inResponseTo
+}
+
+// Meta-messages
+
+type Done struct {
+	Message
+}
+
+type Error struct {
+	Message
+	Error error
+}
+
+type Unsupported struct {
+	Message
+}
+
+// Actions
+
+type ApproveCertificate struct {
+	Message
+	Approved bool
+}
+
+type Configure struct {
+	Message
+	Config *config.AccountConfig
+}
+
+type Connect struct {
+	Message
+}
+
+type Disconnect struct {
+	Message
+}
+
+type ListDirectories struct {
+	Message
+}
+
+type OpenDirectory struct {
+	Message
+	Directory string
+}
+
+// Messages
+
+type CertificateApprovalRequest struct {
+	Message
+	CertPool *x509.CertPool
+}
+
+type Directory struct {
+	Message
+	Attributes []string
+	Name       string
+}
+
+type DirectoryInfo struct {
+	Message
+	Flags    []string
+	Name     string
+	ReadOnly bool
+
+	Exists, Recent, Unseen int
+}
13:51:00 +0200 Rename mucconf wins into conf wins' href='/danisanti/profani-tty/commit/themes/bios?id=a952776b899dd29056ad6779b14dab75a4125924'>a952776b ^
adb470c4 ^
503e0ae3 ^
adb470c4 ^










































d3cc5bd7 ^



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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137