aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--display.c35
-rw-r--r--display.h3
-rw-r--r--term.h2
-rw-r--r--vt100.c55
4 files changed, 87 insertions, 8 deletions
diff --git a/display.c b/display.c
index 17d6b9f..30ed7a0 100644
--- a/display.c
+++ b/display.c
@@ -7,9 +7,14 @@ void runes_display_init(RunesTerm *t)
cairo_font_face_t *font_face;
cairo_matrix_t font_matrix, ctm;
- t->bgcolor = cairo_pattern_create_rgb(1.0, 1.0, 1.0);
- t->fgcolor = cairo_pattern_create_rgb(0.0, 0.0, 1.0);
- t->cursorcolor = cairo_pattern_create_rgb(0.0, 1.0, 0.0);
+ t->colors[0] = cairo_pattern_create_rgb(0.0, 0.0, 0.0);
+ t->colors[1] = cairo_pattern_create_rgb(1.0, 0.0, 0.0);
+ t->colors[2] = cairo_pattern_create_rgb(0.0, 1.0, 0.0);
+ t->colors[3] = cairo_pattern_create_rgb(1.0, 1.0, 0.0);
+ t->colors[4] = cairo_pattern_create_rgb(0.0, 0.0, 1.0);
+ t->colors[5] = cairo_pattern_create_rgb(1.0, 0.0, 1.0);
+ t->colors[6] = cairo_pattern_create_rgb(1.0, 1.0, 1.0);
+ t->colors[7] = cairo_pattern_create_rgb(1.0, 1.0, 1.0);
font_face = cairo_toy_font_face_create("monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_matrix_init_scale(&font_matrix, 14.0, 14.0);
@@ -18,10 +23,13 @@ void runes_display_init(RunesTerm *t)
cairo_set_scaled_font(t->cr, t->font);
+ runes_display_reset_text_attributes(t);
+ t->cursorcolor = cairo_pattern_create_rgb(0.0, 1.0, 0.0);
+
+ cairo_save(t->cr);
cairo_set_source(t->cr, t->bgcolor);
cairo_paint(t->cr);
-
- cairo_set_source(t->cr, t->fgcolor);
+ cairo_restore(t->cr);
runes_display_move_to(t, 0, 0);
@@ -133,3 +141,20 @@ void runes_display_kill_line_forward(RunesTerm *t)
runes_display_move_to(t, t->row, t->col);
}
+
+void runes_display_reset_text_attributes(RunesTerm *t)
+{
+ runes_display_set_fg_color(t, t->colors[7]);
+ runes_display_set_bg_color(t, t->colors[0]);
+}
+
+void runes_display_set_fg_color(RunesTerm *t, cairo_pattern_t *color)
+{
+ t->fgcolor = color;
+ cairo_set_source(t->cr, t->fgcolor);
+}
+
+void runes_display_set_bg_color(RunesTerm *t, cairo_pattern_t *color)
+{
+ t->bgcolor = color;
+}
diff --git a/display.h b/display.h
index 0a6979a..d597542 100644
--- a/display.h
+++ b/display.h
@@ -9,5 +9,8 @@ void runes_display_move_to(RunesTerm *t, int row, int col);
void runes_display_show_string(RunesTerm *t, char *buf, size_t len);
void runes_display_backspace(RunesTerm *t);
void runes_display_kill_line_forward(RunesTerm *t);
+void runes_display_reset_text_attributes(RunesTerm *t);
+void runes_display_set_fg_color(RunesTerm *t, cairo_pattern_t *color);
+void runes_display_set_bg_color(RunesTerm *t, cairo_pattern_t *color);
#endif
diff --git a/term.h b/term.h
index fb3d1e0..e32cf55 100644
--- a/term.h
+++ b/term.h
@@ -14,6 +14,8 @@ struct runes_term {
cairo_pattern_t *cursorcolor;
cairo_scaled_font_t *font;
+ cairo_pattern_t *colors[8];
+
int row;
int col;
};
diff --git a/vt100.c b/vt100.c
index 087a212..445756f 100644
--- a/vt100.c
+++ b/vt100.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include <string.h>
#include "runes.h"
@@ -16,8 +17,27 @@ static char *runes_vt100_handle_escape_sequence(RunesTerm *t, char *buf, size_t
UNUSED(len);
if (buf[1] == '[') { /* CSI */
- /* ignoring parameters, for now */
- switch (buf[2]) {
+ int p[3] = { -1, -1, -1 };
+ int paramlen;
+ char type;
+
+ buf += 2;
+
+ /* XXX stop hardcoding the max number of parameters */
+ if (sscanf(buf, "%d;%d;%d%c%n", &p[0], &p[1], &p[2], &type, &paramlen) == 4) {
+ /* nothing */
+ }
+ else if (sscanf(buf, "%d;%d%c%n", &p[0], &p[1], &type, &paramlen) == 3) {
+ /* nothing */
+ }
+ else if (sscanf(buf, "%d%c%n", &p[0], &type, &paramlen) == 2) {
+ /* nothing */
+ }
+ else if (sscanf(buf, "%c%n", &type, &paramlen) == 1) {
+ /* nothing */
+ }
+
+ switch (type) {
case 'D': { /* CUB */
int row, col;
@@ -49,11 +69,40 @@ static char *runes_vt100_handle_escape_sequence(RunesTerm *t, char *buf, size_t
case 'K': /* EL */
runes_display_kill_line_forward(t);
break;
+ case 'm': {
+ int i;
+
+ if (p[0] == -1) {
+ p[0] = 0;
+ }
+
+ for (i = 0; i < 3; ++i) {
+ switch (p[i]) {
+ case -1:
+ break;
+ case 0:
+ runes_display_reset_text_attributes(t);
+ break;
+ case 30: case 31: case 32: case 33:
+ case 34: case 35: case 36: case 37:
+ runes_display_set_fg_color(t, t->colors[p[i] - 30]);
+ break;
+ case 40: case 41: case 42: case 43:
+ case 44: case 45: case 46: case 47:
+ runes_display_set_bg_color(t, t->colors[p[i] - 40]);
+ break;
+ /* XXX ... */
+ default:
+ break;
+ }
+ }
+ break;
+ }
default:
break;
}
- buf += 3;
+ buf += paramlen;
}
else {
/* do nothing, for now */