about summary refs log tree commit diff stats
path: root/browse-slack
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-08-13 06:38:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-08-13 06:38:03 -0700
commitd8ac8020cfac7b4c8e9cce6ab3988511611cff86 (patch)
tree15d60f9216a9ce69f5d4911ab0ef61f50614a1a7 /browse-slack
parent4e3703de21b03b0f3b21efcda8536ec7a652a5ae (diff)
downloadmu-d8ac8020cfac7b4c8e9cce6ab3988511611cff86.tar.gz
.
Diffstat (limited to 'browse-slack')
-rw-r--r--browse-slack/environment.mu42
1 files changed, 36 insertions, 6 deletions
diff --git a/browse-slack/environment.mu b/browse-slack/environment.mu
index 0fdfc087..cb488453 100644
--- a/browse-slack/environment.mu
+++ b/browse-slack/environment.mu
@@ -160,12 +160,7 @@ fn render-item screen: (addr screen), _item: (addr item), _users: (addr array us
   var text-ah/eax: (addr handle array byte) <- get item, text
   var _text/eax: (addr array byte) <- lookup *text-ah
   var text/edx: (addr array byte) <- copy _text
-  var x/eax: int <- copy 0x20/main-panel-hor
-  x <- add 0x10/avatar-space-hor
-  var text-y/ecx: int <- copy y
-  text-y <- add 1/author-name-padding-ver
-  x, text-y <- draw-text-wrapping-right-then-down screen, text, x text-y, 0x70/xmax=post-right-coord screen-height, x text-y, 7/fg 0/bg
-  text-y <- add 2/item-padding-ver
+  var text-y/eax: int <- render-slack-message screen, text, y, screen-height
   # flush
   add-to y, 6/avatar-space-ver
   compare y, text-y
@@ -176,6 +171,41 @@ fn render-item screen: (addr screen), _item: (addr item), _users: (addr array us
   return text-y
 }
 
+fn render-slack-message screen: (addr screen), text: (addr array byte), ymin: int, ymax: int -> _/eax: int {
+  var x/eax: int <- copy 0x20/main-panel-hor
+  x <- add 0x10/avatar-space-hor
+  var y/ecx: int <- copy ymin
+  y <- add 1/author-name-padding-ver
+  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
+  y <- add 2/item-padding-ver
+  return y
+}
+
+# draw text in the rectangle from (xmin, ymin) to (xmax, ymax), starting from (x, y), wrapping as necessary
+# return the next (x, y) coordinate in raster order where drawing stopped
+# that way the caller can draw more if given the same min and max bounding-box.
+# if there isn't enough space, truncate
+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 {
+  var stream-storage: (stream byte 0x4000/print-buffer-size)
+  var stream/edi: (addr stream byte) <- address stream-storage
+  var text/esi: (addr array byte) <- copy _text
+  var len/eax: int <- length text
+  compare len, 0x4000/print-buffer-size
+  {
+    break-if-<
+    write stream, "ERROR: stream too small in draw-text-wrapping-right-then-down"
+  }
+  compare len, 0x4000/print-buffer-size
+  {
+    break-if->=
+    write stream, text
+  }
+  var x/eax: int <- copy _x
+  var y/ecx: int <- copy _y
+  x, y <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
+  return x, y
+}
+
 fn update-environment env: (addr environment), key: byte, items: (addr item-list) {
   {
     compare key, 0xe/ctrl-n
249'>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