2 search-terms: (handle gap-buffer)
3 tabs: (handle array tab)
4 current-tab-index: int # index into tabs
7 cursor-in-search?: boolean
9 cursor-in-channels?: boolean
10 channel-cursor-index: int
16 # type 1: items in a channel
17 # type 2: search for a term
18 # type 3: comments in a single thread
19 item-index: int # what item in the corresponding list we start rendering
22 hidden-items: (handle stream int)
26 search-terms: (handle gap-buffer)
27 search-items: (handle array int)
28 search-items-first-free: int
33 # static buffer sizes in this file:
34 # main-panel-hor # in characters
35 # item-padding-hor # in pixels
36 # item-padding-ver # in characters
37 # avatar-side # in pixels
38 # avatar-space-hor # in characters
39 # avatar-space-ver # in characters
40 # search-position-x # in characters
41 # search-space-ver # in characters
42 # author-name-padding-ver # in characters
43 # post-right-coord # in characters
44 # channel-offset-x # in characters
45 # menu-space-ver # in characters
48 fn initialize-environment _self: (addr environment), _items: (addr item-list) {
49 var self/esi: (addr environment) <- copy _self
50 var search-terms-ah/eax: (addr handle gap-buffer) <- get self, search-terms
51 allocate search-terms-ah
52 var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
53 initialize-gap-buffer search-terms, 0x30/search-capacity
54 var items/eax: (addr item-list) <- copy _items
55 var items-data-first-free-a/eax: (addr int) <- get items, data-first-free
56 var final-item/edx: int <- copy *items-data-first-free-a
57 final-item <- decrement
58 var tabs-ah/ecx: (addr handle array tab) <- get self, tabs
59 populate tabs-ah, 0x10/max-history
60 # current-tab-index implicitly set to 0
61 var tabs/eax: (addr array tab) <- lookup *tabs-ah
62 var first-tab/eax: (addr tab) <- index tabs, 0/current-tab-index
63 var dest/edi: (addr int) <- get first-tab, item-index
64 copy-to *dest, final-item
69 fn render-environment screen: (addr screen), _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
70 var env/esi: (addr environment) <- copy _env
72 var dirty?/eax: (addr boolean) <- get env, dirty?
73 compare *dirty?, 0/false
75 # minimize repaints when typing into the search bar
77 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
78 compare *cursor-in-search?, 0/false
80 render-search-input screen, env
81 clear-rect screen, 0/x 0x2f/y, 0x80/x 0x30/y, 0/bg
82 render-search-menu screen, env
85 # minimize repaints when focus in channel nav
87 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
88 compare *cursor-in-channels?, 0/false
90 render-channels screen, env, channels
91 clear-rect screen, 0/x 0x2f/y, 0x80/x 0x30/y, 0/bg
92 render-channels-menu screen, env
98 render-search-input screen, env
99 render-channels screen, env, channels
100 render-item-list screen, env, users, channels, items
101 render-menu screen, env
102 var dirty?/eax: (addr boolean) <- get env, dirty?
103 copy-to *dirty?, 0/false
106 fn render-channels screen: (addr screen), _env: (addr environment), _channels: (addr array channel) {
107 var env/esi: (addr environment) <- copy _env
108 var cursor-index/edi: int <- copy -1
110 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
111 compare *cursor-in-search?, 0/false
113 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
114 compare *cursor-in-channels?, 0/false
116 var cursor-index-addr/eax: (addr int) <- get env, channel-cursor-index
117 cursor-index <- copy *cursor-index-addr
119 var channels/esi: (addr array channel) <- copy _channels
120 var y/ebx: int <- copy 2/search-space-ver
121 y <- add 1/item-padding-ver
122 var i/ecx: int <- copy 0
123 var max/edx: int <- length channels
127 var offset/eax: (offset channel) <- compute-offset channels, i
128 var curr/eax: (addr channel) <- index channels, offset
129 var name-ah/eax: (addr handle array byte) <- get curr, name
130 var name/eax: (addr array byte) <- lookup *name-ah
133 set-cursor-position screen, 2/x y
135 compare cursor-index, i
137 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 7/grey 0/black
138 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, name, 7/grey 0/black
141 compare cursor-index, i
143 # cursor; reverse video
144 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 0/black 0xf/white
145 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, name, 0/black 0xf/white
147 y <- add 2/channel-padding
153 fn render-item-list screen: (addr screen), _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
154 var env/esi: (addr environment) <- copy _env
155 var tmp-width/eax: int <- copy 0
156 var tmp-height/ecx: int <- copy 0
157 tmp-width, tmp-height <- screen-size screen
158 var screen-width: int
159 copy-to screen-width, tmp-width
160 var screen-height: int
161 copy-to screen-height, tmp-height
163 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
164 var _tabs/eax: (addr array tab) <- lookup *tabs-ah
165 var tabs/edx: (addr array tab) <- copy _tabs
166 var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
167 var current-tab-index/eax: int <- copy *current-tab-index-a
168 var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
169 var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
170 var show-cursor?: boolean
172 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
173 compare *cursor-in-search?, 0/false
175 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
176 compare *cursor-in-channels?, 0/false
178 copy-to show-cursor?, 1/true
180 render-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
181 var top/eax: int <- copy screen-height
182 top <- subtract 2/menu-space-ver
183 clear-rect screen, 0 top, screen-width screen-height, 0/bg
186 fn render-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), items: (addr item-list), screen-height: int {
187 var current-tab/esi: (addr tab) <- copy _current-tab
188 var current-tab-type/eax: (addr int) <- get current-tab, type
189 compare *current-tab-type, 0/all-items
192 render-all-items screen, current-tab, show-cursor?, items, users, screen-height
195 compare *current-tab-type, 1/channel
198 render-channel-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
201 compare *current-tab-type, 2/search
204 render-search-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
207 compare *current-tab-type, 3/thread
210 render-thread-tab screen, current-tab, show-cursor?, users, channels, items, screen-height
215 fn render-all-items screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, _items: (addr item-list), users: (addr array user), screen-height: int {
216 var current-tab/esi: (addr tab) <- copy _current-tab
217 var items/edi: (addr item-list) <- copy _items
218 var newest-item/eax: (addr int) <- get current-tab, item-index
219 var i/ebx: int <- copy *newest-item
220 var items-data-first-free-addr/eax: (addr int) <- get items, data-first-free
221 render-progress screen, i, *items-data-first-free-addr
222 var items-data-ah/eax: (addr handle array item) <- get items, data
223 var _items-data/eax: (addr array item) <- lookup *items-data-ah
224 var items-data/edi: (addr array item) <- copy _items-data
225 var y/ecx: int <- copy 2/search-space-ver
226 y <- add 1/item-padding-ver
227 $render-all-items:loop: {
231 var hide?/eax: boolean <- should-hide? current-tab, i, _items
232 compare hide?, 0/false
235 loop $render-all-items:loop
237 compare y, screen-height
239 var offset/eax: (offset item) <- compute-offset items-data, i
240 var curr-item/eax: (addr item) <- index items-data, offset
241 y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
242 # cursor always at top item
243 copy-to show-cursor?, 0/false
249 fn render-channel-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), _channels: (addr array channel), _items: (addr item-list), screen-height: int {
250 var current-tab/esi: (addr tab) <- copy _current-tab
251 var items/edi: (addr item-list) <- copy _items
252 var channels/ebx: (addr array channel) <- copy _channels
253 var channel-index-addr/eax: (addr int) <- get current-tab, channel-index
254 var channel-index/eax: int <- copy *channel-index-addr
255 var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
256 var current-channel/ecx: (addr channel) <- index channels, channel-offset
257 var current-channel-posts-ah/eax: (addr handle array int) <- get current-channel, posts
258 var _current-channel-posts/eax: (addr array int) <- lookup *current-channel-posts-ah
259 var current-channel-posts/edx: (addr array int) <- copy _current-channel-posts
260 var current-channel-first-channel-item-addr/eax: (addr int) <- get current-tab, item-index
261 var i/ebx: int <- copy *current-channel-first-channel-item-addr
262 var current-channel-posts-first-free-addr/eax: (addr int) <- get current-channel, posts-first-free
263 set-cursor-position 0/screen, 0x68/x 0/y
264 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "channel", 7/fg 0/bg
265 render-progress screen, i, *current-channel-posts-first-free-addr
266 var items-data-ah/eax: (addr handle array item) <- get items, data
267 var _items-data/eax: (addr array item) <- lookup *items-data-ah
268 var items-data/edi: (addr array item) <- copy _items-data
269 var y/ecx: int <- copy 2/search-space-ver
270 y <- add 1/item-padding-ver
274 compare y, screen-height
276 var item-index-addr/eax: (addr int) <- index current-channel-posts, i
277 var item-index/eax: int <- copy *item-index-addr
278 var item-offset/eax: (offset item) <- compute-offset items-data, item-index
279 var curr-item/eax: (addr item) <- index items-data, item-offset
280 y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
281 # cursor always at top item
282 copy-to show-cursor?, 0/false
288 fn render-search-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), _items: (addr item-list), screen-height: int {
289 var current-tab/esi: (addr tab) <- copy _current-tab
290 var items/edi: (addr item-list) <- copy _items
291 var current-tab-search-items-ah/eax: (addr handle array int) <- get current-tab, search-items
292 var _current-tab-search-items/eax: (addr array int) <- lookup *current-tab-search-items-ah
293 var current-tab-search-items/ebx: (addr array int) <- copy _current-tab-search-items
294 var current-tab-top-item-addr/eax: (addr int) <- get current-tab, item-index
295 var i/edx: int <- copy *current-tab-top-item-addr
296 var current-tab-search-items-first-free-addr/eax: (addr int) <- get current-tab, search-items-first-free
297 set-cursor-position 0/screen, 0x68/x 0/y
298 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "search", 7/fg 0/bg
299 render-progress screen, i, *current-tab-search-items-first-free-addr
301 compare *current-tab-search-items-first-free-addr, 0x100/max-search-results
303 set-cursor-position 0/screen, 0x68/x 1/y
304 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "too many results", 4/fg 0/bg
306 var items-data-ah/eax: (addr handle array item) <- get items, data
307 var _items-data/eax: (addr array item) <- lookup *items-data-ah
308 var items-data/edi: (addr array item) <- copy _items-data
309 var y/ecx: int <- copy 2/search-space-ver
310 y <- add 1/item-padding-ver
314 compare y, screen-height
316 var item-index-addr/eax: (addr int) <- index current-tab-search-items, i
317 var item-index/eax: int <- copy *item-index-addr
318 var item-offset/eax: (offset item) <- compute-offset items-data, item-index
319 var curr-item/eax: (addr item) <- index items-data, item-offset
320 y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
321 # cursor always at top item
322 copy-to show-cursor?, 0/false
328 fn render-thread-tab screen: (addr screen), _current-tab: (addr tab), show-cursor?: boolean, users: (addr array user), channels: (addr array channel), _items: (addr item-list), screen-height: int {
329 var current-tab/esi: (addr tab) <- copy _current-tab
330 var items/eax: (addr item-list) <- copy _items
331 var items-data-ah/eax: (addr handle array item) <- get items, data
332 var _items-data/eax: (addr array item) <- lookup *items-data-ah
333 var items-data/edi: (addr array item) <- copy _items-data
334 var post-index-addr/eax: (addr int) <- get current-tab, root-index
335 var post-index/eax: int <- copy *post-index-addr
336 var post-offset/eax: (offset item) <- compute-offset items-data, post-index
337 var post/ebx: (addr item) <- index items-data, post-offset
338 var current-tab-top-item-addr/eax: (addr int) <- get current-tab, item-index
339 var i/edx: int <- copy *current-tab-top-item-addr
340 var post-comments-first-free-addr/eax: (addr int) <- get post, comments-first-free
341 set-cursor-position 0/screen, 0x68/x 0/y
342 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "thread", 7/fg 0/bg
343 render-progress screen, i, *post-comments-first-free-addr
344 var post-comments-ah/eax: (addr handle array int) <- get post, comments
345 var post-comments/eax: (addr array int) <- lookup *post-comments-ah
346 var y/ecx: int <- copy 2/search-space-ver
347 y <- add 1/item-padding-ver
351 compare y, screen-height
353 var item-index-addr/eax: (addr int) <- index post-comments, i
354 var item-index/eax: int <- copy *item-index-addr
355 var item-offset/eax: (offset item) <- compute-offset items-data, item-index
356 var curr-item/eax: (addr item) <- index items-data, item-offset
357 y <- render-item screen, curr-item, users, show-cursor?, y, screen-height
358 # cursor always at top item
359 copy-to show-cursor?, 0/false
363 # finally render the parent -- though we'll never focus on it
364 y <- render-item screen, post, users, 0/no-cursor, y, screen-height
367 # side-effect: mutates cursor position
368 fn render-progress screen: (addr screen), curr: int, max: int {
369 set-cursor-position 0/screen, 0x70/x 0/y
370 var top-index/eax: int <- copy max
371 top-index <- subtract curr # happy accident: 1-based
372 draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, top-index, 7/fg 0/bg
373 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "/", 7/fg 0/bg
374 draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen screen, max, 7/fg 0/bg
377 fn render-search-input screen: (addr screen), _env: (addr environment) {
378 var env/esi: (addr environment) <- copy _env
379 var cursor-in-search?/ecx: (addr boolean) <- get env, cursor-in-search?
380 set-cursor-position 0/screen, 0x22/x=search-position-x 1/y
381 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "search ", 7/fg 0/bg
382 var search-terms-ah/eax: (addr handle gap-buffer) <- get env, search-terms
383 var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
384 rewind-gap-buffer search-terms
385 var x/eax: int <- render-gap-buffer screen, search-terms, 0x2a/x 1/y, *cursor-in-search?, 0xf/fg 0/bg
387 compare x, 0x4a/end-search
389 var y/ecx: int <- copy 0
390 x, y <- render-code-point screen, 0x5f/underscore, 0/xmin 1/ymin, 0x80/xmax, 1/ymax, x, 1/y, 0xf/fg 0/bg
395 # not used in search mode
396 fn render-menu screen: (addr screen), _env: (addr environment) {
397 var env/edi: (addr environment) <- copy _env
399 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
400 compare *cursor-in-search?, 0/false
402 render-search-menu screen, env
405 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
406 compare *cursor-in-channels?, 0/false
409 render-channels-menu screen, env
412 render-main-menu screen, env
415 fn render-main-menu screen: (addr screen), _env: (addr environment) {
416 var width/eax: int <- copy 0
417 var y/ecx: int <- copy 0
418 width, y <- screen-size screen
420 set-cursor-position screen, 2/x, y
422 var env/edi: (addr environment) <- copy _env
423 var num-tabs/edi: (addr int) <- get env, current-tab-index
426 draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
427 draw-text-rightward-from-cursor screen, " go back ", width, 0xf/fg, 0/bg
429 draw-text-rightward-from-cursor screen, " / ", width, 0/fg 0xf/bg
430 draw-text-rightward-from-cursor screen, " search ", width, 0xf/fg, 0/bg
431 draw-text-rightward-from-cursor screen, " Tab ", width, 0/fg 0xf/bg
432 draw-text-rightward-from-cursor screen, " go to channels ", width, 0xf/fg, 0/bg
433 draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
434 draw-text-rightward-from-cursor screen, " go to thread ", width, 0xf/fg, 0/bg
437 var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? _env
438 compare is-all-items-or-channel?, 0/false
441 draw-text-rightward-from-cursor screen, " ^h ", width, 0/fg 0xf/bg
442 draw-text-rightward-from-cursor screen, " hide thread ", width, 0xf/fg, 0/bg
443 draw-text-rightward-from-cursor screen, " ^u ", width, 0/fg 0xf/bg
444 draw-text-rightward-from-cursor screen, " unhide all ", width, 0xf/fg, 0/bg
446 draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg 0xf/bg
447 draw-text-rightward-from-cursor screen, " << page ", width, 0xf/fg, 0/bg
448 draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg 0xf/bg
449 draw-text-rightward-from-cursor screen, " page >> ", width, 0xf/fg, 0/bg
452 fn render-channels-menu screen: (addr screen), _env: (addr environment) {
453 var width/eax: int <- copy 0
454 var y/ecx: int <- copy 0
455 width, y <- screen-size screen
457 set-cursor-position screen, 2/x, y
459 var env/edi: (addr environment) <- copy _env
460 var num-tabs/edi: (addr int) <- get env, current-tab-index
463 draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
464 draw-text-rightward-from-cursor screen, " go back ", width, 0xf/fg, 0/bg
466 draw-text-rightward-from-cursor screen, " / ", width, 0/fg 0xf/bg
467 draw-text-rightward-from-cursor screen, " search ", width, 0xf/fg, 0/bg
468 draw-text-rightward-from-cursor screen, " Tab ", width, 0/fg 0xf/bg
469 draw-text-rightward-from-cursor screen, " go to items ", width, 0xf/fg, 0/bg
470 draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
471 draw-text-rightward-from-cursor screen, " select ", width, 0xf/fg, 0/bg
474 fn render-search-menu screen: (addr screen), _env: (addr environment) {
475 var width/eax: int <- copy 0
476 var y/ecx: int <- copy 0
477 width, y <- screen-size screen
479 set-cursor-position screen, 2/x, y
480 draw-text-rightward-from-cursor screen, " Esc ", width, 0/fg 0xf/bg
481 draw-text-rightward-from-cursor screen, " cancel ", width, 0xf/fg, 0/bg
482 draw-text-rightward-from-cursor screen, " Enter ", width, 0/fg 0xf/bg
483 draw-text-rightward-from-cursor screen, " select ", width, 0xf/fg, 0/bg
484 draw-text-rightward-from-cursor screen, " ^a ", width, 0/fg, 0xf/bg
485 draw-text-rightward-from-cursor screen, " << ", width, 0xf/fg, 0/bg
486 draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg, 0xf/bg
487 draw-text-rightward-from-cursor screen, " <word ", width, 0xf/fg, 0/bg
488 draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg, 0xf/bg
489 draw-text-rightward-from-cursor screen, " word> ", width, 0xf/fg, 0/bg
490 draw-text-rightward-from-cursor screen, " ^e ", width, 0/fg, 0xf/bg
491 draw-text-rightward-from-cursor screen, " >> ", width, 0xf/fg, 0/bg
492 draw-text-rightward-from-cursor screen, " ^u ", width, 0/fg, 0xf/bg
493 draw-text-rightward-from-cursor screen, " clear ", width, 0xf/fg, 0/bg
496 fn render-item screen: (addr screen), _item: (addr item), _users: (addr array user), show-cursor?: boolean, y: int, screen-height: int -> _/ecx: int {
497 var item/esi: (addr item) <- copy _item
498 var users/edi: (addr array user) <- copy _users
499 var author-index-addr/ecx: (addr int) <- get item, by
500 var author-index/ecx: int <- copy *author-index-addr
501 var author-offset/ecx: (offset user) <- compute-offset users, author-index
502 var author/ecx: (addr user) <- index users, author-offset
504 var author-avatar-ah/eax: (addr handle image) <- get author, avatar
505 var _author-avatar/eax: (addr image) <- lookup *author-avatar-ah
506 var author-avatar/ebx: (addr image) <- copy _author-avatar
508 compare author-avatar, 0
510 var y/edx: int <- copy y
511 y <- shift-left 4/log2font-height
512 var x/eax: int <- copy 0x20/main-panel-hor
513 x <- shift-left 3/log2font-width
514 x <- add 0x18/item-padding-hor
515 render-image screen, author-avatar, x, y, 0x50/avatar-side, 0x50/avatar-side
518 var channel-name-ah/eax: (addr handle array byte) <- get item, channel
519 var channel-name/eax: (addr array byte) <- lookup *channel-name-ah
521 var x/eax: int <- copy 0x20/main-panel-hor
522 x <- add 0x40/channel-offset-x
523 set-cursor-position screen, x y
525 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, "#", 7/grey 0/black
526 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, channel-name, 7/grey 0/black
529 var author-real-name-ah/eax: (addr handle array byte) <- get author, real-name
530 var author-real-name/eax: (addr array byte) <- lookup *author-real-name-ah
531 var x/ecx: int <- copy 0x20/main-panel-hor
532 x <- add 0x10/avatar-space-hor
533 set-cursor-position screen, x y
534 draw-text-wrapping-right-then-down-from-cursor-over-full-screen screen, author-real-name, 0xf/white 0/black
538 var text-ah/eax: (addr handle array byte) <- get item, text
539 var _text/eax: (addr array byte) <- lookup *text-ah
540 var text/edx: (addr array byte) <- copy _text
541 var text-y/eax: int <- render-slack-message screen, text, show-cursor?, y, screen-height
543 add-to y, 6/avatar-space-ver
552 fn render-slack-message screen: (addr screen), text: (addr array byte), highlight?: boolean, ymin: int, ymax: int -> _/eax: int {
553 var x/eax: int <- copy 0x20/main-panel-hor
554 x <- add 0x10/avatar-space-hor
555 var y/ecx: int <- copy ymin
556 y <- add 1/author-name-padding-ver
557 $render-slack-message:draw: {
558 compare highlight?, 0/false
561 x, y <- draw-json-text-wrapping-right-then-down screen, text, x y, 0x70/xmax=post-right-coord ymax, x y, 0/fg 7/bg
562 break $render-slack-message:draw
564 x, y <- draw-json-text-wrapping-right-then-down screen, text, x y, 0x70/xmax=post-right-coord ymax, x y, 7/fg 0/bg
566 y <- add 2/item-padding-ver
570 # draw text in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary
571 # return the next (x, y) coordinate in raster order where drawing stopped
572 # that way the caller can draw more if given the same min and max bounding-box.
573 # if there isn't enough space, truncate
574 fn draw-json-text-wrapping-right-then-down screen: (addr screen), _text: (addr array byte), xmin: int, ymin: int, xmax: int, ymax: int, _x: int, _y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
575 var stream-storage: (stream byte 0x4000/print-buffer-size)
576 var stream/edi: (addr stream byte) <- address stream-storage
577 var text/esi: (addr array byte) <- copy _text
578 var len/eax: int <- length text
579 compare len, 0x4000/print-buffer-size
582 write stream, "ERROR: stream too small in draw-text-wrapping-right-then-down"
584 compare len, 0x4000/print-buffer-size
589 var x/eax: int <- copy _x
590 var y/ecx: int <- copy _y
591 x, y <- draw-json-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
595 # draw a stream in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary
596 # return the next (x, y) coordinate in raster order where drawing stopped
597 # that way the caller can draw more if given the same min and max bounding-box.
598 # if there isn't enough space, truncate
599 fn draw-json-stream-wrapping-right-then-down screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
600 var xcurr/ecx: int <- copy x
601 var ycurr/edx: int <- copy y
602 var c/ebx: code-point <- copy 0
603 var next-c/esi: code-point <- copy 0
605 # read c from either next-c or stream
606 $draw-json-stream-wrapping-right-then-down:read-base: {
612 break $draw-json-stream-wrapping-right-then-down:read-base
614 c <- read-json-code-point stream
616 compare c, 0xffffffff/end-of-file
618 $draw-json-stream-wrapping-right-then-down:render-code-point-utf8: {
619 compare c, 0x5c/backslash
622 xcurr, ycurr <- render-json-escaped-code-point screen, stream, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
623 break $draw-json-stream-wrapping-right-then-down:render-code-point-utf8
625 compare c, 0xa/newline
628 # minimum effort to clear cursor
629 var dummy/eax: int <- draw-code-point screen, 0x20/space, xcurr, ycurr, color, background-color
632 break $draw-json-stream-wrapping-right-then-down:render-code-point-utf8
634 var offset/eax: int <- draw-code-point screen, c, xcurr, ycurr, color, background-color
635 # overlay a combining character if necessary
636 $draw-json-stream-wrapping-right-then-down:read-combiner: {
637 var done?/eax: boolean <- stream-empty? stream
638 compare done?, 0/false
641 # no combining character allowed here
642 var g/eax: code-point-utf8 <- read-code-point-utf8 stream
643 var c/eax: code-point <- to-code-point g
644 # if not a combining character, save for next iteration and loop
646 var combining-code-point?/eax: boolean <- combining-code-point? c
647 compare combining-code-point?, 0/false
652 break $draw-json-stream-wrapping-right-then-down:read-combiner
654 # otherwise overlay it without saving its width
655 # This means strange results if a base and its combiner have different
656 # widths. We'll always follow the base width.
657 var dummy/eax: int <- overlay-code-point screen, c, xcurr, ycurr, color, background-color
669 set-cursor-position screen, xcurr, ycurr
673 # just return a different register
674 fn read-json-code-point stream: (addr stream byte) -> _/ebx: code-point {
675 var g/eax: code-point-utf8 <- read-code-point-utf8 stream
676 var result/eax: code-point <- to-code-point g
681 # https://www.json.org/json-en.html
682 fn render-json-escaped-code-point screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, xcurr: int, ycurr: int, color: int, background-color: int -> _/ecx: int, _/edx: int {
683 var g/ebx: code-point <- read-json-code-point stream
684 compare g, 0xffffffff/end-of-file
691 var x/eax: int <- copy xcurr
718 var y/ecx: int <- copy 0
723 x, y <- render-json-escaped-unicode-code-point screen, stream, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
724 var y/edx: int <- copy y
727 # most characters escape to themselves
728 # combining characters not supported after backslash
729 x, y <- render-code-point screen, g, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
730 var y/edx: int <- copy y
735 fn render-json-escaped-unicode-code-point screen: (addr screen), stream: (addr stream byte), xmin: int, ymin: int, xmax: int, ymax: int, xcurr: int, ycurr: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
736 var hex-digits-storage: (array byte 4)
737 var hex-digits/esi: (addr array byte) <- address hex-digits-storage
738 # slurp 4 bytes exactly
739 var src/eax: byte <- read-byte stream
740 var dest/ecx: (addr byte) <- index hex-digits, 0
741 copy-byte-to *dest, src
742 src <- read-byte stream
743 dest <- index hex-digits, 1
744 copy-byte-to *dest, src
745 src <- read-byte stream
746 dest <- index hex-digits, 2
747 copy-byte-to *dest, src
748 src <- read-byte stream
749 dest <- index hex-digits, 3
750 copy-byte-to *dest, src
753 var endash?/eax: boolean <- string-equal? hex-digits, "2013"
754 compare endash?, 0/false
756 var x/eax: int <- copy 0
757 var y/ecx: int <- copy 0
758 x, y <- render-code-point screen, 0x2d/dash, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
763 var emdash?/eax: boolean <- string-equal? hex-digits, "2014"
764 compare emdash?, 0/false
766 var x/eax: int <- copy 0
767 var y/ecx: int <- copy 0
768 x, y <- render-code-point screen, 0x2d/dash, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
773 var left-quote?/eax: boolean <- string-equal? hex-digits, "2018"
774 compare left-quote?, 0/false
776 var x/eax: int <- copy 0
777 var y/ecx: int <- copy 0
778 x, y <- render-code-point screen, 0x27/quote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
783 var right-quote?/eax: boolean <- string-equal? hex-digits, "2019"
784 compare right-quote?, 0/false
786 var x/eax: int <- copy 0
787 var y/ecx: int <- copy 0
788 x, y <- render-code-point screen, 0x27/quote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
793 var left-dquote?/eax: boolean <- string-equal? hex-digits, "201c"
794 compare left-dquote?, 0/false
796 var x/eax: int <- copy 0
797 var y/ecx: int <- copy 0
798 x, y <- render-code-point screen, 0x22/dquote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
803 var right-dquote?/eax: boolean <- string-equal? hex-digits, "201d"
804 compare right-dquote?, 0/false
806 var x/eax: int <- copy 0
807 var y/ecx: int <- copy 0
808 x, y <- render-code-point screen, 0x22/dquote, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
813 var bullet?/eax: boolean <- string-equal? hex-digits, "2022"
814 compare bullet?, 0/false
816 var x/eax: int <- copy 0
817 var y/ecx: int <- copy 0
818 x, y <- render-code-point screen, 0x2a/asterisk, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
823 var ellipses?/eax: boolean <- string-equal? hex-digits, "2026"
824 compare ellipses?, 0/false
826 var x/eax: int <- copy 0
827 var y/ecx: int <- copy 0
828 x, y <- draw-text-wrapping-right-then-down screen, "...", xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
831 var n/eax: int <- parse-hex-int hex-digits
832 var c/edx: code-point <- copy n
833 var x/eax: int <- copy 0
834 var y/ecx: int <- copy 0
835 x, y <- render-code-point screen, c, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
841 fn update-environment _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
842 var env/edi: (addr environment) <- copy _env
843 # first dispatch to search mode if necessary
845 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
846 compare *cursor-in-search?, 0/false
848 update-search env, key, users, channels, items
852 compare key, 0x2f/slash
855 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
856 copy-to *cursor-in-search?, 1/true
857 # do one more repaint
858 var dirty?/eax: (addr boolean) <- get env, dirty?
859 copy-to *dirty?, 1/true
863 compare key, 0x1b/esc
869 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
873 # toggle cursor between main panel and channels nav
874 not *cursor-in-channels? # bitwise NOT; only works if you never assign 1/true to this variable
875 # do one more repaint
876 var dirty?/eax: (addr boolean) <- get env, dirty?
877 copy-to *dirty?, 1/true
881 compare *cursor-in-channels?, 0/false
883 update-main-panel env, key, users, channels, items
887 compare *cursor-in-channels?, 0/false
889 update-channels-nav env, key, users, channels, items
894 fn update-main-panel env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
896 compare key, 0xa/newline
898 new-thread-tab-from-cursor env, users, channels, items
902 compare key, 8/ctrl-h
904 var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? env
905 compare is-all-items-or-channel?, 0/false
907 hide-thread env, users, channels, items
911 compare key, 0x15/ctrl-u
913 var is-all-items-or-channel?/eax: boolean <- current-tab-is-all-items-or-channel? env
914 compare is-all-items-or-channel?, 0/false
916 new-all-items-tab env, users, channels, items
920 compare key, 0x81/down-arrow
922 next-item env, users, channels, items
926 compare key, 0x82/up-arrow
928 previous-item env, users, channels, items
932 compare key, 6/ctrl-f
934 page-down env, users, channels, items
938 compare key, 2/ctrl-b
940 page-up env, users, channels, items
945 fn current-tab-is-all-items-or-channel? _env: (addr environment) -> _/eax: boolean {
946 var env/esi: (addr environment) <- copy _env
947 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
948 var _tabs/eax: (addr array tab) <- lookup *tabs-ah
949 var tabs/edx: (addr array tab) <- copy _tabs
950 var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
951 var current-tab-index/eax: int <- copy *current-tab-index-a
952 var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
953 var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
954 var current-tab-type/eax: (addr int) <- get current-tab, type
956 compare *current-tab-type, 0/all-items
961 compare *current-tab-type, 1/channel
968 # TODO: clamp cursor within bounds
969 fn update-channels-nav _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
970 var env/edi: (addr environment) <- copy _env
971 var channel-cursor-index/eax: (addr int) <- get env, channel-cursor-index
973 compare key, 0x81/down-arrow
975 increment *channel-cursor-index
979 compare key, 0x82/up-arrow
981 decrement *channel-cursor-index
985 compare key, 0xa/newline
987 new-channel-tab env, *channel-cursor-index, channels
988 var cursor-in-channels?/eax: (addr boolean) <- get env, cursor-in-channels?
989 copy-to *cursor-in-channels?, 0/false
994 fn update-search _env: (addr environment), key: byte, users: (addr array user), channels: (addr array channel), items: (addr item-list) {
995 var env/edi: (addr environment) <- copy _env
996 var cursor-in-search?/eax: (addr boolean) <- get env, cursor-in-search?
1000 # get out of search mode
1001 copy-to *cursor-in-search?, 0/false
1005 compare key, 0xa/newline
1007 # perform a search, then get out of search mode
1008 new-search-tab env, items
1009 copy-to *cursor-in-search?, 0/false
1012 # otherwise delegate
1013 var search-terms-ah/eax: (addr handle gap-buffer) <- get env, search-terms
1014 var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
1015 var g/ecx: code-point-utf8 <- copy key
1016 edit-gap-buffer search-terms, g
1019 fn new-all-items-tab _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
1020 var env/edi: (addr environment) <- copy _env
1021 var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
1022 increment *current-tab-index-addr
1023 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1024 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1025 var max-tabs/ebx: int <- length tabs
1027 compare *current-tab-index-addr, max-tabs
1029 abort "history overflow; grow max-history (we should probably improve this)"
1031 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1032 var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
1033 var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
1034 clear-object current-tab
1035 var items/eax: (addr item-list) <- copy _items
1036 var items-data-first-free-a/eax: (addr int) <- get items, data-first-free
1037 var final-item/edx: int <- copy *items-data-first-free-a
1038 final-item <- decrement
1039 var dest/edi: (addr int) <- get current-tab, item-index
1040 copy-to *dest, final-item
1043 fn new-thread-tab-from-cursor _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
1044 var env/edi: (addr environment) <- copy _env
1045 var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
1046 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1047 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1048 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1049 var item-index/esi: int <- item-index env, _items, channels
1050 var post-index/ecx: int <- post-index _items, item-index
1051 new-thread-tab env, users, channels, _items, post-index, item-index
1054 fn new-thread-tab _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list), _post-index: int, _item-index: int {
1055 var env/edi: (addr environment) <- copy _env
1056 var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
1057 increment *current-tab-index-addr
1058 var current-tab-index/edx: int <- copy *current-tab-index-addr
1059 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1060 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1061 var max-tabs/ebx: int <- length tabs
1062 compare current-tab-index, max-tabs
1064 compare current-tab-index, max-tabs
1066 abort "history overflow; grow max-history (we should probably improve this)"
1068 var current-tab-offset/edi: (offset tab) <- compute-offset tabs, current-tab-index
1069 var current-tab/edi: (addr tab) <- index tabs, current-tab-offset
1070 clear-object current-tab
1071 var current-tab-type/eax: (addr int) <- get current-tab, type
1072 copy-to *current-tab, 3/thread
1073 var current-tab-root-index/eax: (addr int) <- get current-tab, root-index
1074 var post-index/ecx: int <- copy _post-index
1075 copy-to *current-tab-root-index, post-index
1076 var items/eax: (addr item-list) <- copy _items
1077 var items-data-ah/eax: (addr handle array item) <- get items, data
1078 var items-data/eax: (addr array item) <- lookup *items-data-ah
1079 var offset/ecx: (offset item) <- compute-offset items-data, post-index
1080 var post/eax: (addr item) <- index items-data, offset
1081 var post-comments-first-free-addr/ecx: (addr int) <- get post, comments-first-free
1083 # post-comment-index = index of a comment in a post's comment array
1084 # comment-index = index of a comment in the global item list
1085 var final-post-comment-index/ecx: int <- copy *post-comments-first-free-addr
1086 final-post-comment-index <- decrement
1087 var post-comments-ah/eax: (addr handle array int) <- get post, comments
1088 var post-comments/eax: (addr array int) <- lookup *post-comments-ah
1089 # look for item-index in post-comments[0..final-post-comment-index]
1090 var curr-post-comment-index/edx: int <- copy final-post-comment-index
1092 compare curr-post-comment-index, 0
1095 # if we didn't find the current item in a post's comments, it must be
1096 # the parent post itself which isn't in the comment list but hackily
1097 # rendered at the bottom. Just render the whole comment list.
1098 var item-index/eax: int <- copy _item-index
1099 var tab-item-index-addr/edi: (addr int) <- get current-tab, item-index
1100 copy-to *tab-item-index-addr, curr-post-comment-index
1103 var curr-comment-index/ecx: (addr int) <- index post-comments, curr-post-comment-index
1104 var item-index/eax: int <- copy _item-index
1105 compare *curr-comment-index, item-index
1109 var item-index/eax: int <- copy _item-index
1110 var tab-item-index-addr/edi: (addr int) <- get current-tab, item-index
1111 copy-to *tab-item-index-addr, curr-post-comment-index
1114 curr-post-comment-index <- decrement
1117 abort "new-thread-tab: should never leave previous loop without returning"
1120 fn new-thread-tab-from-url _env: (addr environment), _url: (addr array byte), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
1121 var id-storage: (array byte 0x11)
1122 var id/ecx: (addr array byte) <- address id-storage
1123 var url/edx: (addr array byte) <- copy _url
1124 var len/ebx: int <- length url
1125 var idx/eax: int <- copy len
1126 idx <- subtract 0x11/id-length
1128 var x/eax: (addr byte) <- index url, idx
1129 var x2/ecx: byte <- copy-byte *x
1134 idx <- increment # skip 'p'
1135 var dest-idx/edi: int <- copy 0
1136 # insert first 10 digits of id
1138 compare dest-idx, 0xa/ten
1141 var c/eax: (addr byte) <- index url, idx
1142 var c2/eax: byte <- copy-byte *c
1143 var dest/ecx: (addr byte) <- index id, dest-idx
1144 copy-byte-to *dest, c2
1147 dest-idx <- increment
1150 # insert a decimal point
1152 var dest/ecx: (addr byte) <- index id, dest-idx
1153 var decimal-point/eax: byte <- copy 0x2e
1154 copy-byte-to *dest, decimal-point
1155 dest-idx <- increment
1157 # insert remaining digits of id
1159 compare dest-idx, 0x11/id-length
1162 var c/eax: (addr byte) <- index url, idx
1163 var c2/eax: byte <- copy-byte *c
1164 var dest/ecx: (addr byte) <- index id, dest-idx
1165 copy-byte-to *dest, c2
1168 dest-idx <- increment
1171 var post-index/eax: int <- find-item-by-id _items, id
1172 new-thread-tab _env, users, channels, _items, post-index, post-index
1175 fn find-item-by-id _items: (addr item-list), id: (addr array byte) -> _/eax: int {
1176 var items/eax: (addr item-list) <- copy _items
1177 var items-data-ah/eax: (addr handle array item) <- get items, data
1178 var items-data/eax: (addr array item) <- lookup *items-data-ah
1179 var i/ecx: int <- copy 0
1180 var len/edx: int <- length items-data
1184 var offset/edx: (offset item) <- compute-offset items-data, i
1185 var curr-item/eax: (addr item) <- index items-data, offset
1186 var curr-item-id-ah/eax: (addr handle array byte) <- get curr-item, id
1187 var curr-item-id/eax: (addr array byte) <- lookup *curr-item-id-ah
1189 var found?/eax: boolean <- string-equal? curr-item-id, id
1190 compare found?, 0/false
1197 abort "find-item-by-id: not found"
1201 # hide a thread in a (channel or all-items) tab
1202 fn hide-thread _env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
1203 var env/edi: (addr environment) <- copy _env
1204 var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
1205 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1206 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1207 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1208 var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
1209 var current-tab/ebx: (addr tab) <- index tabs, current-tab-offset
1210 var current-tab-hidden-items-ah/edx: (addr handle stream int) <- get current-tab, hidden-items
1211 var current-tab-hidden-items/eax: (addr stream int) <- lookup *current-tab-hidden-items-ah
1213 compare current-tab-hidden-items, 0
1215 populate-stream current-tab-hidden-items-ah, 0x10/max-hidden-threads
1216 current-tab-hidden-items <- lookup *current-tab-hidden-items-ah
1219 var too-many-hidden-items?/eax: boolean <- stream-full? current-tab-hidden-items
1220 compare too-many-hidden-items?, 0/false
1222 abort "too many hidden threads in this tab" # TODO: create a space for flash error messages on screen
1225 var current-item-index/esi: int <- item-index env, items, channels
1226 var current-post-index-value/ecx: int <- post-index items, current-item-index
1227 # . turn current-post-index into an addr
1228 var current-post-index-storage: int
1229 copy-to current-post-index-storage, current-post-index-value
1230 var current-post-index-addr/ecx: (addr int) <- address current-post-index-storage
1232 write-to-stream current-tab-hidden-items, current-post-index-addr
1233 # current-tab's item-index is now on a hidden item
1234 # try to position it on a visible item
1235 var item-index-addr/esi: (addr int) <- get current-tab, item-index
1236 var old-item-index/eax: int <- copy *item-index-addr
1237 next-item env, users, channels, items
1238 compare *item-index-addr, old-item-index
1240 previous-item env, users, channels, items
1243 fn should-hide? _tab: (addr tab), item-index: int, items: (addr item-list) -> _/eax: boolean {
1244 var post-index/ecx: int <- post-index items, item-index
1245 var tab/esi: (addr tab) <- copy _tab
1246 var tab-hidden-items-ah/edx: (addr handle stream int) <- get tab, hidden-items
1247 var tab-hidden-items/eax: (addr stream int) <- lookup *tab-hidden-items-ah
1248 compare tab-hidden-items, 0
1251 # either we haven't hidden anything, or we're in a tab type that doesn't
1255 rewind-stream tab-hidden-items
1258 var done?/eax: boolean <- stream-empty? tab-hidden-items
1259 compare done?, 0/false
1263 var curr-item-addr/edx: (addr int) <- address curr-item
1264 read-from-stream tab-hidden-items, curr-item-addr
1265 # if curr-item == post-index, return true
1266 compare curr-item, post-index
1276 # what index in the global items list is the cursor at in the current tab?
1277 fn item-index _env: (addr environment), _items: (addr item-list), _channels: (addr array channel) -> _/esi: int {
1278 var env/eax: (addr environment) <- copy _env
1279 var current-tab-index-addr/esi: (addr int) <- get env, current-tab-index
1280 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1281 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1282 var tab-index/esi: int <- copy *current-tab-index-addr
1283 var tab-offset/esi: (offset tab) <- compute-offset tabs, tab-index
1284 var tab/esi: (addr tab) <- index tabs, tab-offset
1285 var tab-type/eax: (addr int) <- get tab, type
1287 compare *tab-type, 0/all-items
1289 var tab-item-index/eax: (addr int) <- get tab, item-index
1290 return *tab-item-index
1293 compare *tab-type, 1/channel
1295 var channel-index-addr/eax: (addr int) <- get tab, channel-index
1296 var channel-index/eax: int <- copy *channel-index-addr
1297 var channels/ecx: (addr array channel) <- copy _channels
1298 var channel-offset/eax: (offset channel) <- compute-offset channels, channel-index
1299 var current-channel/eax: (addr channel) <- index channels, channel-offset
1300 var current-channel-posts-ah/eax: (addr handle array int) <- get current-channel, posts
1301 var current-channel-posts/eax: (addr array int) <- lookup *current-channel-posts-ah
1302 var channel-item-index-addr/ecx: (addr int) <- get tab, item-index
1303 var channel-item-index/ecx: int <- copy *channel-item-index-addr
1304 var channel-item-index/eax: (addr int) <- index current-channel-posts, channel-item-index
1305 return *channel-item-index
1308 compare *tab-type, 2/search
1310 var tab-search-items-ah/eax: (addr handle array int) <- get tab, search-items
1311 var tab-search-items/eax: (addr array int) <- lookup *tab-search-items-ah
1312 var tab-search-items-index-addr/ecx: (addr int) <- get tab, item-index
1313 var tab-search-items-index/ecx: int <- copy *tab-search-items-index-addr
1314 var src/eax: (addr int) <- index tab-search-items, tab-search-items-index
1318 compare *tab-type, 3/thread
1320 var items/eax: (addr item-list) <- copy _items
1321 var items-data-ah/eax: (addr handle array item) <- get items, data
1322 var _items-data/eax: (addr array item) <- lookup *items-data-ah
1323 var items-data/edi: (addr array item) <- copy _items-data
1324 var tab-root-index-addr/eax: (addr int) <- get tab, root-index
1325 var tab-root-index/eax: int <- copy *tab-root-index-addr
1326 var tab-root-offset/eax: (offset item) <- compute-offset items-data, tab-root-index
1327 var post/eax: (addr item) <- index items-data, tab-root-offset
1328 var post-comments-ah/eax: (addr handle array int) <- get post, comments
1329 var post-comments/eax: (addr array int) <- lookup *post-comments-ah
1330 var tab-item-index-addr/ecx: (addr int) <- get tab, item-index
1331 var tab-item-index/ecx: int <- copy *tab-item-index-addr
1332 var src/eax: (addr int) <- index post-comments, tab-item-index
1335 abort "item-index: unknown tab type"
1339 # go from a comment item to its parent post
1340 fn post-index _items: (addr item-list), item-index: int -> _/ecx: int {
1341 var items/eax: (addr item-list) <- copy _items
1342 var items-data-ah/eax: (addr handle array item) <- get items, data
1343 var items-data/eax: (addr array item) <- lookup *items-data-ah
1344 var index/ecx: int <- copy item-index
1345 var offset/ecx: (offset item) <- compute-offset items-data, index
1346 var item/eax: (addr item) <- index items-data, offset
1347 var parent/eax: (addr int) <- get item, parent
1356 fn new-channel-tab _env: (addr environment), channel-index: int, _channels: (addr array channel) {
1357 var env/edi: (addr environment) <- copy _env
1358 var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
1359 increment *current-tab-index-addr
1360 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1361 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1362 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1363 var max-tabs/edx: int <- length tabs
1364 compare current-tab-index, max-tabs
1366 compare current-tab-index, max-tabs
1368 abort "history overflow; grow max-history (we should probably improve this)"
1370 var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
1371 var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
1372 clear-object current-tab
1373 var current-tab-type/eax: (addr int) <- get current-tab, type
1374 copy-to *current-tab, 1/channel
1375 var current-tab-channel-index/eax: (addr int) <- get current-tab, channel-index
1376 var curr-channel-index/edx: int <- copy channel-index
1377 copy-to *current-tab-channel-index, curr-channel-index
1378 var channels/esi: (addr array channel) <- copy _channels
1379 var curr-channel-offset/eax: (offset channel) <- compute-offset channels, curr-channel-index
1380 var curr-channel/eax: (addr channel) <- index channels, curr-channel-offset
1381 var curr-channel-posts-first-free-addr/eax: (addr int) <- get curr-channel, posts-first-free
1382 var curr-channel-final-post-index/eax: int <- copy *curr-channel-posts-first-free-addr
1383 curr-channel-final-post-index <- decrement
1384 var dest/edi: (addr int) <- get current-tab, item-index
1385 copy-to *dest, curr-channel-final-post-index
1388 fn new-search-tab _env: (addr environment), items: (addr item-list) {
1389 var env/edi: (addr environment) <- copy _env
1390 var current-tab-index-addr/eax: (addr int) <- get env, current-tab-index
1391 increment *current-tab-index-addr
1392 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1393 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1394 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1395 var max-tabs/edx: int <- length tabs
1396 compare current-tab-index, max-tabs
1398 compare current-tab-index, max-tabs
1400 abort "history overflow; grow max-history (we should probably improve this)"
1402 var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
1403 var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
1404 clear-object current-tab
1405 var current-tab-type/eax: (addr int) <- get current-tab, type
1406 copy-to *current-tab, 2/search
1407 var current-tab-search-terms-ah/edx: (addr handle gap-buffer) <- get current-tab, search-terms
1408 allocate current-tab-search-terms-ah
1409 var current-tab-search-terms/eax: (addr gap-buffer) <- lookup *current-tab-search-terms-ah
1410 initialize-gap-buffer current-tab-search-terms, 0x30/search-capacity
1411 var search-terms-ah/ebx: (addr handle gap-buffer) <- get env, search-terms
1412 copy-gap-buffer search-terms-ah, current-tab-search-terms-ah
1413 var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
1414 search-items current-tab, items, search-terms
1417 fn search-items _tab: (addr tab), _items: (addr item-list), search-terms: (addr gap-buffer) {
1418 var tab/edi: (addr tab) <- copy _tab
1419 var tab-items-first-free-addr/esi: (addr int) <- get tab, search-items-first-free
1420 var tab-items-ah/eax: (addr handle array int) <- get tab, search-items
1421 populate tab-items-ah, 0x100/max-search-results
1422 var _tab-items/eax: (addr array int) <- lookup *tab-items-ah
1423 var tab-items/edi: (addr array int) <- copy _tab-items
1424 # preprocess search-terms
1425 var search-terms-stream-storage: (stream byte 0x100)
1426 var search-terms-stream-addr/ecx: (addr stream byte) <- address search-terms-stream-storage
1427 emit-gap-buffer search-terms, search-terms-stream-addr
1428 var search-terms-text-h: (handle array byte)
1429 var search-terms-text-ah/eax: (addr handle array byte) <- address search-terms-text-h
1430 stream-to-array search-terms-stream-addr, search-terms-text-ah
1431 var tmp/eax: (addr array byte) <- lookup *search-terms-text-ah
1432 var search-terms-text: (addr array byte)
1433 copy-to search-terms-text, tmp
1435 var items/ecx: (addr item-list) <- copy _items
1436 var items-data-ah/eax: (addr handle array item) <- get items, data
1437 var _items-data/eax: (addr array item) <- lookup *items-data-ah
1438 var items-data/ebx: (addr array item) <- copy _items-data
1439 var items-data-first-free-a/edx: (addr int) <- get items, data-first-free
1440 var i/ecx: int <- copy 0
1442 compare i, *items-data-first-free-a
1444 var curr-offset/eax: (offset item) <- compute-offset items-data, i
1445 var curr-item/eax: (addr item) <- index items-data, curr-offset
1446 var found?/eax: boolean <- search-terms-match? curr-item, search-terms-text
1447 compare found?, 0/false
1450 var tab-items-first-free/eax: int <- copy *tab-items-first-free-addr
1451 compare tab-items-first-free, 0x100/max-search-results
1453 var dest/eax: (addr int) <- index tab-items, tab-items-first-free
1455 increment *tab-items-first-free-addr
1460 var tab/edi: (addr tab) <- copy _tab
1461 var tab-item-index-addr/edi: (addr int) <- get tab, item-index
1462 var tab-items-first-free/eax: int <- copy *tab-items-first-free-addr
1463 tab-items-first-free <- decrement
1464 copy-to *tab-item-index-addr, tab-items-first-free
1467 fn search-terms-match? _item: (addr item), search-terms: (addr array byte) -> _/eax: boolean {
1468 var item/esi: (addr item) <- copy _item
1469 var item-text-ah/eax: (addr handle array byte) <- get item, text
1470 var item-text/eax: (addr array byte) <- lookup *item-text-ah
1471 var i/ecx: int <- copy 0
1472 var max/edx: int <- length item-text
1473 var search-terms2/ebx: (addr array byte) <- copy search-terms
1474 var slen/ebx: int <- length search-terms2
1475 max <- subtract slen
1479 var found?/eax: boolean <- substring-match? item-text, search-terms, i
1480 compare found?, 0/false
1491 fn substring-match? _s: (addr array byte), _pat: (addr array byte), start: int -> _/eax: boolean {
1492 var s/esi: (addr array byte) <- copy _s
1493 var pat/edi: (addr array byte) <- copy _pat
1494 var s-idx/edx: int <- copy start
1495 var pat-idx/ebx: int <- copy 0
1497 var tmp/eax: int <- length pat
1498 copy-to pat-len, tmp
1500 compare pat-idx, pat-len
1502 var s-ab/eax: (addr byte) <- index s, s-idx
1503 var s-b/eax: byte <- copy-byte *s-ab
1504 var pat-ab/ecx: (addr byte) <- index pat, pat-idx
1505 var pat-b/ecx: byte <- copy-byte *pat-ab
1512 pat-idx <- increment
1518 fn previous-tab _env: (addr environment) {
1519 var env/edi: (addr environment) <- copy _env
1520 var current-tab-index-addr/ecx: (addr int) <- get env, current-tab-index
1521 compare *current-tab-index-addr, 0
1524 decrement *current-tab-index-addr
1525 # if necessary restore search state
1526 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1527 var tabs/eax: (addr array tab) <- lookup *tabs-ah
1528 var current-tab-index/ecx: int <- copy *current-tab-index-addr
1529 var current-tab-offset/ecx: (offset tab) <- compute-offset tabs, current-tab-index
1530 var current-tab/ecx: (addr tab) <- index tabs, current-tab-offset
1531 var current-tab-type/eax: (addr int) <- get current-tab, type
1532 compare *current-tab-type, 2/search
1534 var current-tab-search-terms-ah/ecx: (addr handle gap-buffer) <- get current-tab, search-terms
1535 var search-terms-ah/edx: (addr handle gap-buffer) <- get env, search-terms
1536 var search-terms/eax: (addr gap-buffer) <- lookup *search-terms-ah
1537 clear-gap-buffer search-terms
1538 copy-gap-buffer current-tab-search-terms-ah, search-terms-ah
1542 fn next-item _env: (addr environment), users: (addr array user), _channels: (addr array channel), _items: (addr item-list) {
1543 var env/edi: (addr environment) <- copy _env
1544 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1545 var _tabs/eax: (addr array tab) <- lookup *tabs-ah
1546 var tabs/edx: (addr array tab) <- copy _tabs
1547 var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
1548 var current-tab-index/eax: int <- copy *current-tab-index-a
1549 var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
1550 var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
1551 var dest/ebx: (addr int) <- get current-tab, item-index
1552 # if current-tab isn't all-items or channel, no need to worry about hidden items
1553 var current-tab-type/eax: (addr int) <- get current-tab, type
1555 compare *current-tab-type, 0/all-items
1557 compare *current-tab-type, 1/channel
1566 var old-value/ecx: int <- copy *dest
1567 # do { --*dest } while *dest > 0 and should-hide?(current-tab, *dest)
1572 # if current item is not hidden, return
1573 var current-item-index/esi: int <- item-index env, _items, _channels
1574 var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
1575 compare should-hide?, 0/false
1579 # couldn't find a visible item. Restore.
1580 copy-to *dest, old-value
1583 fn previous-item _env: (addr environment), users: (addr array user), _channels: (addr array channel), _items: (addr item-list) {
1584 var env/edi: (addr environment) <- copy _env
1585 var tabs-ah/eax: (addr handle array tab) <- get env, tabs
1586 var _tabs/eax: (addr array tab) <- lookup *tabs-ah
1587 var tabs/edx: (addr array tab) <- copy _tabs
1588 var current-tab-index-a/eax: (addr int) <- get env, current-tab-index
1589 var current-tab-index/eax: int <- copy *current-tab-index-a
1590 var current-tab-offset/eax: (offset tab) <- compute-offset tabs, current-tab-index
1591 var current-tab/edx: (addr tab) <- index tabs, current-tab-offset
1592 var current-tab-type/eax: (addr int) <- get current-tab, type
1593 compare *current-tab-type, 0/all-items
1596 var items/esi: (addr item-list) <- copy _items
1597 var items-data-first-free-a/ecx: (addr int) <- get items, data-first-free
1598 var final-item-index/ecx: int <- copy *items-data-first-free-a
1599 final-item-index <- decrement
1600 var dest/ebx: (addr int) <- get current-tab, item-index
1601 var old-value/eax: int <- copy *dest
1602 # do { ++*dest } while *dest < final-index and should-hide?(current-tab, *dest)
1604 compare *dest, final-item-index
1607 # if current item is not hidden, return
1608 var current-item-index/esi: int <- item-index env, _items, _channels
1609 var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
1610 compare should-hide?, 0/false
1614 # couldn't find a visible item. Restore.
1615 copy-to *dest, old-value
1618 compare *current-tab-type, 1/channel
1621 var current-channel-index-addr/eax: (addr int) <- get current-tab, channel-index
1622 var current-channel-index/eax: int <- copy *current-channel-index-addr
1623 var channels/esi: (addr array channel) <- copy _channels
1624 var current-channel-offset/eax: (offset channel) <- compute-offset channels, current-channel-index
1625 var current-channel/eax: (addr channel) <- index channels, current-channel-offset
1626 var current-channel-posts-first-free-addr/eax: (addr int) <- get current-channel, posts-first-free
1627 var final-item-index/ecx: int <- copy *current-channel-posts-first-free-addr
1628 final-item-index <- decrement
1629 var dest/ebx: (addr int) <- get current-tab, item-index
1630 var old-value/eax: int <- copy *dest
1631 # do { ++*dest } while *dest < final-index and should-hide?(current-tab, *dest)
1633 compare *dest, final-item-index
1636 # if current item is not hidden, return
1637 var current-item-index/esi: int <- item-index env, _items, _channels
1638 var should-hide?/eax: boolean <- should-hide? current-tab, current-item-index, _items
1639 compare should-hide?, 0/false
1643 # couldn't find a visible item. Restore.
1644 copy-to *dest, old-value
1647 compare *current-tab-type, 2/search
1650 var current-tab-search-items-first-free-addr/eax: (addr int) <- get current-tab, search-items-first-free
1651 var final-item-index/ecx: int <- copy *current-tab-search-items-first-free-addr
1652 final-item-index <- decrement
1653 var dest/eax: (addr int) <- get current-tab, item-index
1654 compare *dest, final-item-index
1659 compare *current-tab-type, 3/thread
1662 var items/eax: (addr item-list) <- copy _items
1663 var items-data-ah/eax: (addr handle array item) <- get items, data
1664 var _items-data/eax: (addr array item) <- lookup *items-data-ah
1665 var items-data/esi: (addr array item) <- copy _items-data
1666 var current-tab-root-index-addr/eax: (addr int) <- get current-tab, root-index
1667 var current-tab-root-index/eax: int <- copy *current-tab-root-index-addr
1668 var current-tab-root-offset/eax: (offset item) <- compute-offset items-data, current-tab-root-index
1669 var post/eax: (addr item) <- index items-data, current-tab-root-offset
1670 var post-comments-first-free-addr/ecx: (addr int) <- get post, comments-first-free
1671 var final-item-index/ecx: int <- copy *post-comments-first-free-addr
1672 final-item-index <- decrement
1673 var dest/eax: (addr int) <- get current-tab, item-index
1674 compare *dest, final-item-index
1681 fn page-down _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
1682 var env/edi: (addr environment) <- copy _env
1683 var items/eax: (addr item-list) <- copy _items
1684 var items-data-ah/eax: (addr handle array item) <- get items, data
1685 var _items-data/eax: (addr array item) <- lookup *items-data-ah
1686 var items-data/ebx: (addr array item) <- copy _items-data
1687 var _old-item-index/esi: int <- item-index env, _items, channels
1688 var old-item-index/ecx: int <- copy _old-item-index
1689 var y/edx: int <- copy 2
1691 compare y, 0x28/screen-height-minus-menu
1693 var item-index/esi: int <- item-index env, _items, channels
1696 break-if-= # skip this condition on first iteration
1697 compare item-index, old-item-index
1699 # no forward progress; we're at the bottom of the current tab
1702 var item-offset/eax: (offset item) <- compute-offset items-data, item-index
1703 var item/eax: (addr item) <- index items-data, item-offset
1704 var item-text-ah/eax: (addr handle array byte) <- get item, text
1705 var item-text/eax: (addr array byte) <- lookup *item-text-ah
1706 var h/eax: int <- estimate-height item-text
1708 next-item env, users, channels, _items
1711 # we're past the end of the screen now, so bounce back for some continuity
1712 previous-item env, users, channels, _items
1714 # HACK: make sure we make forward progress even if a single post takes up
1716 # We can't see the rest of that single post at the moment. But at least we
1718 var old-item-index/eax: int <- copy old-item-index
1719 var item-index/esi: int <- item-index env, _items, channels
1720 compare item-index, old-item-index
1722 next-item env, users, channels, _items
1726 fn page-up _env: (addr environment), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
1727 var env/edi: (addr environment) <- copy _env
1728 var items/eax: (addr item-list) <- copy _items
1729 var items-data-ah/eax: (addr handle array item) <- get items, data
1730 var _items-data/eax: (addr array item) <- lookup *items-data-ah
1731 var items-data/ebx: (addr array item) <- copy _items-data
1732 var _old-item-index/esi: int <- item-index env, _items, channels
1733 var old-item-index/ecx: int <- copy _old-item-index
1734 var y/edx: int <- copy 2
1736 compare y, 0x28/screen-height-minus-menu
1738 var item-index/esi: int <- item-index env, _items, channels
1741 break-if-= # skip this condition on first iteration
1742 compare item-index, old-item-index
1744 # no forward progress; we're at the bottom of the current tab
1747 var item-offset/eax: (offset item) <- compute-offset items-data, item-index
1748 var item/eax: (addr item) <- index items-data, item-offset
1749 var item-text-ah/eax: (addr handle array byte) <- get item, text
1750 var item-text/eax: (addr array byte) <- lookup *item-text-ah
1751 var h/eax: int <- estimate-height item-text
1753 previous-item env, users, channels, _items
1758 # keep sync'd with render-item
1759 fn estimate-height _message-text: (addr array byte) -> _/eax: int {
1760 var message-text/esi: (addr array byte) <- copy _message-text
1761 var result/eax: int <- length message-text
1762 var remainder/edx: int <- copy 0
1763 result, remainder <- integer-divide result, 0x40/post-width
1764 compare remainder, 0
1769 result <- add 2/item-padding-ver
1770 compare result, 6/avatar-space-ver
1773 return 6/avatar-space-ver