1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-01 05:08:46 +00:00

Some code tidying, use macros in a few more places.

This commit is contained in:
Nicholas Marriott 2007-07-10 10:21:58 +00:00
parent 40ece59195
commit a3bfe208b3
2 changed files with 37 additions and 33 deletions

View File

@ -8,4 +8,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.2 2007-07-10 10:21:58 nicm Exp $

View File

@ -1,4 +1,4 @@
/* $Id: screen.c,v 1.1.1.1 2007-07-09 19:03:54 nicm Exp $ */ /* $Id: screen.c,v 1.2 2007-07-10 10:21:58 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -69,7 +69,7 @@ screen_create(struct screen *s, u_int sx, u_int sy)
s->cy = 0; s->cy = 0;
s->ry_upper = 0; s->ry_upper = 0;
s->ry_lower = sy - 1; s->ry_lower = screen_last_y(s);
s->attr = SCREEN_DEFATTR; s->attr = SCREEN_DEFATTR;
s->colr = SCREEN_DEFCOLR; s->colr = SCREEN_DEFCOLR;
@ -172,17 +172,15 @@ screen_resize(struct screen *s, u_int sx, u_int sy)
/* Draw a set of lines on the screen. */ /* Draw a set of lines on the screen. */
void void
screen_draw(struct screen *s, struct buffer *b, u_int py_upper, u_int py_lower) screen_draw(struct screen *s, struct buffer *b, u_int uy, u_int ly)
{ {
u_char attr, colr; u_char attr, colr;
size_t size; size_t size;
u_int i, j; u_int i, j;
uint16_t n; uint16_t n;
if (py_upper > s->sy || py_lower > s->sy || py_upper > py_lower) { if (uy > screen_last_y(s) || ly > screen_last_y(s) || ly < uy)
log_fatalx( log_fatalx("screen_draw_lines: bad range");
"screen_draw_lines: invalid, %u to %u", py_upper, py_lower);
}
/* XXX. This is naive and rough right now. */ /* XXX. This is naive and rough right now. */
attr = 0; attr = 0;
@ -192,10 +190,10 @@ screen_draw(struct screen *s, struct buffer *b, u_int py_upper, u_int py_lower)
input_store_one(b, CODE_ATTRIBUTES, 0); input_store_one(b, CODE_ATTRIBUTES, 0);
for (j = py_upper; j <= py_lower; j++) { for (j = uy; j <= ly; j++) {
input_store_two(b, CODE_CURSORMOVE, j + 1, 1); input_store_two(b, CODE_CURSORMOVE, j + 1, 1);
for (i = 0; i < s->sx; i++) { for (i = 0; i <= screen_last_x(s); i++) {
size = BUFFER_USED(b); size = BUFFER_USED(b);
input_store_one(b, CODE_ATTRIBUTES, 0); input_store_one(b, CODE_ATTRIBUTES, 0);
@ -327,11 +325,11 @@ screen_free_lines(struct screen *s, u_int uy, u_int ly)
for (i = uy; i <= ly; i++) { for (i = uy; i <= ly; i++) {
xfree(s->grid_data[i]); xfree(s->grid_data[i]);
s->grid_data[i] = (u_char *) 0xabcdabcd; s->grid_data[i] = (u_char *) 0xffffffff;
xfree(s->grid_attr[i]); xfree(s->grid_attr[i]);
s->grid_attr[i] = (u_char *) 0xabcdabcd; s->grid_attr[i] = (u_char *) 0xffffffff;
xfree(s->grid_colr[i]); xfree(s->grid_colr[i]);
s->grid_colr[i] = (u_char *) 0xabcdabcd; s->grid_colr[i] = (u_char *) 0xffffffff;
} }
} }
@ -343,12 +341,15 @@ screen_move_lines(struct screen *s, u_int dy, u_int uy, u_int ly)
log_debug("moving lines %u:%u to %u", uy, ly, dy); log_debug("moving lines %u:%u to %u", uy, ly, dy);
ny = (ly - uy) + 1;
if (uy > screen_last_y(s) || ly > screen_last_y(s) || ly < uy) if (uy > screen_last_y(s) || ly > screen_last_y(s) || ly < uy)
log_fatalx("screen_move_lines: bad range"); log_fatalx("screen_move_lines: bad range");
if (dy > screen_last_y(s)) if (dy > screen_last_y(s))
log_fatalx("screen_move_lines: bad destination"); log_fatalx("screen_move_lines: bad destination");
if (dy + ny - 1 > screen_last_y(s))
log_fatalx("screen_move_lines: bad destination");
ny = (ly - uy) + 1;
memmove( memmove(
s->grid_data + dy, s->grid_data + uy, ny * (sizeof *s->grid_data)); s->grid_data + dy, s->grid_data + uy, ny * (sizeof *s->grid_data));
memmove( memmove(
@ -423,8 +424,8 @@ screen_sequence(struct screen *s, u_char *ptr)
break; break;
case CODE_CURSORDOWN: case CODE_CURSORDOWN:
ua = screen_extract(ptr); ua = screen_extract(ptr);
if (s->cy + ua >= s->sy) if (s->cy + ua > screen_last_y(s))
ua = s->sy - 1 - s->cy; ua = screen_last_y(s) - s->cy;
s->cy += ua; s->cy += ua;
break; break;
case CODE_CURSORLEFT: case CODE_CURSORLEFT:
@ -435,8 +436,8 @@ screen_sequence(struct screen *s, u_char *ptr)
break; break;
case CODE_CURSORRIGHT: case CODE_CURSORRIGHT:
ua = screen_extract(ptr); ua = screen_extract(ptr);
if (s->cx + ua >= s->sx) if (s->cx + ua > screen_last_x(s))
ua = s->sx - 1 - s->cx; ua = screen_last_x(s) - s->cx;
s->cx += ua; s->cx += ua;
break; break;
case CODE_CURSORMOVE: case CODE_CURSORMOVE:
@ -624,7 +625,7 @@ screen_write_character(struct screen *s, u_char ch)
s->grid_colr[s->cy][s->cx] = s->colr; s->grid_colr[s->cy][s->cx] = s->colr;
s->cx++; s->cx++;
if (s->cx >= s->sx) { if (s->cx > screen_last_x(s)) {
s->cx = 0; s->cx = 0;
screen_cursor_down_scroll(s, 1); screen_cursor_down_scroll(s, 1);
} }
@ -645,9 +646,9 @@ screen_cursor_up_scroll(struct screen *s, u_int ny)
void void
screen_cursor_down_scroll(struct screen *s, u_int ny) screen_cursor_down_scroll(struct screen *s, u_int ny)
{ {
if (s->sy - 1 - s->cy < ny) { if (screen_last_y(s) - s->cy < ny) {
screen_scroll_up(s, ny - (s->sy - 1 - s->cy)); screen_scroll_up(s, ny - (screen_last_y(s) - s->cy));
s->cy = s->sy - 1; s->cy = screen_last_y(s);
} else } else
s->cy += ny; s->cy += ny;
} }
@ -656,7 +657,7 @@ screen_cursor_down_scroll(struct screen *s, u_int ny)
void void
screen_scroll_up(struct screen *s, u_int ny) screen_scroll_up(struct screen *s, u_int ny)
{ {
if (s->ry_upper == 0 && s->ry_lower == s->sy - 1) { if (s->ry_upper == 0 && s->ry_lower == screen_last_y(s)) {
screen_delete_lines(s, 0, ny); screen_delete_lines(s, 0, ny);
return; return;
} }
@ -668,7 +669,7 @@ screen_scroll_up(struct screen *s, u_int ny)
void void
screen_scroll_down(struct screen *s, u_int ny) screen_scroll_down(struct screen *s, u_int ny)
{ {
if (s->ry_upper == 0 && s->ry_lower == s->sy - 1) { if (s->ry_upper == 0 && s->ry_lower == screen_last_y(s)) {
screen_insert_lines(s, 0, ny); screen_insert_lines(s, 0, ny);
return; return;
} }
@ -696,17 +697,19 @@ void
screen_fill_end_of_screen( screen_fill_end_of_screen(
struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr) struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr)
{ {
if (py >= s->sy) if (py > screen_last_y(s))
return; return;
if (px != 0) { if (px != 0) {
screen_fill_end_of_line(s, px, py, data, attr, colr); screen_fill_end_of_line(s, px, py, data, attr, colr);
if (py++ >= s->sy) if (py++ > screen_last_y(s))
return; return;
} }
while (py++ < s->sy) while (py <= screen_last_y(s)) {
screen_fill_line(s, py - 1, data, attr, colr); screen_fill_line(s, py, data, attr, colr);
py++;
}
} }
/* Fill to end of line. */ /* Fill to end of line. */
@ -714,9 +717,9 @@ void
screen_fill_end_of_line( screen_fill_end_of_line(
struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr) struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr)
{ {
if (px >= s->sx) if (px > screen_last_x(s))
return; return;
if (py >= s->sy) if (py > screen_last_y(s))
return; return;
memset(s->grid_data[py] + px, data, s->sx - px); memset(s->grid_data[py] + px, data, s->sx - px);
@ -729,9 +732,9 @@ void
screen_fill_start_of_line( screen_fill_start_of_line(
struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr) struct screen *s, u_int px, u_int py, u_char data, u_char attr, u_char colr)
{ {
if (px >= s->sx) if (px > screen_last_x(s))
return; return;
if (py >= s->sy) if (py > screen_last_y(s))
return; return;
memset(s->grid_data[py], data, px); memset(s->grid_data[py], data, px);