about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-08-13 06:56:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-08-13 06:56:21 -0700
commit8facfa7d23c93e7eef871b4dcc4e305d354e805c (patch)
treeee89682ab5d8da7909a348454b4a7e60be2f7d71
parentd8ac8020cfac7b4c8e9cce6ab3988511611cff86 (diff)
downloadmu-8facfa7d23c93e7eef871b4dcc4e305d354e805c.tar.gz
slack: start rendering newlines
-rw-r--r--browse-slack/environment.mu58
1 files changed, 57 insertions, 1 deletions
diff --git a/browse-slack/environment.mu b/browse-slack/environment.mu
index cb488453..736b62f4 100644
--- a/browse-slack/environment.mu
+++ b/browse-slack/environment.mu
@@ -25,6 +25,8 @@ fn initialize-environment _self: (addr environment), _items: (addr item-list) {
   copy-to *dest, newest-item
 }
 
+### Render
+
 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
@@ -202,10 +204,64 @@ fn draw-json-text-wrapping-right-then-down screen: (addr screen), _text: (addr a
   }
   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
+  x, y <- draw-json-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color
   return x, y
 }
 
+# draw a stream 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-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 {
+  var xcurr/eax: int <- copy x
+  var ycurr/ecx: int <- copy y
+  {
+    var g/ebx: grapheme <- read-json-grapheme stream
+    compare g, 0xffffffff/end-of-file
+    break-if-=
+    $draw-json-stream-wrapping-right-then-down:render-grapheme: {
+      compare g, 0x5c/backslash
+      {
+        break-if-!=
+        var next-g/ebx: grapheme <- read-json-grapheme stream
+        compare next-g, 0xffffffff/end-of-file
+        break-if-=  # just draw a final backslash
+        xcurr, ycurr <- render-json-escaped-grapheme screen, next-g, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
+        break $draw-json-stream-wrapping-right-then-down:render-grapheme
+      }
+      xcurr, ycurr <- render-grapheme screen, g, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
+    }
+    loop
+  }
+  set-cursor-position screen, xcurr, ycurr
+  return xcurr, ycurr
+}
+
+# just return a different register
+fn read-json-grapheme stream: (addr stream byte) -> _/ebx: grapheme {
+  var result/eax: grapheme <- read-grapheme stream
+  return result
+}
+
+fn render-json-escaped-grapheme screen: (addr screen), g: grapheme, xmin: int, ymin: int, xmax: int, ymax: int, xcurr: int, ycurr: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
+  compare g, 0x6e/n
+  var x/eax: int <- copy xcurr
+  {
+    break-if-!=
+    # minimum effort to clear cursor
+    draw-code-point screen, 0x20/space, xcurr, ycurr, color, background-color
+    x <- copy xmin
+    increment ycurr
+    return x, ycurr
+  }
+  # most characters escape to themselves
+  var y/ecx: int <- copy 0
+  x, y <- render-grapheme screen, g, xmin, ymin, xmax, ymax, xcurr, ycurr, color, background-color
+  return x, y
+}
+
+### Edit
+
 fn update-environment env: (addr environment), key: byte, items: (addr item-list) {
   {
     compare key, 0xe/ctrl-n
+0100 readme: updated' href='/akspecs/ranger/commit/README?h=v1.9.0b6&id=36e4e71ee5643fc0b2c501956086434389ec5384'>36e4e71e ^
20ab9343 ^

20ab9343 ^





4ea0f69a ^

240394a4 ^
7dc8fef8 ^
36e4e71e ^

4a383291 ^
78a7d762 ^
e952d6cb ^
78a7d762 ^
e952d6cb ^
4ea0f69a ^

7838675f ^

07069888 ^

07069888 ^
7838675f ^

1891697f ^
755e7df1 ^
a3d5f44b ^
7838675f ^
7dc8fef8 ^
500cf259 ^


7dc8fef8 ^



240394a4 ^



240394a4 ^
7dc8fef8 ^
240394a4 ^




7dc8fef8 ^
240394a4 ^



e5fb3d74 ^
240394a4 ^

240394a4 ^
7dc8fef8 ^



7b33b517 ^

176e8a68 ^
7b33b517 ^
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