slack: render items in reverse chronological order

This commit is contained in:
Kartik K. Agaram 2021-08-11 17:17:41 -07:00
parent ba438e3d83
commit 5c55de64e0
2 changed files with 31 additions and 17 deletions

View File

@ -17,7 +17,7 @@ type environment {
# channel-offset-x # in characters
# menu-space-ver # in characters
fn render-environment screen: (addr screen), env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr array item) {
fn render-environment screen: (addr screen), env: (addr environment), users: (addr array user), channels: (addr array channel), items: (addr item-list) {
clear-screen screen
render-search-input screen, env
render-channels screen, env, channels
@ -49,7 +49,7 @@ fn render-channels screen: (addr screen), env: (addr environment), _channels: (a
}
}
fn render-item-list screen: (addr screen), env: (addr environment), _items: (addr array item), users: (addr array user) {
fn render-item-list screen: (addr screen), env: (addr environment), _items: (addr item-list), users: (addr array user) {
var tmp-width/eax: int <- copy 0
var tmp-height/ecx: int <- copy 0
tmp-width, tmp-height <- screen-size screen
@ -60,18 +60,21 @@ fn render-item-list screen: (addr screen), env: (addr environment), _items: (add
#
var y/ecx: int <- copy 2/search-space-ver
y <- add 1/item-padding-ver
var items/esi: (addr array item) <- copy _items
var i/ebx: int <- copy 0
var max/edx: int <- length items
var items/esi: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
var newest-item/eax: (addr int) <- get items, newest
var i/ebx: int <- copy *newest-item
{
compare i, max
break-if->=
compare i, 0
break-if-<
compare y, screen-height
break-if->=
var offset/eax: (offset item) <- compute-offset items, i
var curr-item/eax: (addr item) <- index items, offset
var offset/eax: (offset item) <- compute-offset items-data, i
var curr-item/eax: (addr item) <- index items-data, offset
y <- render-item screen, curr-item, users, y, screen-height
i <- increment
i <- decrement
loop
}
var top/eax: int <- copy screen-height

View File

@ -21,6 +21,11 @@ type item {
newest-comment-index: int
}
type item-list {
data: (handle array item)
newest: int
}
# globals:
# users: (handle array user)
# channels: (handle array channel)
@ -68,11 +73,10 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
populate channels-ah, 0x20/num-channels
var _channels/eax: (addr array channel) <- lookup *channels-ah
var channels/esi: (addr array channel) <- copy _channels
var items-h: (handle array item)
var items-ah/eax: (addr handle array item) <- address items-h
populate items-ah, 0x10000/num-items
var _items/eax: (addr array item) <- lookup *items-ah
var items/edx: (addr array item) <- copy _items
var items-storage: item-list
var items/edx: (addr item-list) <- address items-storage
var items-data-ah/eax: (addr handle array item) <- get items, data
populate items-data-ah, 0x10000/num-items
parse s, users, channels, items
# render
var env-storage: environment
@ -89,7 +93,11 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
}
}
fn parse in: (addr stream byte), users: (addr array user), channels: (addr array channel), items: (addr array item) {
fn parse in: (addr stream byte), users: (addr array user), channels: (addr array channel), _items: (addr item-list) {
var items/esi: (addr item-list) <- copy _items
var items-data-ah/eax: (addr handle array item) <- get items, data
var _items-data/eax: (addr array item) <- lookup *items-data-ah
var items-data/edi: (addr array item) <- copy _items-data
# 'in' consists of a long, flat sequence of records surrounded by parens
var record-storage: (stream byte 0x18000)
var record/ecx: (addr stream byte) <- address record-storage
@ -117,11 +125,14 @@ fn parse in: (addr stream byte), users: (addr array user), channels: (addr array
{
compare user?, 0/false
break-if-!=
parse-item record, channels, items, item-idx
parse-item record, channels, items-data, item-idx
item-idx <- increment
}
loop
}
var dest/eax: (addr int) <- get items, newest
copy-to *dest, item-idx
decrement *dest
}
fn parse-record in: (addr stream byte), out: (addr stream byte) {