From: John Tsiombikas Date: Mon, 25 Nov 2019 18:35:06 +0000 (+0200) Subject: don't crash with no buffers, and clear the screen on exit X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;ds=inline;h=c17213b9500cfb26ba0d85b1a63c9aeb56981748;hp=8bf8b3066f32093ee83cb52e720002ea7dc94250;p=visor don't crash with no buffers, and clear the screen on exit --- diff --git a/libvisor/src/visor.c b/libvisor/src/visor.c index 2c93521..84ffd95 100644 --- a/libvisor/src/visor.c +++ b/libvisor/src/visor.c @@ -100,13 +100,15 @@ void vi_term_size(struct visor *vi, int xsz, int ysz) void vi_redraw(struct visor *vi) { - int i, col, cur_x = 0, cur_y = 0; + int i = 0, col, cur_x = 0, cur_y = 0; char c; struct vi_buffer *vb; struct vi_span *sp, *spans_end; const char *tptr, *tend; vi_addr spoffs, addr; + if(!vi->buflist) goto end; + vb = vi->buflist; if(!(sp = vi_buf_find_span(vb, vb->view_start, &spoffs))) { sp = vb->spans; diff --git a/visor/src/term.c b/visor/src/term.c index af7d278..4746836 100644 --- a/visor/src/term.c +++ b/visor/src/term.c @@ -56,11 +56,20 @@ int term_init(const char *ttypath) void term_cleanup(void) { + term_clear(); + term_setcursor(0, 0); + term_flush(); tcsetattr(ttyfd, TCSAFLUSH, &saved_term); close(ttyfd); ttyfd = -1; } +void term_reset(void) +{ + term_puts("\033c"); + term_flush(); +} + void term_getsize(int *width, int *height) { *width = term_width; diff --git a/visor/src/term.h b/visor/src/term.h index c1ce67d..fbf0558 100644 --- a/visor/src/term.h +++ b/visor/src/term.h @@ -36,6 +36,7 @@ union term_event { int term_init(const char *ttypath); void term_cleanup(void); +void term_reset(void); void term_getsize(int *width, int *height); void term_resize_func(void (*func)(int, int));