4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.1 2008/02/03 23:31:25 james
14 * *** empty log message ***
19 ansi_write (ANSI * a, char *buf, int n)
21 write (a->fd, buf, n);
27 ansi_move (ANSI * a, CRT_Pos p)
31 int dx = a->pos.x - p.x;
32 int dy = a->pos.y - p.y;
35 if (a->pos.x != ANSI_INVAL)
45 ansi_write (a, "\033[C", 3);
49 ansi_write (a, "\033[D", 3);
53 n = snprintf (buf, sizeof (buf), "\033[%dG", p.x + 1);
54 ansi_write (a, buf, n);
61 ansi_write (a, "\033[A", 3);
65 ansi_write (a, "\033[B", 3);
69 n = snprintf (buf, sizeof (buf), "\033[%dA", -dy);
70 ansi_write (a, buf, n);
74 n = snprintf (buf, sizeof (buf), "\033[%dB", dy);
75 ansi_write (a, buf, n);
82 ansi_write (a, "\033[E", 3);
86 ansi_write (a, "\033[F", 3);
90 n = snprintf (buf, sizeof (buf), "\033[%dE", -dy);
91 ansi_write (a, buf, n);
95 n = snprintf (buf, sizeof (buf), "\033[%dF", dy);
96 ansi_write (a, buf, n);
101 n = snprintf (buf, sizeof (buf), "\033[%d;%dHF", p.y + 1, p.x + 1);
102 ansi_write (a, buf, n);
107 n = snprintf (buf, sizeof (buf), "\033[%d;%dHF", p.y + 1, p.x + 1);
108 ansi_write (a, buf, n);
116 ansi_showhide_cursor (ANSI * a, int hide)
118 if (a->hide_cursor == hide)
123 ansi_write (a, "\033[?25h", 6);
127 ansi_write (a, "\033[?25l", 6);
130 a->hide_cursor = hide;
134 void ansi_force_attr_normal(ANSI *a)
136 ansi_write (a, "\033[0m", 4);
137 a->attr=CRT_ATTR_NORMAL;
141 ansi_set_attr (ANSI * a, int attr)
144 dif = attr ^ a->attr;
149 if (attr == ATTR_NORMAL)
151 ansi_force_attr_normal(a);
155 if (dif & CRT_ATTR_UNDERLINE)
157 if (attr & CRT_ATTR_UNDERLINE)
159 ansi_write (a, "\033[4m", 4);
163 ansi_write (a, "\033[24m", 5);
166 if (dif & CRT_ATTR_REVERSE)
168 if (attr & CRT_ATTR_REVERSE)
170 ansi_write (a, "\033[7m", 4);
174 ansi_write (a, "\033[27m", 5);
177 if (dif & CRT_ATTR_BOLD)
179 if (attr & CRT_ATTR_REVERSE)
181 ansi_write (a, "\033[1m", 4);
185 ansi_write (a, "\033[22m", 5);
192 ansi_render (ANSI * a, CRT_CA ca)
201 ansi_set_attr (a, ca.attr);
203 ansi_write (a, &ca.chr, 1);
207 /*Can't easily wrap round here as don't know size of destination screen*/
208 /*so invalidate the cached cursor position*/
210 if (a->pos.x >= CRT_COLS)
211 a->pos.x = ANSI_INVAL;
221 ansi_force_attr_normal(a);
223 ansi_write (a, "\033[2J", 4);
224 /*different emulators leave cursor in different places after cls differently*/
225 a->pos.x = ANSI_INVAL;
230 ansi_draw (ANSI * a, CRT * c)
235 ansi_showhide_cursor (a, 1);
237 for (p.y = 0; p.y < CRT_ROWS; ++p.y)
239 if (p.y >= a->size.y)
242 for (p.x = 0; p.x < CRT_COLS; ++p.x, ++o)
244 if (p.x >= a->size.x)
246 if (crt_ca_cmp (a->crt.screen[p], c->screen[p]))
248 a->crt.screen[p] = c->screen[p];
251 ansi_render (a, a->crt.screen[p]);
257 ansi_move (a, a->crt.pos);
259 a->crt.hide_cursor = c->hide_cursor;
260 ansi_showhide_cursor (a, ci->crt.hide_cursor);
264 ansi_reset (ANSI * a)
266 ansi_write (a, "\033[c", 3);
268 a->pos.x = ANSI_INVAL;
269 a->hide_cursor = ANSI_INVAL;
274 ansi_draw (a, &a->crt);