summaryrefslogtreecommitdiff
path: root/term.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2006-10-29 08:07:51 +0000
committerRich Felker <dalias@aerifal.cx>2006-10-29 08:07:51 +0000
commit89fd3b76518cf3004053331c580a349afaaf2dab (patch)
tree61897409524c883266942c744ca58df69eb3970b /term.c
parentb97a486c34c343ab18bf16aef507478992af0625 (diff)
major internal changes in representation of character cells.
we now use 12 bytes per cell instead of 10. however, this allows us to support 256-color mode (not yet implemented but the framework is in place) and to mix scripts when using combining characters. while the latter sounds ridiculous at first, being able to visibly see a combining letter attached to a [, ", or ' is extremely useful in scripting and regular expressions with some languages. some code is left slightly messy, but overall it's much cleaner now since struct uucell is now properly encapsulated.
Diffstat (limited to 'term.c')
-rw-r--r--term.c61
1 files changed, 21 insertions, 40 deletions
diff --git a/term.c b/term.c
index 83a7c42..1bfc4c7 100644
--- a/term.c
+++ b/term.c
@@ -61,7 +61,8 @@ static void reset(struct uuterm *t)
{
/* cheap trick */
memset(&t->reset, 0, sizeof *t - offsetof(struct uuterm, reset));
- t->attr = 7;
+ t->attr = 0;
+ t->color = 7;
t->sr_y2 = t->h - 1;
erase_display(t, 2);
}
@@ -198,19 +199,30 @@ static void csi(struct uuterm *t, unsigned c)
if (t->param[i] == 39) t->param[i] = 37;
if (t->param[i] == 49) t->param[i] = 40;
if (!t->param[i]) {
- t->attr = 7;
+ t->attr = 0;
+ t->color = 7;
} else if (t->param[i] < 8) {
t->attr |= attr[t->param[i]-1];
} else if (t->param[i]-21 < 7) {
t->attr &= ~attr[t->param[i]-21];
} else if (t->param[i]-30 < 8) {
- t->attr &= ~UU_ATTR_FG;
- t->attr |= t->param[i] - 30;
+ t->color &= ~255;
+ t->color |= t->param[i] - 30;
} else if (t->param[i]-40 < 8) {
- t->attr &= ~UU_ATTR_BG;
- t->attr |= t->param[i] - 40 << 4;
+ t->color &= ~(255<<8);
+ t->color |= t->param[i] - 40 << 8;
}
}
+ if ((t->color&255) < 16)
+ if (t->attr & UU_ATTR_BOLD)
+ t->color |= 8;
+ else
+ t->color &= ~8;
+ if ((t->color>>8) < 16)
+ if (t->attr & UU_ATTR_BLINK)
+ t->color |= 8<<8;
+ else
+ t->color &= ~(8<<8);
break;
case 'n':
switch (t->param[0]) {
@@ -328,38 +340,6 @@ static void escape(struct uuterm *t, unsigned c)
}
}
-static void setchar(struct uucell *cell, unsigned c, unsigned a)
-{
- int i;
- if (a & UU_ATTR_REV)
- cell->a = (a & ~(0xff))
- | ((a & 0x0f) << 4)
- | ((a & 0xf0) >> 4);
- else
- cell->a = a;
- for (i=0; i<sizeof(cell->c); i++, c>>=8)
- cell->c[i] = c;
-}
-
-static void addchar(struct uucell *cell, unsigned c)
-{
- int i;
- unsigned b;
-
- for (i=b=0; i<3; i++) b |= cell->c[i] << 8*i;
- if (b == 0 || b == ' ' || b == 0xa0) {
- setchar(cell, c, cell->a);
- return;
- }
- if (!(c = uu_combine_involution(b, c))) return;
- for (; i<sizeof(cell->c); i++) {
- if (!cell->c[i]) {
- cell->c[i] = c;
- break;
- }
- }
-}
-
static void process_char(struct uuterm *t, unsigned c)
{
int x, y, w;
@@ -415,7 +395,7 @@ static void process_char(struct uuterm *t, unsigned c)
x = 0;
}
- addchar(&t->rows[y]->cells[x], c);
+ uucell_append(&t->rows[y]->cells[x], c);
dirty(t, y, x, 1);
break;
case 1:
@@ -424,7 +404,8 @@ static void process_char(struct uuterm *t, unsigned c)
while (w--) {
if (t->am) newline(t); // kills am flag
dirty(t, t->y, t->x, 1);
- setchar(&t->rows[t->y]->cells[t->x++], w?UU_FULLWIDTH:c, t->attr);
+ uucell_set(&t->rows[t->y]->cells[t->x++],
+ w?UU_FULLWIDTH:c, t->attr, t->color);
if (t->x == t->w) {
t->x--;
t->am=1;