Content-Length: 433008 | pFad | http://github.com/adafruit/circuitpython/commit/1f2e66f5086e19ee653a21bf7293afea924ce23e

CA Add support for VT100 terminal color ESC sequences · adafruit/circuitpython@1f2e66f · GitHub
Skip to content

Commit 1f2e66f

Browse files
committed
Add support for VT100 terminal color ESC sequences
1 parent 22e5a09 commit 1f2e66f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
//| * ``ESC [ #### D`` - Move the cursor to the left by ####
3434
//| * ``ESC [ 2 J`` - Erase the entire display
3535
//| * ``ESC [ nnnn ; mmmm H`` - Move the cursor to mmmm, nnnn.
36+
//| * ``ESC [ nn m`` - Set the terminal display attributes.
37+
//| * ``ESC [ nn ; nn m`` - Set the terminal display attributes.
38+
//|
39+
//| Supported Display attributes:
40+
//| 0 - Reset all attributes
41+
//| Foreground Colors Background Colors
42+
//| 30 - Black 40 - Black
43+
//| 31 - Red 41 - Red
44+
//| 32 - Green 42 - Green
45+
//| 33 - Yellow 43 - Yellow
46+
//| 34 - Blue 44 - Blue
47+
//| 35 - Magenta 45 - Magenta
48+
//| 36 - Cyan 46 - Cyan
49+
//| 37 - White 47 - White
3650
//| """
3751
//|
3852
//| def __init__(

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

+42
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "shared-module/fontio/BuiltinFont.h"
1010
#include "shared-bindings/displayio/TileGrid.h"
11+
#include "shared-bindings/displayio/Palette.h"
1112
#include "shared-bindings/terminalio/Terminal.h"
1213

1314
#if CIRCUITPY_STATUS_BAR
@@ -46,6 +47,22 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
4647
return len;
4748
}
4849

50+
uint32_t _select_color(uint16_t ascii_color) {
51+
uint32_t color_value = 0;
52+
if ((ascii_color & 1) > 0) {
53+
color_value += 0xff0000;
54+
}
55+
if ((ascii_color & 2) > 0) {
56+
color_value += 0x00ff00;
57+
}
58+
if ((ascii_color & 4) > 0) {
59+
color_value += 0x0000ff;
60+
}
61+
62+
return color_value;
63+
}
64+
65+
displayio_palette_t *terminal_palette = self->scroll_area->pixel_shader;
4966
const byte *i = data;
5067
uint16_t start_y = self->cursor_y;
5168
while (i < data + len) {
@@ -127,6 +144,15 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
127144
common_hal_displayio_tilegrid_set_all_tiles(self->scroll_area, 0);
128145
}
129146
}
147+
if (c == 'm') {
148+
if ((n >= 40 && n <= 47) || (n >= 30 && n <= 37)) {
149+
common_hal_displayio_palette_set_color(terminal_palette, 1 - (n / 40), _select_color(n % 10));
150+
}
151+
if (n == 0) {
152+
common_hal_displayio_palette_set_color(terminal_palette, 0, 0x000000);
153+
common_hal_displayio_palette_set_color(terminal_palette, 1, 0xffffff);
154+
}
155+
}
130156
if (c == ';') {
131157
uint16_t m = 0;
132158
for (++j; j < 9; j++) {
@@ -155,6 +181,22 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
155181
self->cursor_y = n;
156182
start_y = self->cursor_y;
157183
}
184+
if (c == 'm') {
185+
if ((n >= 40 && n <= 47) || (n >= 30 && n <= 37)) {
186+
common_hal_displayio_palette_set_color(terminal_palette, 1 - (n / 40), _select_color(n % 10));
187+
}
188+
if (n == 0) {
189+
common_hal_displayio_palette_set_color(terminal_palette, 0, 0x000000);
190+
common_hal_displayio_palette_set_color(terminal_palette, 1, 0xffffff);
191+
}
192+
if ((m >= 40 && m <= 47) || (m >= 30 && m <= 37)) {
193+
common_hal_displayio_palette_set_color(terminal_palette, 1 - (m / 40), _select_color(m % 10));
194+
}
195+
if (m == 0) {
196+
common_hal_displayio_palette_set_color(terminal_palette, 0, 0x000000);
197+
common_hal_displayio_palette_set_color(terminal_palette, 1, 0xffffff);
198+
}
199+
}
158200
}
159201
i += j + 1;
160202
continue;

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/1f2e66f5086e19ee653a21bf7293afea924ce23e

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy