From 9bc11116890bf5f33d3a32d5efe97167fa8056ce Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 11 Jul 2019 17:37:31 -0400 Subject: Factor out clear --- bin/shotty.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'bin') diff --git a/bin/shotty.c b/bin/shotty.c index a70f40b8..e5f05bbf 100644 --- a/bin/shotty.c +++ b/bin/shotty.c @@ -58,6 +58,13 @@ static struct Cell *cell(uint y, uint x) { return &cells[y * cols + x]; } +static void clear(struct Cell *a, struct Cell *b) { + for (; a <= b; ++a) { + a->style = style; + a->ch = ' '; + } +} + static char updateNUL(wchar_t ch) { switch (ch) { case BS: if (x) x--; return NUL; @@ -156,24 +163,18 @@ static char updateCSI(wchar_t ch) { } break; case ED: { - struct Cell *from = cell(0, 0); - struct Cell *to = cell(rows - 1, cols - 1); - if (ps[0] == 0) from = cell(y, x); - if (ps[0] == 1) to = cell(y, x); - for (struct Cell *clear = from; clear <= to; ++clear) { - clear->style = style; - clear->ch = ' '; - } + struct Cell *a = cell(0, 0); + struct Cell *b = cell(rows - 1, cols - 1); + if (ps[0] == 0) a = cell(y, x); + if (ps[0] == 1) b = cell(y, x); + clear(a, b); } break; case EL: { - struct Cell *from = cell(y, 0); - struct Cell *to = cell(y, cols - 1); - if (ps[0] == 0) from = cell(y, x); - if (ps[0] == 1) to = cell(y, x); - for (struct Cell *clear = from; clear <= to; ++clear) { - clear->style = style; - clear->ch = ' '; - } + struct Cell *a = cell(y, 0); + struct Cell *b = cell(y, cols - 1); + if (ps[0] == 0) a = cell(y, x); + if (ps[0] == 1) b = cell(y, x); + clear(a, b); } break; case SM: // ignore @@ -287,10 +288,7 @@ int main(int argc, char *argv[]) { if (!cells) err(EX_OSERR, "calloc"); style = def; - for (uint i = 0; i < rows * cols; ++i) { - cells[i].style = style; - cells[i].ch = ' '; - } + clear(cell(0, 0), cell(rows - 1, cols - 1)); wint_t ch; while (WEOF != (ch = getwc(file))) { -- cgit 1.4.1 lect>
path: root/sshd_config (unfollow)
Commit message (Expand)Author
2019-02-22Fix name of <raw> window in man pageJune McEnroe
2019-02-22Rename global tags with angle bracketsJune McEnroe
2019-02-22Show status window while connectingJune McEnroe
2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe
2019-02-21Replace "view" with "window"June McEnroe
2019-02-21Remove ROT13June McEnroe
2019-02-21Clean up man pageJune McEnroe
2019-01-26Draw UI before connectingJune McEnroe
2019-01-25Avoid unused variable warnings with getyxJune McEnroe
2019-01-25Add GNU/Linux build instructionsJune McEnroe