summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-09-29 18:48:04 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-09-29 18:48:04 +0000
commit32f177038fe48ecf250dd688acadcf2bb954e218 (patch)
tree1ee2997d250869fc0e2008cf5914e9a46a464354
parent3d6c324405660fbfcbd255d78c89bf250723beb7 (diff)
Dl/Il should follow scrolling region.
-rw-r--r--input.c21
-rw-r--r--screen.c72
2 files changed, 82 insertions, 11 deletions
diff --git a/input.c b/input.c
index f2b38096..5b8ce90a 100644
--- a/input.c
+++ b/input.c
@@ -1,4 +1,4 @@
-/* $Id: input.c,v 1.12 2007-09-29 17:45:10 nicm Exp $ */
+/* $Id: input.c,v 1.13 2007-09-29 18:48:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -203,9 +203,6 @@ input_parse(struct input_ctx *ictx, u_char *buf, size_t len, struct buffer *b)
void *
input_state_first(u_char ch, enum input_class iclass, struct input_ctx *ictx)
{
- log_debug2("first (%hhu); sx=%u, sy=%u, cx=%u, cy=%u",
- ch, ictx->s->sx, ictx->s->sy, ictx->s->cx, ictx->s->cy);
-
switch (iclass) {
case INPUT_C0CONTROL:
if (ch == 0x1b)
@@ -493,8 +490,9 @@ input_handle_sequence(u_char ch, struct input_ctx *ictx)
u_int i;
struct input_arg *iarg;
- log_debug2("-- sq "
- "%zu: %hhu (%c): %u", ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args));
+ log_debug2("-- sq %zu: %hhu (%c): %u [sx=%u, sy=%u, cx=%u, cy=%u]",
+ ictx->off, ch, ch, ARRAY_LENGTH(&ictx->args),
+ ictx->s->sx, ictx->s->sy, ictx->s->cx, ictx->s->cy);
for (i = 0; i < ARRAY_LENGTH(&ictx->args); i++) {
iarg = &ARRAY_ITEM(&ictx->args, i);
if (*iarg->data != '\0')
@@ -640,7 +638,10 @@ input_handle_sequence_dl(struct input_ctx *ictx)
return;
}
- screen_delete_lines(ictx->s, ictx->s->cy, n);
+ if (n < ictx->s->ry_upper || n > ictx->s->ry_lower)
+ screen_delete_lines(ictx->s, ictx->s->cy, n);
+ else
+ screen_delete_lines_region(ictx->s, ictx->s->cy, n);
input_store_one(ictx->b, CODE_DELETELINE, n);
}
@@ -683,8 +684,10 @@ input_handle_sequence_il(struct input_ctx *ictx)
log_debug3("il: out of range: %hu", n);
return;
}
-
- screen_insert_lines(ictx->s, ictx->s->cy, n);
+ if (n < ictx->s->ry_upper || n > ictx->s->ry_lower)
+ screen_insert_lines(ictx->s, ictx->s->cy, n);
+ else
+ screen_insert_lines_region(ictx->s, ictx->s->cy, n);
input_store_one(ictx->b, CODE_INSERTLINE, n);
}
diff --git a/screen.c b/screen.c
index 10f08641..d1887b70 100644
--- a/screen.c
+++ b/screen.c
@@ -1,4 +1,4 @@
-/* $Id: screen.c,v 1.14 2007-09-29 18:07:18 nicm Exp $ */
+/* $Id: screen.c,v 1.15 2007-09-29 18:48:04 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -173,7 +173,7 @@ screen_draw(struct screen *s, struct buffer *b, u_int uy, u_int ly)
attr = 0;
colr = SCREEN_DEFCOLR;
- input_store_two(b, CODE_SCROLLREGION, 1, s->sy);
+ input_store_two(b, CODE_SCROLLREGION, s->ry_upper + 1, s->ry_lower + 1);
input_store_zero(b, CODE_CURSOROFF);
@@ -566,6 +566,40 @@ screen_insert_lines(struct screen *s, u_int py, u_int ny)
s, py, ny, SCREEN_DEFDATA, SCREEN_DEFATTR, SCREEN_DEFCOLR);
}
+/* Insert lines in region. */
+void
+screen_insert_lines_region(struct screen *s, u_int py, u_int ny)
+{
+ if (py < s->ry_upper || py > s->ry_lower)
+ return;
+ if (py + ny > s->ry_lower)
+ ny = s->ry_lower - py;
+ log_debug("inserting lines in region: %u,%u (%u,%u)", py, ny,
+ s->ry_upper, s->ry_lower);
+
+ /*
+ * Insert range of ny lines at py:
+ * - Free ny lines from end of screen.
+ * - Move from py to end of screen - ny to py + ny.
+ * - Create ny lines at py.
+ *
+ * Example: insert 2 lines at 4.
+ * ryu = 11, ryl = 16, py = 13, ny = 2
+ * screen_free_lines(s, 15, 2); - delete lines 15,16
+ * screen_move_lines(s, 13, 15, 2);- move 13,14 to 15,16
+ * screen_make_lines(s, 13, 2); - make lines 13,14
+ */
+
+ screen_free_lines(s, (s->ry_upper + 1) - ny, ny);
+
+ if (py != s->ry_upper)
+ screen_move_lines(s, py + ny, py, (s->ry_upper + 1) - py - ny);
+
+ screen_make_lines(s, py, ny);
+ screen_fill_lines(
+ s, py, ny, SCREEN_DEFDATA, SCREEN_DEFATTR, SCREEN_DEFCOLR);
+}
+
/* Delete lines. */
void
screen_delete_lines(struct screen *s, u_int py, u_int ny)
@@ -600,6 +634,40 @@ screen_delete_lines(struct screen *s, u_int py, u_int ny)
s, s->sy - ny, ny, SCREEN_DEFDATA, SCREEN_DEFATTR, SCREEN_DEFCOLR);
}
+/* Delete lines inside scroll region. */
+void
+screen_delete_lines_region(struct screen *s, u_int py, u_int ny)
+{
+ if (py < s->ry_upper || py > s->ry_lower)
+ return;
+ if (py + ny > s->ry_lower)
+ ny = s->ry_lower - py;
+ log_debug("deleting lines in region: %u,%u (%u,%u)", py, ny,
+ s->ry_upper, s->ry_lower);
+
+ /*
+ * Delete range of ny lines at py:
+ * - Free ny lines at py.
+ * - Move from py + ny to end of region to py.
+ * - Free and recreate last ny lines.
+ *
+ * Example: delete lines 13,14.
+ * ryu = 11, ryl = 16, py = 13, ny = 2
+ * screen_free_lines(s, 13, 2); - delete lines 13,14
+ * screen_move_lines(s, 15, 16, 2);- move 15,16 to 13
+ * screen_make_lines(s, 15, 16); - make lines 15,16
+ */
+
+ screen_free_lines(s, py, ny);
+
+ if (py != s->ry_lower)
+ screen_move_lines(s, py, py + ny, (s->ry_lower + 1) - py - ny);
+
+ screen_make_lines(s, (s->ry_lower + 1) - ny, ny);
+ screen_fill_lines(s, (s->ry_lower + 1) - ny,
+ ny, SCREEN_DEFDATA, SCREEN_DEFATTR, SCREEN_DEFCOLR);
+}
+
/* Insert characters. */
void
screen_insert_characters(struct screen *s, u_int px, u_int py, u_int nx)