@@ -114,43 +114,30 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
114
114
}
115
115
} else if (c == 0x1b ) {
116
116
// Handle commands of the form [ESC].<digits><command-char> where . is not yet known.
117
- uint16_t n = 0 ;
117
+ uint8_t vt_args [3 ] = {0 ,-1 ,-1 };
118
+ uint8_t n_args = 1 ;
118
119
uint8_t j = 1 ;
119
120
for (; j < 6 ; j ++ ) {
120
121
if ('0' <= i [j ] && i [j ] <= '9' ) {
121
- n = n * 10 + (i [j ] - '0' );
122
+ vt_args [ 0 ] = vt_args [ 0 ] * 10 + (i [j ] - '0' );
122
123
} else {
123
124
c = i [j ];
124
125
break ;
125
126
}
126
127
}
127
128
if (i [0 ] == '[' ) {
128
- uint16_t m = -1 ;
129
- if (c == ';' ) {
130
- m = 0 ;
129
+ for (uint8_t i_args = 1 ; i_args < 3 && c == ';' ; i_args ++ ) {
130
+ vt_args [i_args ] = 0 ;
131
131
for (++ j ; j < 9 ; j ++ ) {
132
132
if ('0' <= i [j ] && i [j ] <= '9' ) {
133
- m = m * 10 + (i [j ] - '0' );
133
+ vt_args [i_args ] = vt_args [i_args ] * 10 + (i [j ] - '0' );
134
+ n_args = i_args + 1 ;
134
135
} else {
135
136
c = i [j ];
136
137
break ;
137
138
}
138
139
}
139
140
}
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
- }
151
- }
152
- }
153
- #endif
154
141
if (c == '?' ) {
155
142
#if CIRCUITPY_TERMINALIO_VT100
156
143
if (i [2 ] == '2' && i [3 ] == '5' ) {
@@ -167,78 +154,62 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
167
154
#endif
168
155
} else {
169
156
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
- }
157
+ uint8_t clr_start = self -> cursor_x ;
158 + uint8_t clr_end = self -> scroll_area -> width_in_tiles ;
175
159
#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
- }
160
+ if (vt_args [0 ] == 1 ) {
161
+ clr_start = 0 ;
162
+ clr_end = self -> cursor_x ;
163
+ } else if (vt_args [0 ] == 2 ) {
164
+ clr_start = 0 ;
165
+ }
186
166
#endif
167
+ // Clear the (start/rest/all) of the line.
168
+ for (uint16_t k = clr_start ; k < clr_end ; k ++ ) {
169
+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
187
170
}
188
171
} else if (c == 'D' ) {
189
- if (n > self -> cursor_x ) {
172
+ if (vt_args [ 0 ] > self -> cursor_x ) {
190
173
self -> cursor_x = 0 ;
191
174
} else {
192
- self -> cursor_x -= n ;
175
+ self -> cursor_x -= vt_args [ 0 ] ;
193
176
}
194
177
} else if (c == 'J' ) {
195
- if (n == 2 ) {
178
+ if (vt_args [ 0 ] == 2 ) {
196
179
common_hal_displayio_tilegrid_set_top_left (self -> scroll_area , 0 , 0 );
197
180
self -> cursor_x = self -> cursor_y = start_y = 0 ;
198
181
common_hal_displayio_tilegrid_set_all_tiles (self -> scroll_area , 0 );
199
182
}
200
183
} else if (c == 'H' ) {
201
- if (n > 0 ) {
202
- n -- ;
184
+ if (vt_args [ 0 ] > 0 ) {
185
+ vt_args [ 0 ] -- ;
203
186
}
204
- if (m == -1 ) {
205
- m = 0 ;
187
+ if (vt_args [ 1 ] == -1 ) {
188
+ vt_args [ 1 ] = 0 ;
206
189
}
207
- if (m > 0 ) {
208
- m -- ;
190
+ if (vt_args [ 1 ] > 0 ) {
191
+ vt_args [ 1 ] -- ;
209
192
}
210
- if (n >= self -> scroll_area -> height_in_tiles ) {
211
- n = self -> scroll_area -> height_in_tiles - 1 ;
193
+ if (vt_args [ 0 ] >= self -> scroll_area -> height_in_tiles ) {
194
+ vt_args [ 0 ] = self -> scroll_area -> height_in_tiles - 1 ;
212
195
}
213
- if (m >= self -> scroll_area -> width_in_tiles ) {
214
- m = self -> scroll_area -> width_in_tiles - 1 ;
196
+ if (vt_args [ 1 ] >= self -> scroll_area -> width_in_tiles ) {
197
+ vt_args [ 1 ] = self -> scroll_area -> width_in_tiles - 1 ;
215
198
}
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 ;
199
+ vt_args [ 0 ] = (vt_args [ 0 ] + self -> scroll_area -> top_left_y ) % self -> scroll_area -> height_in_tiles ;
200
+ self -> cursor_x = vt_args [ 1 ] ;
201
+ self -> cursor_y = vt_args [ 0 ] ;
219
202
start_y = self -> cursor_y ;
220
203
#if CIRCUITPY_TERMINALIO_VT100
221
204
} else if (c == 'm' ) {
222
- if ((n >= 40 && n <= 47 ) || (n >= 30 && n <= 37 )) {
223
- common_hal_displayio_palette_set_color (terminal_palette , 1 - (n / 40 ), _select_color (n % 10 ));
224
- }
225
- if (n == 0 ) {
226
- common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
227
- common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
228
- }
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 ));
231
- }
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 );
235
- }
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 ));
238
- }
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 );
205
+ for (uint8_t i_args = 0 ; i_args < n_args ; i_args ++ ) {
206
+ if ((vt_args [i_args ] >= 40 && vt_args [i_args ] <= 47 ) || (vt_args [i_args ] >= 30 && vt_args [i_args ] <= 37 )) {
207
+ common_hal_displayio_palette_set_color (terminal_palette , 1 - (vt_args [i_args ] / 40 ), _select_color (vt_args [i_args ] % 10 ));
208
+ }
209
+ if (vt_args [i_args ] == 0 ) {
210
+ common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
211
+ common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
212
+ }
242
213
}
243
214
#endif
244
215
}
@@ -281,7 +252,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
281
252
#endif
282
253
} else if (i [0 ] == ']' && c == ';' ) {
283
254
self -> in_osc_command = true;
284
- self -> osc_command = n ;
255
+ self -> osc_command = vt_args [ 0 ] ;
285
256
i += j + 1 ;
286
257
}
287
258
}
0 commit comments