From c61eafbbf49cd8e7e4bfe623214ae86ad206d959 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 5 May 2021 05:09:48 -0400 Subject: [PATCH] [ncdirect] use '\v' for cursor down, not '\n' With '\v' (vertical tab), we don't need force raw mode. This saves us system calls, and makes the entire affair more reliable (no race between setting up termios and emitting '\n'; no chance for second tcsetattr to fail). Thanks once more to @dnkl on #1625. --- src/lib/direct.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/lib/direct.c b/src/lib/direct.c index f67aca344..b0677450d 100644 --- a/src/lib/direct.c +++ b/src/lib/direct.c @@ -140,36 +140,23 @@ int ncdirect_cursor_right(ncdirect* nc, int num){ } // if we're on the last line, we need some scrolling action. rather than -// merely using cud, we emit newlines in raw mode. this combination has -// the peculiar property of scrolling when necessary and not performing -// a carriage return -- a pure line feed. +// merely using cud, we emit vertical tabs. this has the peculiar property +// (in all terminals tested) of scrolling when necessary but performing no +// carriage return -- a pure line feed. int ncdirect_cursor_down(ncdirect* nc, int num){ - if(num < 0){ return -1; } if(num == 0){ return 0; } - struct termios term, raw; - if(tcgetattr(nc->ctermfd, &term)){ - return -1; - } - memcpy(&raw, &term, sizeof(raw)); - cfmakeraw(&raw); - if(tcsetattr(nc->ctermfd, TCSADRAIN, &raw)){ - return -1; - } int ret = 0; while(num--){ - if(ncfputc('\n', nc->ttyfp) == EOF){ + if(ncfputc('\v', nc->ttyfp) == EOF){ ret = -1; break; } } - if(tcsetattr(nc->ctermfd, TCSADRAIN, &term)){ - return -1; - } return ret; } @@ -483,7 +470,7 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){ // FIXME replace with a SGR clear ncdirect_set_fg_default(n); ncdirect_set_bg_default(n); - if(putc('\n', n->ttyfp) == EOF){ + if(ncfputc('\n', n->ttyfp) == EOF){ return -1; } if(y == toty){