aboutsummaryrefslogtreecommitdiffstats
path: root/src/ansi.c
diff options
context:
space:
mode:
authorjames <>2008-02-13 01:08:38 +0000
committerjames <>2008-02-13 01:08:38 +0000
commit4d50b220e63c52d412bacebb3e44cc712f2e2804 (patch)
tree57633a5a842ffa00f75ba96c19e653be3fb6bde6 /src/ansi.c
parent8688a9519c349b6ee8664be6ce2897a59c0f52be (diff)
downloadsympathy-4d50b220e63c52d412bacebb3e44cc712f2e2804.tar.gz
sympathy-4d50b220e63c52d412bacebb3e44cc712f2e2804.tar.bz2
sympathy-4d50b220e63c52d412bacebb3e44cc712f2e2804.zip
*** empty log message ***
Diffstat (limited to 'src/ansi.c')
-rw-r--r--src/ansi.c196
1 files changed, 80 insertions, 116 deletions
diff --git a/src/ansi.c b/src/ansi.c
index c501ab9..b6f30f9 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -10,6 +10,9 @@ static char rcsid[] = "$Id$";
/*
* $Log$
+ * Revision 1.17 2008/02/13 01:08:18 james
+ * *** empty log message ***
+ *
* Revision 1.16 2008/02/07 13:22:51 james
* *** empty log message ***
*
@@ -80,50 +83,6 @@ set_blocking (int fd)
}
-int
-ansi_read (ANSI * a, void *buf, int n)
-{
- int red;
-
- set_nonblocking (a->fd);
- red = read (a->fd, buf, n);
-
- if (!red)
- return -1;
-
- if ((red == -1) && (errno == EAGAIN))
- {
- return 0;
- }
-
- return red;
-}
-
-void
-ansi_write (ANSI * a, char *buf, int n)
-{
- set_blocking (a->fd);
- write (a->fd, buf, n);
-}
-
-void
-ansi_getsize (ANSI * a)
-{
- struct winsize sz = { 0 };
- if (ioctl (a->fd, TIOCGWINSZ, &sz))
- {
- a->size.x = CRT_COLS;
- a->size.y = CRT_ROWS;
- }
- else
- {
- a->size.x = sz.ws_col;
- a->size.y = sz.ws_row;
- }
-
-}
-
-
void
ansi_move (ANSI * a, CRT_Pos p)
{
@@ -144,70 +103,70 @@ ansi_move (ANSI * a, CRT_Pos p)
{
if (dx == 1)
{
- ansi_write (a, "\033[C", 3);
+ a->terminal->xmit (a->terminal, "\033[C", 3);
}
else if (dx == -1)
{
- ansi_write (a, "\033[D", 3);
+ a->terminal->xmit (a->terminal, "\033[D", 3);
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
}
else if (!dx)
{
if (dy == -1)
{
- ansi_write (a, "\033[A", 3);
+ a->terminal->xmit (a->terminal, "\033[A", 3);
}
else if (dy == 1)
{
- ansi_write (a, "\033[B", 3);
+ a->terminal->xmit (a->terminal, "\033[B", 3);
}
else if (dy < 0)
{
n = snprintf (buf, sizeof (buf), "\033[%dA", -dy);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dB", dy);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
}
else if (!p.x)
{
if (dy == 1)
{
- ansi_write (a, "\033[E", 3);
+ a->terminal->xmit (a->terminal, "\033[E", 3);
}
else if (dy == -1)
{
- ansi_write (a, "\033[F", 3);
+ a->terminal->xmit (a->terminal, "\033[F", 3);
}
else if (dy > 0)
{
n = snprintf (buf, sizeof (buf), "\033[%dE", dy);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%dF", -dy);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
}
else
{
n = snprintf (buf, sizeof (buf), "\033[%d;%dH", p.y + 1, p.x + 1);
- ansi_write (a, buf, n);
+ a->terminal->xmit (a->terminal, buf, n);
}
a->pos = p;
@@ -222,11 +181,11 @@ ansi_showhide_cursor (ANSI * a, int hide)
if (hide)
{
- ansi_write (a, "\033[?25l", 6);
+ a->terminal->xmit (a->terminal, "\033[?25l", 6);
}
else
{
- ansi_write (a, "\033[?25h", 6);
+ a->terminal->xmit (a->terminal, "\033[?25h", 6);
}
a->hide_cursor = hide;
@@ -236,7 +195,7 @@ ansi_showhide_cursor (ANSI * a, int hide)
void
ansi_force_attr_normal (ANSI * a)
{
- ansi_write (a, "\033[0m", 4);
+ a->terminal->xmit (a->terminal, "\033[0m", 4);
a->attr = CRT_ATTR_NORMAL;
a->color = ANSI_INVAL;
}
@@ -277,7 +236,7 @@ ansi_set_color (ANSI * a, int color)
fprintf (stderr, "Color set to %d %d %x\n", fg, bg, color);
#endif
- ansi_write (a, buf, i);
+ a->terminal->xmit (a->terminal, buf, i);
a->color = color;
}
}
@@ -306,34 +265,34 @@ ansi_set_attr (ANSI * a, int attr)
{
if (attr & CRT_ATTR_UNDERLINE)
{
- ansi_write (a, "\033[4m", 4);
+ a->terminal->xmit (a->terminal, "\033[4m", 4);
}
else
{
- ansi_write (a, "\033[24m", 5);
+ a->terminal->xmit (a->terminal, "\033[24m", 5);
}
}
if (dif & CRT_ATTR_REVERSE)
{
if (attr & CRT_ATTR_REVERSE)
{
- ansi_write (a, "\033[7m", 4);
+ a->terminal->xmit (a->terminal, "\033[7m", 4);
}
else
{
- ansi_write (a, "\033[27m", 5);
+ a->terminal->xmit (a->terminal, "\033[27m", 5);
}
}
if (dif & CRT_ATTR_BOLD)
{
if (attr & CRT_ATTR_BOLD)
{
- ansi_write (a, "\033[1m", 4);
+ a->terminal->xmit (a->terminal, "\033[1m", 4);
}
else
{
- ansi_write (a, "\033[21m", 5);
- ansi_write (a, "\033[22m", 5);
+ a->terminal->xmit (a->terminal, "\033[21m", 5);
+ a->terminal->xmit (a->terminal, "\033[22m", 5);
}
}
@@ -353,7 +312,7 @@ ansi_render (ANSI * a, CRT_CA ca)
ansi_set_attr (a, ca.attr);
ansi_set_color (a, ca.color);
- ansi_write (a, &ca.chr, 1);
+ a->terminal->xmit (a->terminal, &ca.chr, 1);
a->pos.x++;
@@ -375,11 +334,12 @@ ansi_cls (ANSI * a)
ansi_force_attr_normal (a);
ansi_set_color (a, CRT_COLOR_NORMAL);
ansi_move (a, p);
- ansi_write (a, "\033[2J", 4);
+ a->terminal->xmit (a->terminal, "\033[2J", 4);
/*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)
{
@@ -396,11 +356,11 @@ ansi_scroll_up (ANSI * a, CRT_Pos s, CRT_Pos e)
ansi_showhide_cursor (a, 1);
i = sprintf (buf, "\033[%d;%dr", s.y + 1, e.y + 1);
- ansi_write (a, buf, i);
+ a->terminal->xmit (a->terminal, buf, i);
i = sprintf (buf, "\033[%d;%dH", e.y + 1, 0);
- ansi_write (a, buf, i);
- ansi_write (a, "\033D", 2);
- ansi_write (a, "\033[r", 3);
+ 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);
@@ -461,7 +421,7 @@ ansi_spot_scroll (ANSI * a, CRT * c)
return;
}
-
+#endif
void
@@ -471,7 +431,8 @@ ansi_draw (ANSI * a, CRT * c)
int o;
int hidden_cursor = 0;
- ansi_spot_scroll (a, c);
+ if (crt_pos_cmp(a->terminal.size,a->size)) {
+
for (p.y = 0; p.y < CRT_ROWS; ++p.y)
{
@@ -505,7 +466,7 @@ ansi_draw (ANSI * a, CRT * c)
ansi_set_color (a, CRT_MAKE_COLOR (CRT_COLOR_WHITE, CRT_COLOR_RED));
ansi_move (a, p);
- ansi_write (a, msg, sizeof (msg));
+ a->terminal->xmit (a->terminal, msg, sizeof (msg));
a->pos.x = ANSI_INVAL;
}
@@ -527,8 +488,11 @@ void
ansi_reset (ANSI * a)
{
// FIXME: -- echos back crap?
-// ansi_write (a, "\033[c", 3);
- ansi_getsize (a);
+// a->terminal->xmit (a->terminal, "\033[c", 3);
+
+ terminal_getsize(a->terminal);
+
+ a->size=a->terminal->size;
a->pos.x = ANSI_INVAL;
a->hide_cursor = ANSI_INVAL;
@@ -536,21 +500,21 @@ ansi_reset (ANSI * a)
crt_reset (&a->crt);
ansi_cls (a);
- ansi_write (a, "\033=", 2);
- ansi_write (a, "\033[?6l", 5);
- ansi_write (a, "\033[r", 3);
+ a->terminal->xmit (a->terminal, "\033=", 2);
+ a->terminal->xmit (a->terminal, "\033[?6l", 5);
+ a->terminal->xmit (a->terminal, "\033[r", 3);
ansi_draw (a, &a->crt);
}
void
-ansi_flush_escape (ANSI * a, VT102 * v, TTY * t)
+ansi_flush_escape (ANSI * a, Context *c)
{
ANSI_Parser *p = &a->parser;
int i;
for (i = 0; i < p->escape_ptr; ++i)
{
- vt102_send (v, p->escape_buf[i], t);
+ vt102_send (c->v, p->escape_buf[i], c->t);
}
p->escape_ptr = 0;
@@ -558,26 +522,26 @@ ansi_flush_escape (ANSI * a, VT102 * v, TTY * t)
}
void
-ansi_parse_deckey (ANSI * a, VT102 * v, TTY * t)
+ansi_parse_deckey (ANSI * a, Context *c)
{
ANSI_Parser *p = &a->parser;
if ((p->escape_buf[1] != '[') && (p->escape_buf[1] != 'O'))
{
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a, c);
return;
}
if ((p->escape_buf[2] >= 'A') || (p->escape_buf[2] <= 'Z'))
{
- vt102_send (v, KEY_UP + (p->escape_buf[2] - 'A'), t);
+ vt102_send (c->v, KEY_UP + (p->escape_buf[2] - 'A'), c->t);
}
else if ((p->escape_buf[2] >= 'a') || (p->escape_buf[2] <= 'z'))
{
- vt102_send (v, KEY_154 + (p->escape_buf[2] - 'a'), t);
+ vt102_send (c->v, KEY_154 + (p->escape_buf[2] - 'a'), c->t);
}
else
{
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
return;
}
p->in_escape = 0;
@@ -585,22 +549,22 @@ ansi_parse_deckey (ANSI * a, VT102 * v, TTY * t)
}
void
-ansi_parse_ansikey (ANSI * a, VT102 * v, TTY * t)
+ansi_parse_ansikey (ANSI * a,Context *c)
{
ANSI_Parser *p = &a->parser;
if ((p->escape_buf[1] != '[') || (p->escape_buf[3] != '~'))
{
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a, c);
return;
}
if ((p->escape_buf[2] >= '0') || (p->escape_buf[2] <= '9'))
{
- vt102_send (v, KEY_180 + (p->escape_buf[2] - '0'), t);
+ vt102_send (c->v, KEY_180 + (p->escape_buf[2] - '0'), c->t);
}
else
{
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
return;
}
@@ -611,7 +575,7 @@ ansi_parse_ansikey (ANSI * a, VT102 * v, TTY * t)
void
-ansi_parse_escape (ANSI * a, VT102 * v, TTY * t)
+ansi_parse_escape (ANSI * a,Context *c)
{
ANSI_Parser *p = &a->parser;
switch (p->escape_ptr)
@@ -626,41 +590,41 @@ ansi_parse_escape (ANSI * a, VT102 * v, TTY * t)
case 'O':
break;
default:
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
}
break;
case 3:
switch (p->escape_buf[1])
{
case 'O':
- ansi_parse_deckey (a, v, t);
+ ansi_parse_deckey (a, c);
break;
case '[':
if ((p->escape_buf[2] >= 'A') && (p->escape_buf[2] <= 'Z'))
- ansi_parse_deckey (a, v, t);
+ ansi_parse_deckey (a,c);
break;
default:
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
}
break;
case 4:
switch (p->escape_buf[1])
{
case '[':
- ansi_parse_ansikey (a, v, t);
+ ansi_parse_ansikey (a, c);
break;
default:
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
}
break;
case 5:
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
}
}
void
-ansi_check_escape (ANSI * a, VT102 * v, TTY * t)
+ansi_check_escape (ANSI * a, Context *c)
{
ANSI_Parser *p = &a->parser;
struct timeval now, diff;
@@ -678,24 +642,24 @@ ansi_check_escape (ANSI * a, VT102 * v, TTY * t)
/*Time up? */
if (diff.tv_sec || (diff.tv_usec > ANSI_ESCAPE_TIMEOUT))
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
}
void
-ansi_parse_char (ANSI * a, int c, VT102 * v, TTY * t)
+ansi_parse_char (ANSI * a,Context *c, int ch)
{
ANSI_Parser *p = &a->parser;
/*See if it's time to flush the escape*/
- ansi_check_escape (a, v, t);
+ ansi_check_escape (a, c);
- if (c == 033)
+ if (ch == 033)
{
if (p->in_escape)
- ansi_flush_escape (a, v, t);
+ ansi_flush_escape (a,c);
p->in_escape++;
p->escape_ptr = 0;
@@ -704,33 +668,33 @@ ansi_parse_char (ANSI * a, int c, VT102 * v, TTY * t)
if (p->in_escape)
{
- p->escape_buf[p->escape_ptr++] = c;
- ansi_parse_escape (a, v, t);
+ p->escape_buf[p->escape_ptr++] = ch;
+ ansi_parse_escape (a,c);
}
else
{
- vt102_send (v, c, t);
+ vt102_send (c->v, ch, c->t);
}
}
void
-ansi_parse (ANSI * a, char *buf, int len, VT102 * v, TTY * t)
+ansi_parse (ANSI * a,Context *c, char *buf, int len)
{
while (len--)
- ansi_parse_char (a, *(buf++), v, t);
+ ansi_parse_char (a,c, *(buf++));
}
int
-ansi_dispatch (ANSI * a, VT102 * v, TTY * t)
+ansi_dispatch (ANSI * a, Context *c)
{
char buf[1024];
int red;
- ansi_check_escape (a, v, t);
+ ansi_check_escape (a, c);
- red = ansi_read (a, buf, sizeof (buf));
+ red = a->terminal->recv(a->terminal,buf,sizeof(buf));
if (red <= 0)
return red;
@@ -745,7 +709,7 @@ ansi_dispatch (ANSI * a, VT102 * v, TTY * t)
#endif
- ansi_parse (a, buf, red, v, t);
+ ansi_parse (a,c, buf, red );
return 0;
}