@@ -47,6 +47,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
47
47
return len ;
48
48
}
49
49
50
+ #if CIRCUITPY_TERMINALIO_VT100
50
51
uint32_t _select_color (uint16_t ascii_color ) {
51
52
uint32_t color_value = 0 ;
52
53
if ((ascii_color & 1 ) > 0 ) {
@@ -63,6 +64,8 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
63
64
}
64
65
65
66
displayio_palette_t * terminal_palette = self -> scroll_area -> pixel_shader ;
67
+ #endif
68
+
66
69
const byte * i = data ;
67
70
uint16_t start_y = self -> cursor_y ;
68
71
while (i < data + len ) {
@@ -113,7 +116,6 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
113
116
// Handle commands of the form [ESC].<digits><command-char> where . is not yet known.
114
117
uint16_t n = 0 ;
115
118
uint8_t j = 1 ;
116
- uint8_t j2 = 0 ;
117
119
for (; j < 6 ; j ++ ) {
118
120
if ('0' <= i [j ] && i [j ] <= '9' ) {
119
121
n = n * 10 + (i [j ] - '0' );
@@ -123,13 +125,34 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
123
125
}
124
126
}
125
127
if (i [0 ] == '[' ) {
126
- if (i [1 ] == 'K' ) {
127
- // Clear the rest of the line.
128
- for (uint16_t k = self -> cursor_x ; k < self -> scroll_area -> width_in_tiles ; k ++ ) {
129
- common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
128
+ uint16_t m = -1 ;
129
+ if (c == ';' ) {
130
+ m = 0 ;
131
+ for (++ j ; j < 9 ; j ++ ) {
132
+ if ('0' <= i [j ] && i [j ] <= '9' ) {
133
+ m = m * 10 + (i [j ] - '0' );
134
+ } else {
135
+ c = i [j ];
136
+ break ;
137
+ }
138
+ }
139
+ }
140
+ #if CIRCUITPY_TERMINALIO_VT100
141
+ uint8_t m2 = -1 ;
142
+ if (c == ';' ) {
143
+ m2 = 0 ;
144
+ for (++ j ; j < 12 ; j ++ ) {
145
+ if ('0' <= i [j ] && i [j ] <= '9' ) {
146
+ m2 = m2 * 10 + (i [j ] - '0' );
147
+ } else {
148
+ c = i [j ];
149
+ break ;
150
+ }
130
151
}
131
- i += 2 ;
132
- } else if (i [1 ] == '?' ) {
152
+ }
153
+ #endif
154
+ if (c == '?' ) {
155
+ #if CIRCUITPY_TERMINALIO_VT100
133
156
if (i [2 ] == '2' && i [3 ] == '5' ) {
134
157
// cursor visibility commands
135
158
if (i [4 ] == 'h' ) {
@@ -141,100 +164,87 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
141
164
}
142
165
}
143
166
i += 5 ;
167
+ #endif
144
168
} else {
145
- if (c == 'D' ) {
169
+ if (c == 'K' ) {
170
+ if (n == 0 ) {
171
+ // Clear the rest of the line.
172
+ for (uint16_t k = self -> cursor_x ; k < self -> scroll_area -> width_in_tiles ; k ++ ) {
173
+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
174
+ }
175
+ #if CIRCUITPY_TERMINALIO_VT100
176
+ } else if (n == 1 ) {
177
+ // Clear start to cursor
178
+ for (uint16_t k = 0 ; k < self -> cursor_x ; k ++ ) {
179
+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
180
+ }
181
+ } else if (n == 2 ) {
182
+ // Clear entire line
183
+ for (uint16_t k = 0 ; k < self -> scroll_area -> width_in_tiles ; k ++ ) {
184
+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
185
+ }
186
+ #endif
187
+ }
188
+ } else if (c == 'D' ) {
146
189
if (n > self -> cursor_x ) {
147
190
self -> cursor_x = 0 ;
148
191
} else {
149
192
self -> cursor_x -= n ;
150
193
}
151
- }
152
- if (c == 'J' ) {
194
+ } else if (c == 'J' ) {
153
195
if (n == 2 ) {
154
196
common_hal_displayio_tilegrid_set_top_left (self -> scroll_area , 0 , 0 );
155
197
self -> cursor_x = self -> cursor_y = start_y = 0 ;
156
- n = 0 ;
157
198
common_hal_displayio_tilegrid_set_all_tiles (self -> scroll_area , 0 );
158
199
}
159
- }
160
- if (c == 'm' ) {
200
+ } else if (c == 'H' ) {
201
+ if (n > 0 ) {
202
+ n -- ;
203
+ }
204
+ if (m == -1 ) {
205
+ m = 0 ;
206
+ }
207
+ if (m > 0 ) {
208
+ m -- ;
209
+ }
210
+ if (n >= self -> scroll_area -> height_in_tiles ) {
211
+ n = self -> scroll_area -> height_in_tiles - 1 ;
212
+ }
213
+ if (m >= self -> scroll_area -> width_in_tiles ) {
214
+ m = self -> scroll_area -> width_in_tiles - 1 ;
215
+ }
216
+ n = (n + self -> scroll_area -> top_left_y ) % self -> scroll_area -> height_in_tiles ;
217
+ self -> cursor_x = m ;
218
+ self -> cursor_y = n ;
219
+ start_y = self -> cursor_y ;
220
+ #if CIRCUITPY_TERMINALIO_VT100
221
+ } else if (c == 'm' ) {
161
222
if ((n >= 40 && n <= 47 ) || (n >= 30 && n <= 37 )) {
162
223
common_hal_displayio_palette_set_color (terminal_palette , 1 - (n / 40 ), _select_color (n % 10 ));
163
224
}
164
225
if (n == 0 ) {
165
226
common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
166
227
common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
167
228
}
168
- }
169
- if (c == 'H' ) {
170
- self -> cursor_x = self -> cursor_y = start_y = 0 ;
171
- }
172
- if (c == ';' ) {
173
- uint16_t m = 0 ;
174
- uint8_t m2 = 0 ;
175
- for (++ j ; j < 9 ; j ++ ) {
176
- if ('0' <= i [j ] && i [j ] <= '9' ) {
177
- m = m * 10 + (i [j ] - '0' );
178
- } else {
179
- c = i [j ];
180
- break ;
181
- }
229
+ if ((m >= 40 && m <= 47 ) || (m >= 30 && m <= 37 )) {
230
+ common_hal_displayio_palette_set_color (terminal_palette , 1 - (m / 40 ), _select_color (m % 10 ));
182
231
}
183
- if (c == ';' ) {
184
- for (++ j2 ; j2 < 9 ; j2 ++ ) {
185
- if ('0' <= i [j2 ] && i [j2 ] <= '9' ) {
186
- m2 = m2 * 10 + (i [j2 ] - '0' );
187
- } else {
188
- c = i [j2 ];
189
- break ;
190
- }
191
- }
232
+ if (m == 0 ) {
233
+ common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
234
+ common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
192
235
}
193
- if (c == 'H' ) {
194
- if (n > 0 ) {
195
- n -- ;
196
- }
197
- if (m > 0 ) {
198
- m -- ;
199
- }
200
- if (n >= self -> scroll_area -> height_in_tiles ) {
201
- n = self -> scroll_area -> height_in_tiles - 1 ;
202
- }
203
- if (m >= self -> scroll_area -> width_in_tiles ) {
204
- m = self -> scroll_area -> width_in_tiles - 1 ;
205
- }
206
- n = (n + self -> scroll_area -> top_left_y ) % self -> scroll_area -> height_in_tiles ;
207
- self -> cursor_x = m ;
208
- self -> cursor_y = n ;
209
- start_y = self -> cursor_y ;
236
+ if ((m2 >= 40 && m2 <= 47 ) || (m2 >= 30 && m2 <= 37 )) {
237
+ common_hal_displayio_palette_set_color (terminal_palette , 1 - (m2 / 40 ), _select_color (m2 % 10 ));
210
238
}
211
- if (c == 'm' ) {
212
- if ((n >= 40 && n <= 47 ) || (n >= 30 && n <= 37 )) {
213
- common_hal_displayio_palette_set_color (terminal_palette , 1 - (n / 40 ), _select_color (n % 10 ));
214
- }
215
- if (n == 0 ) {
216
- common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
217
- common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
218
- }
219
- if ((m >= 40 && m <= 47 ) || (m >= 30 && m <= 37 )) {
220
- common_hal_displayio_palette_set_color (terminal_palette , 1 - (m / 40 ), _select_color (m % 10 ));
221
- }
222
- if (m == 0 ) {
223
- common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
224
- common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
225
- }
226
- if ((m2 >= 40 && m2 <= 47 ) || (m2 >= 30 && m2 <= 37 )) {
227
- common_hal_displayio_palette_set_color (terminal_palette , 1 - (m2 / 40 ), _select_color (m2 % 10 ));
228
- }
229
- if (m2 == 0 ) {
230
- common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
231
- common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
232
- }
239
+ if (m2 == 0 ) {
240
+ common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
241
+ common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
233
242
}
243
+ #endif
234
244
}
235
- i += j + j2 + 1 ;
236
- continue ;
245
+ i += j + 1 ;
237
246
}
247
+ #if CIRCUITPY_TERMINALIO_VT100
238
248
} else if (i [0 ] == 'M' ) {
239
249
if (self -> cursor_y != self -> scroll_area -> top_left_y ) {
240
250
if (self -> cursor_y > 0 ) {
@@ -268,6 +278,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
268
278
}
269
279
start_y = self -> cursor_y ;
270
280
i ++ ;
281
+ #endif
271
282
} else if (i [0 ] == ']' && c == ';' ) {
272
283
self -> in_osc_command = true;
273
284
self -> osc_command = n ;
0 commit comments