@@ -113,6 +113,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
113113 // Handle commands of the form [ESC].<digits><command-char> where . is not yet known.
114114 uint16_t n = 0 ;
115115 uint8_t j = 1 ;
116+ uint8_t j2 = 0 ;
116117 for (; j < 6 ; j ++ ) {
117118 if ('0' <= i [j ] && i [j ] <= '9' ) {
118119 n = n * 10 + (i [j ] - '0' );
@@ -128,6 +129,18 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
128129 common_hal_displayio_tilegrid_set_tile (self -> scroll_area , k , self -> cursor_y , 0 );
129130 }
130131 i += 2 ;
132+ } else if (i [1 ] == '?' ) {
133+ if (i [2 ] == '2' && i [3 ] == '5' ) {
134+ // cursor visibility commands
135+ if (i [4 ] == 'h' ) {
136+ // make cursor visible
137+ // not implemented yet
138+ } else if (i [4 ] == 'l' ) {
139+ // make cursor invisible
140+ // not implemented yet
141+ }
142+ }
143+ i += 5 ;
131144 } else {
132145 if (c == 'D' ) {
133146 if (n > self -> cursor_x ) {
@@ -153,8 +166,12 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
153166 common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
154167 }
155168 }
169+ if (c == 'H' ) {
170+ self -> cursor_x = self -> cursor_y = start_y = 0 ;
171+ }
156172 if (c == ';' ) {
157173 uint16_t m = 0 ;
174+ uint8_t m2 = 0 ;
158175 for (++ j ; j < 9 ; j ++ ) {
159176 if ('0' <= i [j ] && i [j ] <= '9' ) {
160177 m = m * 10 + (i [j ] - '0' );
@@ -163,6 +180,16 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
163180 break ;
164181 }
165182 }
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+ }
192+ }
166193 if (c == 'H' ) {
167194 if (n > 0 ) {
168195 n -- ;
@@ -196,11 +223,51 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
196223 common_hal_displayio_palette_set_color (terminal_palette , 0 , 0x000000 );
197224 common_hal_displayio_palette_set_color (terminal_palette , 1 , 0xffffff );
198225 }
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+ }
199233 }
200234 }
201- i += j + 1 ;
235+ i += j + j2 + 1 ;
202236 continue ;
203237 }
238+ } else if (i [0 ] == 'M' ) {
239+ if (self -> cursor_y != self -> scroll_area -> top_left_y ) {
240+ if (self -> cursor_y > 0 ) {
241+ self -> cursor_y = self -> cursor_y - 1 ;
242+ } else {
243+ self -> cursor_y = self -> scroll_area -> height_in_tiles - 1 ;
244+ }
245+ } else {
246+ if (self -> cursor_y > 0 ) {
247+ common_hal_displayio_tilegrid_set_top_left (self -> scroll_area , 0 , self -> cursor_y - 1 );
248+ } else {
249+ common_hal_displayio_tilegrid_set_top_left (self -> scroll_area , 0 , self -> scroll_area -> height_in_tiles - 1 );
250+ }
251+ for (uint8_t icol = 0 ; icol < self -> scroll_area -> width_in_tiles ; icol ++ ) {
252+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , icol , self -> scroll_area -> top_left_y , 0 );
253+ }
254+
255+ self -> cursor_x = 0 ;
256+ self -> cursor_y = self -> scroll_area -> top_left_y ;
257+ }
258+ start_y = self -> cursor_y ;
259+ i ++ ;
260+ } else if (i [0 ] == 'D' ) {
261+ self -> cursor_y = (self -> cursor_y + 1 ) % self -> scroll_area -> height_in_tiles ;
262+ if (self -> cursor_y == self -> scroll_area -> top_left_y ) {
263+ common_hal_displayio_tilegrid_set_top_left (self -> scroll_area , 0 , (self -> cursor_y + 1 ) % self -> scroll_area -> height_in_tiles );
264+ for (uint8_t icol = 0 ; icol < self -> scroll_area -> width_in_tiles ; icol ++ ) {
265+ common_hal_displayio_tilegrid_set_tile (self -> scroll_area , icol , self -> cursor_y , 0 );
266+ }
267+ self -> cursor_x = 0 ;
268+ }
269+ start_y = self -> cursor_y ;
270+ i ++ ;
204271 } else if (i [0 ] == ']' && c == ';' ) {
205272 self -> in_osc_command = true;
206273 self -> osc_command = n ;
0 commit comments