-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobserver.aro
More file actions
executable file
·377 lines (316 loc) · 19.2 KB
/
observer.aro
File metadata and controls
executable file
·377 lines (316 loc) · 19.2 KB
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
(* ============================================================
observer.aro – Render terminal UI on every UIState change.
Fan-out pattern:
ui-state-repository Observer → computes style, emits Render event with mode + style
Render Handler where <event: mode> == "setup" – first-run token entry
Render Handler where <event: mode> == "compose" – new post dialog
Render Handler where <event: mode> == "timeline" – scrollable post list
Variable naming constraints:
- No <is-*> (is = keyword)
- No <*-at> (at = preposition)
============================================================ *)
(* ---- Dispatch: compute style once, emit Render event with mode + style ---- *)
(Dispatch UI Render: ui-state-repository Observer) {
Extract the <state: UIState> from the <event: newValue>.
Extract the <mode> from the <state: mode>.
Compute the <sep-width> from (<terminal: columns>).
Compute the <separator> from "─" * <sep-width>.
Compute the <input-width> from (<terminal: columns>) - 4.
Create the <style: TerminalStyles> with {
separatorLine: <separator>,
inputWidth: <input-width>,
reset: "\u{001B}[0m",
muted: "\u{001B}[2m",
heading: "\u{001B}[1m\u{001B}[97m",
prompt: "\u{001B}[36m",
cursor: "\u{001B}[32m",
counter: "\u{001B}[33m",
authorName: "\u{001B}[1m",
username: "\u{001B}[36m",
cursorIndicator: "\u{001B}[32m"
}.
Emit a <Render: event> with { mode: <mode>, style: <style> }.
Return an <OK: status> for the <dispatch>.
}
(* ── Setup screen ── *)
(Render Setup: Render Handler) where <event: mode> == "setup" {
Retrieve the <state: UIState> from the <ui-state-repository> where <key> is "main".
Extract the <style: TerminalStyles> from the <event: style>.
Extract the <compose-text> from the <state: composeText>.
Compute the <step-requests-instance> from (<state: setupStep>) == "instance".
match <step-requests-instance> {
case true { Create the <setup-prompt> with "Enter your Mastodon instance URL (e.g. https://mastodon.social):". }
case false { Create the <setup-prompt> with "Enter your access token:". }
}
Transform the <display> from the <template: setup.screen>.
Render the <display> to the <console>.
Return an <OK: status> for the <render>.
}
(* ── Compose screen ── *)
(Render Compose: Render Handler) where <event: mode> == "compose" {
Retrieve the <state: UIState> from the <ui-state-repository> where <key> is "main".
Extract the <style: TerminalStyles> from the <event: style>.
Extract the <compose-text> from the <state: composeText>.
Compute the <character-count: length> from <compose-text>.
Compute the <chars-remaining> from 500 - <character-count>.
Transform the <display> from the <template: compose.screen>.
Render the <display> to the <console>.
Return an <OK: status> for the <render>.
}
(* ── Reply screen ── *)
(Render Reply: Render Handler) where <event: mode> == "reply" {
Retrieve the <state: UIState> from the <ui-state-repository> where <key> is "main".
Extract the <style: TerminalStyles> from the <event: style>.
(* Reduce visible slots by 5 rows to fit inline reply box *)
Compute the <panel-height> from (<terminal: rows>) - 8.
Compute the <visible-count> from <panel-height> / 3.
Compute the <account-column-width> from (<terminal: columns>) - 42.
Compute the <content-column-width> from (<terminal: columns>) - 4.
Compute the <post-separator-width> from (<terminal: columns>) - 2.
Compute the <post-separator> from "─" * <post-separator-width>.
Delete the <previous-slots> from the <visible-slot-repository>.
Delete the <previous-wrap-states> from the <wrap-state-repository>.
for <slot-index> from 0 to <visible-count> {
Compute the <post-index> from <slot-index> + (<state: selection>).
Retrieve the <post> from the <post-repository>
where <key> = <post-index>
default { key: -1, acct: "", displayName: "", content: "", createdAt: "", boosterAcct: "", boosted: "", favourited: "" }.
Extract the <post-account> from the <post: acct>.
Extract the <post-display-name> from the <post: displayName>.
Extract the <post-content> from the <post: content>.
Extract the <post-date> from the <post: createdAt>.
Extract the <post-booster> from the <post: boosterAcct>.
Compute the <this-slot-selected> from <slot-index> == (<state: cursor>).
match <this-slot-selected> {
case true { Create the <cursor-marker> with "▶". }
case false { Create the <cursor-marker> with " ". }
}
Compute the <account-text: clip> from <post-account> with <account-column-width>.
Compute the <author-display-text: clip> from <post-display-name> with 18.
Compute the <date-display-text: clip> from <post-date> with 16.
Split the <content-words> from <post-content> by /\s/.
Create the <initial-wrap-state> with { key: <slot-index>, curLine: "", result: "" }.
Store the <initial-wrap-state> into the <wrap-state-repository>.
for each <word> in <content-words> {
Compute the <word-character-count: length> from <word>.
Compute the <word-has-no-text> from <word-character-count> == 0.
match <word-has-no-text> {
case true { }
case false {
Retrieve the <wrap-state> from the <wrap-state-repository> where <key> = <slot-index>.
Extract the <current-line> from the <wrap-state: curLine>.
Extract the <completed-lines> from the <wrap-state: result>.
Compute the <current-line-length: length> from <current-line>.
Compute the <current-line-has-no-words> from <current-line-length> == 0.
match <current-line-has-no-words> {
case true { Create the <projected-length> with <word-character-count>. }
case false { Compute the <projected-length> from <current-line-length> + <word-character-count> + 1. }
}
Compute the <word-fits-current-line> from <projected-length> <= <content-column-width>.
match <word-fits-current-line> {
case true {
match <current-line-has-no-words> {
case true { Create the <line-extended> with <word>. }
case false { Compute the <line-extended> from <current-line> ++ " " ++ <word>. }
}
Update the <wrap-state: curLine> with <line-extended>.
Store the <wrap-state> into the <wrap-state-repository>.
}
case false {
Compute the <no-completed-lines-yet> from <completed-lines> == "".
match <no-completed-lines-yet> {
case true { Create the <completed-lines-extended> with <current-line>. }
case false { Compute the <completed-lines-extended> from <completed-lines> ++ "\u{000A} " ++ <current-line>. }
}
Update the <wrap-state: result> with <completed-lines-extended>.
Update the <wrap-state: curLine> with <word>.
Store the <wrap-state> into the <wrap-state-repository>.
}
}
}
}
}
Retrieve the <final-wrap-state> from the <wrap-state-repository> where <key> = <slot-index>.
Extract the <last-partial-line> from the <final-wrap-state: curLine>.
Extract the <all-completed-lines> from the <final-wrap-state: result>.
Compute the <content-fits-one-line> from <all-completed-lines> == "".
match <content-fits-one-line> {
case true { Create the <wrapped-content> with <last-partial-line>. }
case false { Compute the <wrapped-content> from <all-completed-lines> ++ "\u{000A} " ++ <last-partial-line>. }
}
Compute the <booster-len: length> from <post-booster>.
Compute the <has-booster> from <booster-len> > 0.
match <has-booster> {
case true { Compute the <booster-label> from "\u{001B}[2m ↻ \u{001B}[0m\u{001B}[36m@" ++ <post-booster> ++ "\u{001B}[0m". }
case false { Create the <booster-label> with "". }
}
Extract the <post-boosted> from the <post: boosted>.
Compute the <was-boosted> from <post-boosted> == "true".
match <was-boosted> {
case true { Create the <boost-marker> with " 🚀". }
case false { Create the <boost-marker> with "". }
}
Extract the <post-favourited> from the <post: favourited>.
Compute the <was-favourited> from <post-favourited> == "true".
match <was-favourited> {
case true { Create the <fav-marker> with " ❤️". }
case false { Create the <fav-marker> with "". }
}
Create the <slot: Slot> with { key: <slot-index>, marker: <cursor-marker>, acct: <account-text>, name: <author-display-text>, content: <wrapped-content>, date: <date-display-text>, booster: <booster-label>, boostMarker: <boost-marker>, favMarker: <fav-marker>, sep: <post-separator> }.
Store the <slot> into the <visible-slot-repository>.
}
(* ── Split slots into pre-cursor and post-cursor for inline reply prompt ── *)
Extract the <cursor-pos> from the <state: cursor>.
Compute the <post-start> from <cursor-pos> + 1.
Delete the <prev-pre-slots> from the <pre-slot-repository>.
Delete the <prev-post-slots> from the <post-slot-repository>.
for <pre-idx> from 0 to <post-start> {
Retrieve the <pre-slot> from the <visible-slot-repository> where <key> = <pre-idx>.
Store the <pre-slot> into the <pre-slot-repository>.
}
Compute the <post-slots-exist> from <post-start> <= <visible-count>.
match <post-slots-exist> {
case true {
for <post-idx> from <post-start> to <visible-count> {
Retrieve the <post-slot> from the <visible-slot-repository> where <key> = <post-idx>.
Store the <post-slot> into the <post-slot-repository>.
}
}
case false { }
}
Retrieve the <pre-display-slots> from the <pre-slot-repository>.
Retrieve the <post-display-slots> from the <post-slot-repository>.
Extract the <selection> from the <state: selection>.
Extract the <total-posts> from the <state: totalPosts>.
Compute the <scroll-position-zero> from <selection> == 0.
Compute the <cursor-position-zero> from (<state: cursor>) == 0.
Compute the <viewing-post-top> from <scroll-position-zero> AND <cursor-position-zero>.
match <viewing-post-top> {
case true { Create the <auto-label> with "\u{001B}[34m (autoupdate)\u{001B}[0m". }
case false { Create the <auto-label> with "". }
}
Extract the <compose-text> from the <state: composeText>.
Extract the <reply-acct> from the <state: replyToAcct>.
Compute the <character-count: length> from <compose-text>.
Transform the <display> from the <template: reply.screen>.
Render the <display> to the <console>.
Return an <OK: status> for the <render>.
}
(* ── Timeline screen ── *)
(Render Timeline: Render Handler) where <event: mode> == "timeline" {
Retrieve the <state: UIState> from the <ui-state-repository> where <key> is "main".
Extract the <style: TerminalStyles> from the <event: style>.
Compute the <panel-height> from (<terminal: rows>) - 3.
Compute the <visible-count> from <panel-height> / 3.
Compute the <account-column-width> from (<terminal: columns>) - 42.
Compute the <content-column-width> from (<terminal: columns>) - 4.
Compute the <post-separator-width> from (<terminal: columns>) - 2.
Compute the <post-separator> from "─" * <post-separator-width>.
Delete the <previous-slots> from the <visible-slot-repository>.
Delete the <previous-wrap-states> from the <wrap-state-repository>.
for <slot-index> from 0 to <visible-count> {
Compute the <post-index> from <slot-index> + (<state: selection>).
Retrieve the <post> from the <post-repository>
where <key> = <post-index>
default { key: -1, acct: "", displayName: "", content: "", createdAt: "", boosterAcct: "", boosted: "", favourited: "" }.
Extract the <post-account> from the <post: acct>.
Extract the <post-display-name> from the <post: displayName>.
Extract the <post-content> from the <post: content>.
Extract the <post-date> from the <post: createdAt>.
Extract the <post-booster> from the <post: boosterAcct>.
Compute the <this-slot-selected> from <slot-index> == (<state: cursor>).
match <this-slot-selected> {
case true { Create the <cursor-marker> with "▶". }
case false { Create the <cursor-marker> with " ". }
}
Compute the <account-text: clip> from <post-account> with <account-column-width>.
Compute the <author-display-text: clip> from <post-display-name> with 18.
Compute the <date-display-text: clip> from <post-date> with 16.
(* ── Word-wrap post content into lines of content-column-width ── *)
Split the <content-words> from <post-content> by /\s/.
Create the <initial-wrap-state> with { key: <slot-index>, curLine: "", result: "" }.
Store the <initial-wrap-state> into the <wrap-state-repository>.
for each <word> in <content-words> {
Compute the <word-character-count: length> from <word>.
Compute the <word-has-no-text> from <word-character-count> == 0.
match <word-has-no-text> {
case true { }
case false {
Retrieve the <wrap-state> from the <wrap-state-repository> where <key> = <slot-index>.
Extract the <current-line> from the <wrap-state: curLine>.
Extract the <completed-lines> from the <wrap-state: result>.
Compute the <current-line-length: length> from <current-line>.
Compute the <current-line-has-no-words> from <current-line-length> == 0.
match <current-line-has-no-words> {
case true { Create the <projected-length> with <word-character-count>. }
case false { Compute the <projected-length> from <current-line-length> + <word-character-count> + 1. }
}
Compute the <word-fits-current-line> from <projected-length> <= <content-column-width>.
match <word-fits-current-line> {
case true {
match <current-line-has-no-words> {
case true { Create the <line-extended> with <word>. }
case false { Compute the <line-extended> from <current-line> ++ " " ++ <word>. }
}
Update the <wrap-state: curLine> with <line-extended>.
Store the <wrap-state> into the <wrap-state-repository>.
}
case false {
Compute the <no-completed-lines-yet> from <completed-lines> == "".
match <no-completed-lines-yet> {
case true { Create the <completed-lines-extended> with <current-line>. }
case false { Compute the <completed-lines-extended> from <completed-lines> ++ "\u{000A} " ++ <current-line>. }
}
Update the <wrap-state: result> with <completed-lines-extended>.
Update the <wrap-state: curLine> with <word>.
Store the <wrap-state> into the <wrap-state-repository>.
}
}
}
}
}
Retrieve the <final-wrap-state> from the <wrap-state-repository> where <key> = <slot-index>.
Extract the <last-partial-line> from the <final-wrap-state: curLine>.
Extract the <all-completed-lines> from the <final-wrap-state: result>.
Compute the <content-fits-one-line> from <all-completed-lines> == "".
match <content-fits-one-line> {
case true { Create the <wrapped-content> with <last-partial-line>. }
case false { Compute the <wrapped-content> from <all-completed-lines> ++ "\u{000A} " ++ <last-partial-line>. }
}
(* ── End word-wrap ── *)
(* ── Repost indicator ── *)
Compute the <booster-len: length> from <post-booster>.
Compute the <has-booster> from <booster-len> > 0.
match <has-booster> {
case true { Compute the <booster-label> from "\u{001B}[2m ↻ \u{001B}[0m\u{001B}[36m@" ++ <post-booster> ++ "\u{001B}[0m". }
case false { Create the <booster-label> with "". }
}
Extract the <post-boosted> from the <post: boosted>.
Compute the <was-boosted> from <post-boosted> == "true".
match <was-boosted> {
case true { Create the <boost-marker> with " 🚀". }
case false { Create the <boost-marker> with "". }
}
Extract the <post-favourited> from the <post: favourited>.
Compute the <was-favourited> from <post-favourited> == "true".
match <was-favourited> {
case true { Create the <fav-marker> with " ❤️". }
case false { Create the <fav-marker> with "". }
}
Create the <slot: Slot> with { key: <slot-index>, marker: <cursor-marker>, acct: <account-text>, name: <author-display-text>, content: <wrapped-content>, date: <date-display-text>, booster: <booster-label>, boostMarker: <boost-marker>, favMarker: <fav-marker>, sep: <post-separator> }.
Store the <slot> into the <visible-slot-repository>.
}
Retrieve the <display-slots> from the <visible-slot-repository>.
Extract the <selection> from the <state: selection>.
Extract the <total-posts> from the <state: totalPosts>.
Compute the <scroll-position-zero> from <selection> == 0.
Compute the <cursor-position-zero> from (<state: cursor>) == 0.
Compute the <viewing-post-top> from <scroll-position-zero> AND <cursor-position-zero>.
match <viewing-post-top> {
case true { Create the <auto-label> with "\u{001B}[34m (autoupdate)\u{001B}[0m". }
case false { Create the <auto-label> with "". }
}
Transform the <display> from the <template: timeline.screen>.
Render the <display> to the <console>.
Return an <OK: status> for the <render>.
}