+ 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;
+}
+
+#endif
+
+
+static void
+ansi_draw_line (ANSI * a, CRT_CA * cap, int y)
+{
+ CRT_Pos p = { 0, y };
+ CRT_CA *acap = &a->crt.screen[CRT_ADDR_POS (&p)];
+
+ for (p.x = 0; p.x < a->crt.size.x; ++p.x)
+ {
+ if (p.x >= a->size.x)
+ continue;
+
+ if (crt_ca_cmp (*acap, *cap))
+ {
+ ansi_showhide_cursor (a, 1);
+ *acap = *cap;
+
+ ansi_move (a, p);
+ ansi_render (a, *acap);
+ }
+
+ acap++;
+ cap++;
+ }
+}
+
+static void
+ansi_resize_check (ANSI * a, CRT_Pos * size)
+{
+
+ if ((size && crt_pos_cmp (a->crt.size, *size))
+ || crt_pos_cmp (a->terminal->size, a->size))
+ {
+
+ terminal_getsize (a->terminal);
+
+ a->size = a->terminal->size;
+
+ a->pos.x = ANSI_INVAL;
+ a->hide_cursor = ANSI_INVAL;
+
+ crt_reset (&a->crt);
+
+ if (size)
+ a->crt.size = *size;
+
+// FIXME: -- echos back crap?
+// a->terminal->xmit (a->terminal, "\033[c", 3);
+
+// 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->utf8)
+ {
+ a->terminal->xmit (a->terminal, "\033%G", 3);
+ }
+ 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 they haven't then ansi_draw will patch it up*/
+
+static void
+ansi_history (ANSI * a, History * h)
+{
+ char buf[32];
+ int i;
+ int guess_scroll;
+/*Do we need to catch up on history?*/
+
+ if (a->history_ptr == h->wptr)
+ return;
+ ansi_resize_check (a, NULL);
+
+ if ((a->size.x < a->crt.size.x) || (a->size.y < a->crt.size.y))
+ return;
+
+ 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);
+
+ i = sprintf (buf, "\033[%d;%dr", 1, guess_scroll);
+ a->terminal->xmit (a->terminal, buf, i);
+
+
+ while (a->history_ptr != h->wptr)
+ {
+
+ History_ent *e = &h->lines[a->history_ptr];
+
+ HISTORY_INC (h, a->history_ptr);
+
+ if (!e->valid)
+ continue;
+
+ /*If so write the line ot the top of the screen */
+ 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);
+
+ 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);
+ a->pos.x = ANSI_INVAL;
+
+ /*now do the same in our image of the screen */
+
+ {
+ CRT_Pos s = { 0 }
+ , e =
+ {
+ 0};
+
+ /*scroll lines up */
+ for (s.y++; s.y < guess_scroll; s.y++, e.y++)
+ {
+ memcpy (&a->crt.screen[CRT_ADDR_POS (&e)],
+ &a->crt.screen[CRT_ADDR_POS (&s)],
+ sizeof (CRT_CA) * a->crt.size.x);
+ }
+
+ /* erase new line */
+ s.y = e.y;
+ e.x = CRT_COLS - 1;
+ crt_erase (&a->crt, s, e, 1, CRT_COLOR_NORMAL);
+ }
+
+ }
+/*reset margins*/
+ a->terminal->xmit (a->terminal, "\033[r", 3);
+ a->pos.x = ANSI_INVAL;
+
+}
+
+
+
+
+static void