/*
* $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 ***
*
}
-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)
{
{
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;
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;
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;
}
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;
}
}
{
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);
}
}
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++;
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)
{
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);
return;
}
-
+#endif
void
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)
{
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;
}
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;
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;
}
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;
}
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;
}
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)
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;
/*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;
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;
#endif
- ansi_parse (a, buf, red, v, t);
+ ansi_parse (a,c, buf, red );
return 0;
}