aboutsummaryrefslogtreecommitdiffstats
path: root/src/ansi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansi.c')
-rw-r--r--src/ansi.c388
1 files changed, 191 insertions, 197 deletions
diff --git a/src/ansi.c b/src/ansi.c
index bcdc63e..39ad34d 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.44 2008/03/06 16:49:05 james
+ * *** empty log message ***
+ *
* Revision 1.43 2008/03/06 01:41:48 james
* *** empty log message ***
*
@@ -143,13 +146,14 @@ static char rcsid[] = "$Id$";
#include "project.h"
-static void
+static int
ansi_move (ANSI * a, CRT_Pos p)
{
char buf[16];
int n;
int dx = p.x - a->pos.x;
int dy = p.y - a->pos.y;
+ int err = 0;
// a->pos.x = ANSI_INVAL;
@@ -157,110 +161,131 @@ ansi_move (ANSI * a, CRT_Pos p)
{
if ((!dx) && (!dy))
- return;
+ return 0;
if (!dy)
{
if (dx == 1)
{
- a->terminal->xmit (a->terminal, "\033[C", 3);
+ if (a->terminal->xmit (a->terminal, "\033[C", 3) != 3)
+ err++;
}
else if (dx == -1)
{
- a->terminal->xmit (a->terminal, "\033[D", 3);
+ if (a->terminal->xmit (a->terminal, "\033[D", 3) != 3)
+ err++;
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
}
else if (!dx)
{
if (dy == -1)
{
- a->terminal->xmit (a->terminal, "\033[A", 3);
+ if (a->terminal->xmit (a->terminal, "\033[A", 3) != 3)
+ err++;
}
else if (dy == 1)
{
- a->terminal->xmit (a->terminal, "\033[B", 3);
+ if (a->terminal->xmit (a->terminal, "\033[B", 3) != 3)
+ err++;
}
else if (dy < 0)
{
n = snprintf (buf, sizeof (buf), "\033[%dA", -dy);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dB", dy);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
}
else if (!p.x)
{
if (dy == 1)
{
- a->terminal->xmit (a->terminal, "\033[E", 3);
+ if (a->terminal->xmit (a->terminal, "\033[E", 3) != 3)
+ err++;
}
else if (dy == -1)
{
- a->terminal->xmit (a->terminal, "\033[F", 3);
+ if (a->terminal->xmit (a->terminal, "\033[F", 3) != 3)
+ err++;
}
else if (dy > 0)
{
n = snprintf (buf, sizeof (buf), "\033[%dE", dy);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dF", -dy);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
- a->terminal->xmit (a->terminal, buf, n);
+ if (a->terminal->xmit (a->terminal, buf, n) != n)
+ err++;
}
a->pos = p;
+
+ return err;
}
-static void
+static int
ansi_showhide_cursor (ANSI * a, int hide)
{
+ int err = 0;
if (a->hide_cursor == hide)
- return;
+ return err;
if (hide)
{
- a->terminal->xmit (a->terminal, "\033[?25l", 6);
+ if (a->terminal->xmit (a->terminal, "\033[?25l", 6) != 6)
+ err++;
}
else
{
- a->terminal->xmit (a->terminal, "\033[?25h", 6);
+ if (a->terminal->xmit (a->terminal, "\033[?25h", 6) != 6)
+ err++;
}
a->hide_cursor = hide;
+ return err;
}
-static void
+static int
ansi_force_attr_normal (ANSI * a)
{
- a->terminal->xmit (a->terminal, "\033[0m", 4);
+ if (a->terminal->xmit (a->terminal, "\033[0m", 4) != 4)
+ return 1;
a->attr = CRT_ATTR_NORMAL;
a->color = ANSI_INVAL;
+ return 0;
}
-static void
+static int
ansi_set_color (ANSI * a, int color)
{
int dif;
@@ -268,48 +293,51 @@ ansi_set_color (ANSI * a, int color)
int i;
int fg, bg;
- if ((a->color == ANSI_INVAL) || (color != a->color))
- {
- fg = CRT_COLOR_FG (color);
- bg = CRT_COLOR_BG (color);
+ if ((a->color != ANSI_INVAL) && (color == a->color))
+ return 0;
+ fg = CRT_COLOR_FG (color);
+ bg = CRT_COLOR_BG (color);
- if (fg & CRT_COLOR_INTENSITY)
- {
- fg += 90;
- }
- else
- {
- fg += 30;
- }
+ if (fg & CRT_COLOR_INTENSITY)
+ {
+ fg += 90;
+ }
+ else
+ {
+ fg += 30;
+ }
- if (bg & CRT_COLOR_INTENSITY)
- {
- bg += 100;
- }
- else
- {
- bg += 40;
- }
+ if (bg & CRT_COLOR_INTENSITY)
+ {
+ bg += 100;
+ }
+ else
+ {
+ bg += 40;
+ }
- i = sprintf (buf, "\033[%d;%dm", fg, bg);
+ i = sprintf (buf, "\033[%d;%dm", fg, bg);
#if 0
- fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color);
+ fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color);
#endif
- a->terminal->xmit (a->terminal, buf, i);
- a->color = color;
- }
+ if (a->terminal->xmit (a->terminal, buf, i) != i)
+ return 1;
+ a->color = color;
+
+ return 0;
}
-static void
+static int
ansi_set_attr (ANSI * a, int attr)
{
int dif;
+ int err = 0;
dif = attr ^ a->attr;
if (!dif)
- return;
+ return 0;
a->attr = attr;
@@ -325,40 +353,48 @@ ansi_set_attr (ANSI * a, int attr)
{
if (attr & CRT_ATTR_UNDERLINE)
{
- a->terminal->xmit (a->terminal, "\033[4m", 4);
+ if (a->terminal->xmit (a->terminal, "\033[4m", 4))
+ err++;
}
else
{
- a->terminal->xmit (a->terminal, "\033[24m", 5);
+ if (a->terminal->xmit (a->terminal, "\033[24m", 5))
+ err++;
}
}
if (dif & CRT_ATTR_REVERSE)
{
if (attr & CRT_ATTR_REVERSE)
{
- a->terminal->xmit (a->terminal, "\033[7m", 4);
+ if (a->terminal->xmit (a->terminal, "\033[7m", 4))
+ err++;
}
else
{
- a->terminal->xmit (a->terminal, "\033[27m", 5);
+ if (a->terminal->xmit (a->terminal, "\033[27m", 5))
+ err++;
}
}
if (dif & CRT_ATTR_BOLD)
{
if (attr & CRT_ATTR_BOLD)
{
- a->terminal->xmit (a->terminal, "\033[1m", 4);
+ if (a->terminal->xmit (a->terminal, "\033[1m", 4))
+ err++;
}
else
{
- a->terminal->xmit (a->terminal, "\033[21m", 5);
- a->terminal->xmit (a->terminal, "\033[22m", 5);
+ if (a->terminal->xmit (a->terminal, "\033[21m", 5))
+ err++;
+ if (a->terminal->xmit (a->terminal, "\033[22m", 5))
+ err++;
}
}
+ return err;
}
-static void
+static int
ascii_emit (TTY * t, uint32_t ch)
{
int i;
@@ -382,8 +418,7 @@ ascii_emit (TTY * t, uint32_t ch)
if (ch < 0x7f)
{
uint8_t c = ch;
- t->xmit (t, &c, 1);
- return;
+ return (t->xmit (t, &c, 1) == 1) ? 0 : -1;
}
for (i = 0; i < VT102_CHARSET_SIZE; ++i)
@@ -391,18 +426,18 @@ ascii_emit (TTY * t, uint32_t ch)
if (vt102_charset_gl[i] == ch)
{
uint8_t c[3] = { 016, i, 017 };
- t->xmit (t, &c, 3);
- return;
+ return (t->xmit (t, &c, 3) == 3) ? 0 : -1;
}
}
- t->xmit (t, "?", 1);
+ return (t->xmit (t, "?", 1) == 1) ? 0 : -1;
}
-static void
+static int
ansi_render (ANSI * a, CRT_CA ca)
{
+ int err = 0;
int dif;
if ((ca.chr < VT102_CHARSET_SIZE) && (vt102_charset_c0[ca.chr]))
@@ -415,9 +450,15 @@ ansi_render (ANSI * a, CRT_CA ca)
ansi_set_color (a, ca.color);
if (a->utf8)
- utf8_emit (a->terminal, ca.chr);
+ {
+ if (utf8_emit (a->terminal, ca.chr))
+ err++;
+ }
else
- ascii_emit (a->terminal, ca.chr);
+ {
+ if (ascii_emit (a->terminal, ca.chr))
+ err++;
+ }
a->pos.x++;
@@ -427,111 +468,33 @@ ansi_render (ANSI * a, CRT_CA ca)
if (a->pos.x >= a->size.x)
a->pos.x = ANSI_INVAL;
+ return err;
}
-static void
+static int
ansi_cls (ANSI * a)
{
CRT_Pos p = { 0 };
+ int err;
crt_cls (&a->crt);
- ansi_set_attr (a, CRT_ATTR_NORMAL);
- ansi_set_color (a, CRT_COLOR_NORMAL);
- ansi_move (a, p);
- a->terminal->xmit (a->terminal, "\033[2J", 4);
+ err += ansi_set_attr (a, CRT_ATTR_NORMAL);
+ err += ansi_set_color (a, CRT_COLOR_NORMAL);
+ err += ansi_move (a, p);
+ if (a->terminal->xmit (a->terminal, "\033[2J", 4) != 4)
+ err++;
/*different emulators leave cursor in different places after cls differently*/
a->pos.x = ANSI_INVAL;
-}
-
-#if 0
-int
-ansi_scroll_up (ANSI * a, CRT_Pos s, CRT_Pos e)
-{
- char buf[16];
- int i;
- if (s.x)
- return -1;
- if (e.x != (CRT_COLS - 1))
- return -1;
- if (s.y)
- return -1;
- if (s.y >= a->size.y)
- return -1;
- ansi_showhide_cursor (a, 1);
- i = sprintf (buf, "\033[%d;%dr", s.y + 1, e.y + 1);
- a->terminal->xmit (a->terminal, buf, i);
- i = sprintf (buf, "\033[%d;%dH", e.y + 1, 0);
- a->terminal->xmit (a->terminal, buf, i);
- a->terminal->xmit (a->terminal, "\033D", 2);
- a->terminal->xmit (a->terminal, "\033[r", 3);
-
- s.y = e.y;
- crt_erase (&a->crt, s, e, 1);
-
- a->pos.x = ANSI_INVAL;
-
- return 0;
-}
-
-
-static void
-ansi_spot_scroll_up (ANSI * a, CRT * c)
-{
- int l, n, p;
-
- l = c->sh.e.x - c->sh.s.x;
- l++;
- l *= sizeof (CRT_CA);
-
- n = c->sh.e.y - c->sh.s.y;
- p = CRT_ADDR_POS (&c->sh.s);
-
- while (n--)
- {
- if (memcmp (&c->screen[p], &a->crt.screen[p + CRT_COLS], l))
- return;
- p += CRT_COLS;
- }
-
- if (ansi_scroll_up (a, c->sh.s, c->sh.e))
- return;
-
- n = c->sh.e.y - c->sh.s.y;
- p = CRT_ADDR_POS (&c->sh.s);
-
- while (n--)
- {
- memcpy (&a->crt.screen[p], &a->crt.screen[p + CRT_COLS], l);
- p += CRT_COLS;
- }
-
- c->sh.dir = 0; //FIXME: horrid hack
-
-}
-
-static void
-ansi_spot_scroll (ANSI * a, CRT * c)
-{
-
- switch (c->sh.dir)
- {
- case -1:
-/*we only care about up for the moment */
- ansi_spot_scroll_up (a, c);
- break;
- }
-
- return;
+ return err;
}
-#endif
-
-
-static void
+static int
ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
{
+ int err = 0;
+
CRT_Pos p = { 0, y };
CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)];
@@ -542,21 +505,25 @@ ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
if (crt_ca_cmp (*acap, *cap))
{
- ansi_showhide_cursor (a, 1);
+ err += ansi_showhide_cursor (a, 1);
+
*acap = *cap;
- ansi_move (a, p);
- ansi_render (a, *acap);
+ err += ansi_move (a, p);
+ err += ansi_render (a, *acap);
}
acap++;
cap++;
}
+
+ return err;
}
-static void
+static int
ansi_resize_check (ANSI * a, CRT_Pos * size)
{
+ int err = 0;
if ((size && crt_pos_cmp (a->crt.size, *size))
|| crt_pos_cmp (a->terminal->size, a->size))
@@ -580,48 +547,58 @@ ansi_resize_check (ANSI * a, CRT_Pos * size)
// maybe - issue 132 column command if we're 132?
ansi_cls (a);
- a->terminal->xmit (a->terminal, "\033=", 2);
- a->terminal->xmit (a->terminal, "\033[?6l", 5);
- a->terminal->xmit (a->terminal, "\033[r", 3);
+ if (a->terminal->xmit (a->terminal, "\033=", 2) != 2)
+ err++;
+ if (a->terminal->xmit (a->terminal, "\033[?6l", 5) != 5)
+ err++;
+ if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3)
+ err++;
if (a->utf8)
{
- a->terminal->xmit (a->terminal, "\033%G", 3);
+ if (a->terminal->xmit (a->terminal, "\033%G", 3) != 3)
+ err++;
}
else
{
- a->terminal->xmit (a->terminal, "\033(B", 3);
- a->terminal->xmit (a->terminal, "\033)0", 3);
- a->terminal->xmit (a->terminal, "\017", 1);
+ if (a->terminal->xmit (a->terminal, "\033(B", 3) != 3)
+ err++;
+ if (a->terminal->xmit (a->terminal, "\033)0", 3) != 3)
+ err++;
+ if (a->terminal->xmit (a->terminal, "\017", 1) != 3)
+ err++;
}
}
+ return err;
}
-/*if they haven't then ansi_draw will patch it up*/
-static void
+static int
ansi_history (ANSI * a, History * h)
{
char buf[32];
int i;
int guess_scroll;
+ int err = 0;
/*Do we need to catch up on history?*/
if (a->history_ptr == h->wptr)
- return;
- ansi_resize_check (a, NULL);
+ return err;
+
+ err += ansi_resize_check (a, NULL);
if ((a->size.x < a->crt.size.x) || (a->size.y < a->crt.size.y))
- return;
+ return err;
guess_scroll = a->crt.size.y - 1; /*Bototm line should be a status line */
- ansi_force_attr_normal (a);
- ansi_set_color (a, CRT_COLOR_NORMAL);
+ err += ansi_force_attr_normal (a);
+ err += ansi_set_color (a, CRT_COLOR_NORMAL);
i = sprintf (buf, "\033[%d;%dr", 1, guess_scroll);
- a->terminal->xmit (a->terminal, buf, i);
+ if (a->terminal->xmit (a->terminal, buf, i) != i)
+ err++;
while (a->history_ptr != h->wptr)
@@ -635,19 +612,24 @@ ansi_history (ANSI * a, History * h)
continue;
/*If so write the line ot the top of the screen */
- ansi_draw_line (a, e->line, 0);
+ err += ansi_draw_line (a, e->line, 0);
/*Roll guess_scroll lines up putting the top line into the xterm's history */
/*Make extra lines a predictable colour */
- ansi_set_color (a, CRT_COLOR_NORMAL);
+ err += ansi_set_color (a, CRT_COLOR_NORMAL);
+
+ err += ansi_showhide_cursor (a, 1);
- ansi_showhide_cursor (a, 1);
i = sprintf (buf, "\033[%d;%dH", guess_scroll, 1);
- a->terminal->xmit (a->terminal, buf, i);
- a->terminal->xmit (a->terminal, "\033D", 2);
+ if (a->terminal->xmit (a->terminal, buf, i) != i)
+ err++;
+
+ if (a->terminal->xmit (a->terminal, "\033D", 2) != 2)
+ err++;
+
a->pos.x = ANSI_INVAL;
/*now do the same in our image of the screen */
@@ -674,22 +656,26 @@ ansi_history (ANSI * a, History * h)
}
/*reset margins*/
- a->terminal->xmit (a->terminal, "\033[r", 3);
+ if (a->terminal->xmit (a->terminal, "\033[r", 3) != 3)
+ err++;
+
a->pos.x = ANSI_INVAL;
+ return err;
}
-static void
+static int
ansi_draw (ANSI * a, CRT * c)
{
CRT_Pos p;
int o;
int hidden_cursor = 0;
+ int err = 0;
- ansi_resize_check (a, &c->size);
+ err += ansi_resize_check (a, &c->size);
for (p.y = 0; p.y < a->crt.size.y; ++p.y)
@@ -697,7 +683,7 @@ ansi_draw (ANSI * a, CRT * c)
if (p.y >= a->size.y)
continue;
- ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y);
+ err += ansi_draw_line (a, &c->screen[CRT_ADDR (p.y, 0)], p.y);
}
@@ -713,34 +699,39 @@ ansi_draw (ANSI * a, CRT * c)
sprintf (msg, "Window too small (%dx%d need %dx%d)", a->size.x,
a->size.y, c->size.x, c->size.y);
- ansi_showhide_cursor (a, 1);
- ansi_set_attr (a, CRT_ATTR_REVERSE);
- ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED));
- ansi_move (a, p);
+ err += ansi_showhide_cursor (a, 1);
+ err += ansi_set_attr (a, CRT_ATTR_REVERSE);
+ err +=
+ ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED));
+ err += ansi_move (a, p);
+
+ if (a->terminal->xmit (a->terminal, msg, i) != i)
+ err++;
- a->terminal->xmit (a->terminal, msg, i);
a->pos.x = ANSI_INVAL;
}
if ((c->pos.x >= a->size.x) || (c->pos.y >= a->size.y))
{
- ansi_showhide_cursor (a, 1);
- return;
+ err += ansi_showhide_cursor (a, 1);
+ return err;
}
a->crt.pos = c->pos;
- ansi_move (a, a->crt.pos);
+ err += ansi_move (a, a->crt.pos);
a->crt.hide_cursor = c->hide_cursor;
- ansi_showhide_cursor (a, a->crt.hide_cursor);
+ err += ansi_showhide_cursor (a, a->crt.hide_cursor);
+
+ return err;
}
-static void
+static int
ansi_reset (ANSI * a, CRT * c)
{
a->size.x = -1;
- ansi_draw (a, c ? c : &a->crt);
+ return ansi_draw (a, c ? c : &a->crt);
}
static void
@@ -1004,12 +995,15 @@ ansi_dispatch (ANSI * a, Context * c)
}
-static void
+static int
ansi_update (ANSI * a, Context * c)
{
- ansi_history (a, c->h);
- ansi_draw (a, &c->v->crt);
+ int err = 0;
+
+ err += ansi_history (a, c->h);
+ err += ansi_draw (a, &c->v->crt);
tty_length (a->terminal, c->v->crt.size.y);
+ return err;
}
static void