From 8facfa7d23c93e7eef871b4dcc4e305d354e805c Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 13 Aug 2021 06:56:21 -0700 Subject: slack: start rendering newlines --- browse-slack/environment.mu | 58 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) 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 -- cgit 1.4.1-2-gfad0 t/blame/cache.go?h=v0.3.3&id=4f0847bb24a5df77f88c883461491a2f6fd955d7'>^
c896e6b ^






b29e1c1 ^

c896e6b ^



b29e1c1 ^

c896e6b ^



b29e1c1 ^

c896e6b ^












b29e1c1 ^
c896e6b ^

b29e1c1 ^

c896e6b ^







b29e1c1 ^


c896e6b ^










b29e1c1 ^

c896e6b ^
b29e1c1 ^



c896e6b ^
b29e1c1 ^
c896e6b ^
b29e1c1 ^
c896e6b ^
b29e1c1 ^

4f0847b ^
c896e6b ^
b29e1c1 ^

4f0847b ^
b29e1c1 ^
c896e6b ^
b29e1c1 ^

c896e6b ^

b29e1c1 ^
c896e6b ^
b29e1c1 ^
c896e6b ^
b29e1c1 ^
c896e6b ^

b29e1c1 ^
c896e6b ^



b29e1c1 ^


c896e6b ^






b29e1c1 ^

c896e6b ^
b29e1c1 ^



c896e6b ^
b29e1c1 ^
c896e6b ^


bded77f ^
c896e6b ^
bded77f ^

c896e6b ^
bded77f ^
c896e6b ^

c896e6b ^
bded77f ^







c896e6b ^
bded77f ^



















c896e6b ^
bded77f ^





c896e6b ^

bded77f ^


c896e6b ^
bded77f ^
c896e6b ^

c896e6b ^






c896e6b ^
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187