From cf5c8bc6b0e880a312a304a13712dce2b206c3c7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 20 Feb 2021 22:45:10 -0800 Subject: 7762 - baremetal/shell: backspace The text buffer can now shrink, which means we need to be careful to erase the old location of the cursor. Just clear screen before render each time. Which means we need to be more efficient with our rendering. --- baremetal/shell/main.mu | 12 +++++++----- baremetal/shell/sandbox.mu | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'baremetal') diff --git a/baremetal/shell/main.mu b/baremetal/shell/main.mu index ee2dda60..262b9829 100644 --- a/baremetal/shell/main.mu +++ b/baremetal/shell/main.mu @@ -7,11 +7,13 @@ fn main { initialize-sandbox sandbox { render-sandbox 0/screen, sandbox, 2/x, 2/y - var key/eax: byte <- read-key 0/keyboard - compare key, 0 - loop-if-= - # no way to quit right now; just reboot - edit-sandbox sandbox, key + { + var key/eax: byte <- read-key 0/keyboard + compare key, 0 + loop-if-= + # no way to quit right now; just reboot + edit-sandbox sandbox, key + } loop } } diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu index e360b9e6..4ca1082c 100644 --- a/baremetal/shell/sandbox.mu +++ b/baremetal/shell/sandbox.mu @@ -34,7 +34,15 @@ fn add-grapheme-to-sandbox _self: (addr sandbox), c: grapheme { add-grapheme-at-gap data, c } +fn delete-grapheme-before-cursor _self: (addr sandbox) { + var self/esi: (addr sandbox) <- copy _self + var data-ah/eax: (addr handle gap-buffer) <- get self, data + var data/eax: (addr gap-buffer) <- lookup *data-ah + delete-before-gap data +} + fn render-sandbox screen: (addr screen), _self: (addr sandbox), x: int, y: int { + clear-screen screen var self/esi: (addr sandbox) <- copy _self var data-ah/eax: (addr handle gap-buffer) <- get self, data var data/eax: (addr gap-buffer) <- lookup *data-ah @@ -43,5 +51,11 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), x: int, y: int { fn edit-sandbox self: (addr sandbox), key: byte { var g/edx: grapheme <- copy key + { + compare g, 8/backspace + break-if-!= + delete-grapheme-before-cursor self + return + } add-grapheme-to-sandbox self, g } -- cgit 1.4.1-2-gfad0 e/?id=6c4ed3cfe2fe66a1e5f26c404ea90e048142db72'>root/commands/compose/send.go
blob: 59ae5d0bdb2c19f349ae371aea3673b5bb24c1ea (plain) (blame)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265