Content-Length: 840529 | pFad | http://github.com/adafruit/circuitpython/commit/0501a8e78f6fbc31f483b0865b17dcff551fc570

24 fix for sequence params and compile flag (not enabled yet) · adafruit/circuitpython@0501a8e · GitHub
Skip to content

Commit 0501a8e

Browse files
committed
fix for sequence params and compile flag (not enabled yet)
1 parent bc96ce8 commit 0501a8e

File tree

4 files changed

+96
-77
lines changed

4 files changed

+96
-77
lines changed

Diff for: ports/atmel-samd/mpconfigport.mk

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ CIRCUITPY_ZLIB = 0
5959

6060
# Turn off a few more things that don't fit in 192kB
6161

62+
CIRCUITPY_TERMINALIO_VT100 = 0
63+
6264
ifeq ($(INTERNAL_FLASH_FILESYSTEM),1)
6365
CIRCUITPY_ONEWIREIO ?= 0
6466
CIRCUITPY_SAFEMODE_PY ?= 0

Diff for: py/circuitpy_mpconfig.mk

+3
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ CFLAGS += -DCIRCUITPY_SYS=$(CIRCUITPY_SYS)
552552
CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO)
553553
CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO)
554554

555+
CIRCUITPY_TERMINALIO_VT100 ?= $(CIRCUITPY_TERMINALIO)
556+
CFLAGS += -DCIRCUITPY_TERMINALIO_VT100=$(CIRCUITPY_TERMINALIO_VT100)
557+
555558
CIRCUITPY_FONTIO ?= $(call enable-if-all,$(CIRCUITPY_DISPLAYIO) $(CIRCUITPY_TERMINALIO))
556559
CFLAGS += -DCIRCUITPY_FONTIO=$(CIRCUITPY_FONTIO)
557560

Diff for: shared-bindings/terminalio/Terminal.c

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
//|
3131
//| VT100 control sequences:
3232
//| * ``ESC [ K`` - Clear the remainder of the line
33+
//| * ``ESC [ 0 K`` - Clear the remainder of the line
34+
//| * ``ESC [ 1 K`` - Clear start of the line to cursor
35+
//| * ``ESC [ 2 K`` - Clear the entire line
3336
//| * ``ESC [ #### D`` - Move the cursor to the left by ####
3437
//| * ``ESC [ 2 J`` - Erase the entire display
3538
//| * ``ESC [ nnnn ; mmmm H`` - Move the cursor to mmmm, nnnn.

Diff for: shared-module/terminalio/Terminal.c

+88-77
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
4747
return len;
4848
}
4949

50+
#if CIRCUITPY_TERMINALIO_VT100
5051
uint32_t _select_color(uint16_t ascii_color) {
5152
uint32_t color_value = 0;
5253
if ((ascii_color & 1) > 0) {
@@ -63,6 +64,8 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
6364
}
6465

6566
displayio_palette_t *terminal_palette = self->scroll_area->pixel_shader;
67+
#endif
68+
6669
const byte *i = data;
6770
uint16_t start_y = self->cursor_y;
6871
while (i < data + len) {
@@ -113,7 +116,6 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
113116
// Handle commands of the form [ESC].<digits><command-char> where . is not yet known.
114117
uint16_t n = 0;
115118
uint8_t j = 1;
116-
uint8_t j2 = 0;
117119
for (; j < 6; j++) {
118120
if ('0' <= i[j] && i[j] <= '9') {
119121
n = n * 10 + (i[j] - '0');
@@ -123,13 +125,34 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
123125
}
124126
}
125127
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+
}
130151
}
131-
i += 2;
132-
} else if (i[1] == '?') {
152+
}
153+
#endif
154+
if (c == '?') {
155+
#if CIRCUITPY_TERMINALIO_VT100
133156
if (i[2] == '2' && i[3] == '5') {
134157
// cursor visibility commands
135158
if (i[4] == 'h') {
@@ -141,100 +164,87 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
141164
}
142165
}
143166
i += 5;
167+
#endif
144168
} 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') {
146189
if (n > self->cursor_x) {
147190
self->cursor_x = 0;
148191
} else {
149192
self->cursor_x -= n;
150193
}
151-
}
152-
if (c == 'J') {
194+
} else if (c == 'J') {
153195
if (n == 2) {
154196
common_hal_displayio_tilegrid_set_top_left(self->scroll_area, 0, 0);
155197
self->cursor_x = self->cursor_y = start_y = 0;
156-
n = 0;
157198
common_hal_displayio_tilegrid_set_all_tiles(self->scroll_area, 0);
158199
}
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') {
161222
if ((n >= 40 && n <= 47) || (n >= 30 && n <= 37)) {
162223
common_hal_displayio_palette_set_color(terminal_palette, 1 - (n / 40), _select_color(n % 10));
163224
}
164225
if (n == 0) {
165226
common_hal_displayio_palette_set_color(terminal_palette, 0, 0x000000);
166227
common_hal_displayio_palette_set_color(terminal_palette, 1, 0xffffff);
167228
}
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));
182231
}
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);
192235
}
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));
210238
}
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);
233242
}
243+
#endif
234244
}
235-
i += j + j2 + 1;
236-
continue;
245+
i += j + 1;
237246
}
247+
#if CIRCUITPY_TERMINALIO_VT100
238248
} else if (i[0] == 'M') {
239249
if (self->cursor_y != self->scroll_area->top_left_y) {
240250
if (self->cursor_y > 0) {
@@ -268,6 +278,7 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
268278
}
269279
start_y = self->cursor_y;
270280
i++;
281+
#endif
271282
} else if (i[0] == ']' && c == ';') {
272283
self->in_osc_command = true;
273284
self->osc_command = n;

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/adafruit/circuitpython/commit/0501a8e78f6fbc31f483b0865b17dcff551fc570

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy