about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-08-11 17:17:41 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-08-11 17:17:41 -0700
commit5c55de64e010b2b44ec019d5bc546d8f2322d6d0 (patch)
treeab352a03772d4e3aefc9343f575f3284c988d1e8
parentba438e3d8318aa72af1fb0998b10c1a2b9b6940b (diff)
downloadmu-5c55de64e010b2b44ec019d5bc546d8f2322d6d0.tar.gz
slack: render items in reverse chronological order
-rw-r--r--browse-slack/environment.mu23
-rw-r--r--browse-slack/main.mu25
2 files changed, 31 insertions, 17 deletions
diff --git a/browse-slack/environment.mu b/browse-slack/environment.mu
index e0e9fc5f..197215ca 100644
--- a/browse-slack/environment.mu
+++ b/browse-slack/environment.mu
@@ -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
diff --git a/browse-slack/main.mu b/browse-slack/main.mu
index 7aa85132..6471fb51 100644
--- a/browse-slack/main.mu
+++ b/browse-slack/main.mu
@@ -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) {