summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-10-13 15:38:38 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-10-13 15:38:38 +0000
commit75d1f0c8cf483aa77cd2bb722c41fe8dcf19f32e (patch)
tree337bbae1d31deb6e914e7d12f241b285f82e9bf7 /usr.bin
parent2aff57fa0b0da877f1ccfe59494580fa2e2c959d (diff)
Move lines into the history when scrolling even if the scroll region is not
the entire screen. Allows ircII users to see history, prompted by naddy.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/grid-view.c23
-rw-r--r--usr.bin/tmux/grid.c72
-rw-r--r--usr.bin/tmux/tmux.h6
3 files changed, 78 insertions, 23 deletions
diff --git a/usr.bin/tmux/grid-view.c b/usr.bin/tmux/grid-view.c
index 70aee107187..266ea69dee9 100644
--- a/usr.bin/tmux/grid-view.c
+++ b/usr.bin/tmux/grid-view.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid-view.c,v 1.6 2009/07/13 10:43:52 nicm Exp $ */
+/* $OpenBSD: grid-view.c,v 1.7 2009/10/13 15:38:37 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -92,15 +92,20 @@ grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
{
GRID_DEBUG(gd, "rupper=%u, rlower=%u", rupper, rlower);
- if (gd->flags & GRID_HISTORY && rupper == 0 && rlower == gd->sy - 1) {
- grid_scroll_line(gd);
- return;
+ if (gd->flags & GRID_HISTORY) {
+ grid_collect_history(gd);
+ if (rupper == 0 && rlower == gd->sy - 1)
+ grid_scroll_history(gd);
+ else {
+ rupper = grid_view_y(gd, rupper);
+ rlower = grid_view_y(gd, rlower);
+ grid_scroll_history_region(gd, rupper, rlower);
+ }
+ } else {
+ rupper = grid_view_y(gd, rupper);
+ rlower = grid_view_y(gd, rlower);
+ grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
}
-
- rupper = grid_view_y(gd, rupper);
- rlower = grid_view_y(gd, rlower);
-
- grid_move_lines(gd, rupper, rupper + 1, rlower - rupper);
}
/* Scroll region down. */
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index 0e6b00797e9..c021bf364f2 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.14 2009/09/15 15:14:09 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.15 2009/10/13 15:38:37 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -161,29 +161,77 @@ grid_compare(struct grid *ga, struct grid *gb)
return (0);
}
-/* Scroll a line into the history. */
+/*
+ * Collect lines from the history if at the limit. Free the top (oldest) 10%
+ * and shift up.
+ */
void
-grid_scroll_line(struct grid *gd)
+grid_collect_history(struct grid *gd)
{
u_int yy;
GRID_DEBUG(gd, "");
- if (gd->hsize >= gd->hlimit) {
- /* If the limit is hit, free the bottom 10% and shift up. */
- yy = gd->hlimit / 10;
- if (yy < 1)
- yy = 1;
+ if (gd->hsize < gd->hlimit)
+ return;
- grid_move_lines(gd, 0, yy, gd->hsize + gd->sy - yy);
- gd->hsize -= yy;
- }
+ yy = gd->hlimit / 10;
+ if (yy < 1)
+ yy = 1;
- yy = gd->hsize + gd->sy;
+ grid_move_lines(gd, 0, yy, gd->hsize + gd->sy - yy);
+ gd->hsize -= yy;
+}
+/*
+ * Scroll the entire visible screen, moving one line into the history. Just
+ * allocate a new line at the bottom and move the history size indicator.
+ */
+void
+grid_scroll_history(struct grid *gd)
+{
+ u_int yy;
+
+ GRID_DEBUG(gd, "");
+
+ yy = gd->hsize + gd->sy;
gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
memset(&gd->linedata[yy], 0, sizeof gd->linedata[yy]);
+
+ gd->hsize++;
+}
+
+/* Scroll a region up, moving the top line into the history. */
+void
+grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
+{
+ struct grid_line *gl_history, *gl_upper, *gl_lower;
+ u_int yy;
+
+ GRID_DEBUG(gd, "upper=%u, lower=%u", upper, lower);
+
+ /* Create a space for a new line. */
+ yy = gd->hsize + gd->sy;
+ gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+
+ /* Move the entire screen down to free a space for this line. */
+ gl_history = &gd->linedata[gd->hsize];
+ memmove(gl_history + 1, gl_history, gd->sy * sizeof *gl_history);
+
+ /* Adjust the region and find its start and end. */
+ upper++;
+ gl_upper = &gd->linedata[upper];
+ lower++;
+ gl_lower = &gd->linedata[lower];
+
+ /* Move the line into the history. */
+ memcpy(gl_history, gl_upper, sizeof *gl_history);
+
+ /* Then move the region up and clear the bottom line. */
+ memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper);
+ memset(gl_lower, 0, sizeof *gl_lower);
+ /* Move the history offset down over the line. */
gd->hsize++;
}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 3e29ace84be..78f018b0f91 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.138 2009/10/13 13:45:56 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.139 2009/10/13 15:38:37 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1592,9 +1592,11 @@ extern const struct grid_cell grid_default_cell;
struct grid *grid_create(u_int, u_int, u_int);
void grid_destroy(struct grid *);
int grid_compare(struct grid *, struct grid *);
+void grid_collect_history(struct grid *);
+void grid_scroll_history(struct grid *);
+void grid_scroll_history_region(struct grid *, u_int, u_int);
void grid_expand_line(struct grid *, u_int, u_int);
void grid_expand_line_utf8(struct grid *, u_int, u_int);
-void grid_scroll_line(struct grid *);
const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int);
struct grid_cell *grid_get_cell(struct grid *, u_int, u_int);
void grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);