-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzzz_notification.go
282 lines (224 loc) · 7.56 KB
/
zzz_notification.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// Code generated by generate/main.go. DO NOT EDIT.
// source: api/api.proto
package iterm2
import (
"fmt"
"github.com/tjamet/goterm2/api"
)
type (
KeystrokeNotifier func(*api.KeystrokeNotification) error
ScreenUpdateNotifier func(*api.ScreenUpdateNotification) error
PromptNotifier func(*api.PromptNotification) error
LocationChangeNotifier func(*api.LocationChangeNotification) error
CustomEscapeSequenceNotifier func(*api.CustomEscapeSequenceNotification) error
NewSessionNotifier func(*api.NewSessionNotification) error
TerminateSessionNotifier func(*api.TerminateSessionNotification) error
LayoutChangedNotifier func(*api.LayoutChangedNotification) error
FocusChangedNotifier func(*api.FocusChangedNotification) error
ServerOriginatedRPCNotifier func(*api.ServerOriginatedRPCNotification) error
BroadcastDomainsChangedNotifier func(*api.BroadcastDomainsChangedNotification) error
VariableChangedNotifier func(*api.VariableChangedNotification) error
ProfileChangedNotifier func(*api.ProfileChangedNotification) error
)
type Notifier struct {
Keystroke []KeystrokeNotifier
ScreenUpdate []ScreenUpdateNotifier
Prompt []PromptNotifier
LocationChange []LocationChangeNotifier
CustomEscapeSequence []CustomEscapeSequenceNotifier
NewSession []NewSessionNotifier
TerminateSession []TerminateSessionNotifier
LayoutChanged []LayoutChangedNotifier
FocusChanged []FocusChangedNotifier
ServerOriginatedRPC []ServerOriginatedRPCNotifier
BroadcastDomainsChanged []BroadcastDomainsChangedNotifier
VariableChanged []VariableChangedNotifier
ProfileChanged []ProfileChangedNotifier
}
func (I *ITerm2) RegisterNotifier(notifier interface{}) error {
if n, ok := notifier.(KeystrokeNotifier); ok {
I.notifier.Keystroke = append(I.notifier.Keystroke, n)
return nil
}
if n, ok := notifier.(ScreenUpdateNotifier); ok {
I.notifier.ScreenUpdate = append(I.notifier.ScreenUpdate, n)
return nil
}
if n, ok := notifier.(PromptNotifier); ok {
I.notifier.Prompt = append(I.notifier.Prompt, n)
return nil
}
if n, ok := notifier.(LocationChangeNotifier); ok {
I.notifier.LocationChange = append(I.notifier.LocationChange, n)
return nil
}
if n, ok := notifier.(CustomEscapeSequenceNotifier); ok {
I.notifier.CustomEscapeSequence = append(I.notifier.CustomEscapeSequence, n)
return nil
}
if n, ok := notifier.(NewSessionNotifier); ok {
I.notifier.NewSession = append(I.notifier.NewSession, n)
return nil
}
if n, ok := notifier.(TerminateSessionNotifier); ok {
I.notifier.TerminateSession = append(I.notifier.TerminateSession, n)
return nil
}
if n, ok := notifier.(LayoutChangedNotifier); ok {
I.notifier.LayoutChanged = append(I.notifier.LayoutChanged, n)
return nil
}
if n, ok := notifier.(FocusChangedNotifier); ok {
I.notifier.FocusChanged = append(I.notifier.FocusChanged, n)
return nil
}
if n, ok := notifier.(ServerOriginatedRPCNotifier); ok {
I.notifier.ServerOriginatedRPC = append(I.notifier.ServerOriginatedRPC, n)
return nil
}
if n, ok := notifier.(BroadcastDomainsChangedNotifier); ok {
I.notifier.BroadcastDomainsChanged = append(I.notifier.BroadcastDomainsChanged, n)
return nil
}
if n, ok := notifier.(VariableChangedNotifier); ok {
I.notifier.VariableChanged = append(I.notifier.VariableChanged, n)
return nil
}
if n, ok := notifier.(ProfileChangedNotifier); ok {
I.notifier.ProfileChanged = append(I.notifier.ProfileChanged, n)
return nil
}
return fmt.Errorf("notifier does not match any existing notifier")
}
func (I *ITerm2) dispatchNotification(n *api.Notification) {
if n.GetKeystrokeNotification() != nil {
for _, f := range I.notifier.Keystroke {
go func(f KeystrokeNotifier, n *api.Notification) {
err := f(n.GetKeystrokeNotification())
if err != nil {
I.logger.Errorf("Failed to notify about Keystroke: %s", err)
}
}(f, n)
}
}
if n.GetScreenUpdateNotification() != nil {
for _, f := range I.notifier.ScreenUpdate {
go func(f ScreenUpdateNotifier, n *api.Notification) {
err := f(n.GetScreenUpdateNotification())
if err != nil {
I.logger.Errorf("Failed to notify about ScreenUpdate: %s", err)
}
}(f, n)
}
}
if n.GetPromptNotification() != nil {
for _, f := range I.notifier.Prompt {
go func(f PromptNotifier, n *api.Notification) {
err := f(n.GetPromptNotification())
if err != nil {
I.logger.Errorf("Failed to notify about Prompt: %s", err)
}
}(f, n)
}
}
if n.GetLocationChangeNotification() != nil {
for _, f := range I.notifier.LocationChange {
go func(f LocationChangeNotifier, n *api.Notification) {
err := f(n.GetLocationChangeNotification())
if err != nil {
I.logger.Errorf("Failed to notify about LocationChange: %s", err)
}
}(f, n)
}
}
if n.GetCustomEscapeSequenceNotification() != nil {
for _, f := range I.notifier.CustomEscapeSequence {
go func(f CustomEscapeSequenceNotifier, n *api.Notification) {
err := f(n.GetCustomEscapeSequenceNotification())
if err != nil {
I.logger.Errorf("Failed to notify about CustomEscapeSequence: %s", err)
}
}(f, n)
}
}
if n.GetNewSessionNotification() != nil {
for _, f := range I.notifier.NewSession {
go func(f NewSessionNotifier, n *api.Notification) {
err := f(n.GetNewSessionNotification())
if err != nil {
I.logger.Errorf("Failed to notify about NewSession: %s", err)
}
}(f, n)
}
}
if n.GetTerminateSessionNotification() != nil {
for _, f := range I.notifier.TerminateSession {
go func(f TerminateSessionNotifier, n *api.Notification) {
err := f(n.GetTerminateSessionNotification())
if err != nil {
I.logger.Errorf("Failed to notify about TerminateSession: %s", err)
}
}(f, n)
}
}
if n.GetLayoutChangedNotification() != nil {
for _, f := range I.notifier.LayoutChanged {
go func(f LayoutChangedNotifier, n *api.Notification) {
err := f(n.GetLayoutChangedNotification())
if err != nil {
I.logger.Errorf("Failed to notify about LayoutChanged: %s", err)
}
}(f, n)
}
}
if n.GetFocusChangedNotification() != nil {
for _, f := range I.notifier.FocusChanged {
go func(f FocusChangedNotifier, n *api.Notification) {
err := f(n.GetFocusChangedNotification())
if err != nil {
I.logger.Errorf("Failed to notify about FocusChanged: %s", err)
}
}(f, n)
}
}
if n.GetServerOriginatedRpcNotification() != nil {
for _, f := range I.notifier.ServerOriginatedRPC {
go func(f ServerOriginatedRPCNotifier, n *api.Notification) {
err := f(n.GetServerOriginatedRpcNotification())
if err != nil {
I.logger.Errorf("Failed to notify about ServerOriginatedRPC: %s", err)
}
}(f, n)
}
}
if n.GetBroadcastDomainsChanged() != nil {
for _, f := range I.notifier.BroadcastDomainsChanged {
go func(f BroadcastDomainsChangedNotifier, n *api.Notification) {
err := f(n.GetBroadcastDomainsChanged())
if err != nil {
I.logger.Errorf("Failed to notify about BroadcastDomainsChanged: %s", err)
}
}(f, n)
}
}
if n.GetVariableChangedNotification() != nil {
for _, f := range I.notifier.VariableChanged {
go func(f VariableChangedNotifier, n *api.Notification) {
err := f(n.GetVariableChangedNotification())
if err != nil {
I.logger.Errorf("Failed to notify about VariableChanged: %s", err)
}
}(f, n)
}
}
if n.GetProfileChangedNotification() != nil {
for _, f := range I.notifier.ProfileChanged {
go func(f ProfileChangedNotifier, n *api.Notification) {
err := f(n.GetProfileChangedNotification())
if err != nil {
I.logger.Errorf("Failed to notify about ProfileChanged: %s", err)
}
}(f, n)
}
}
}