From aff9ae62ef75f7db76d5a1031df296af2f6482e8 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 25 Aug 2020 03:10:47 -0400 Subject: [PATCH] cursor: always flush for immediate action --- src/lib/render.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/lib/render.c b/src/lib/render.c index b8a2d0425..698c5b399 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -1103,6 +1103,10 @@ int ncdirect_fg(ncdirect* nc, unsigned rgb){ } int notcurses_cursor_enable(notcurses* nc, int y, int x){ + if(nc->cursory >= 0 || nc->cursorx >= 0){ + logerror(nc, "Cursor is already enabled\n"); + return -1; + } if(y < 0 || x < 0){ logerror(nc, "Illegal cursor placement: %d, %d\n", y, x); return -1; @@ -1113,13 +1117,12 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){ } if(nc->ttyfd >= 0){ if(nc->tcache.cnorm){ - if(stage_cursor(nc, nc->ttyfp, y, x) || fflush(nc->ttyfp)){ - return -1; - } - nc->cursory = y; - nc->cursorx = x; - if(tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd) == 0){ - return 0; + if(stage_cursor(nc, nc->ttyfp, y, x) == 0){ + if(!tty_emit("cnorm", nc->tcache.cnorm, nc->ttyfd) && !fflush(nc->ttyfp)){ + nc->cursory = y; + nc->cursorx = x; + return 0; + } } } } @@ -1127,11 +1130,15 @@ int notcurses_cursor_enable(notcurses* nc, int y, int x){ } int notcurses_cursor_disable(notcurses* nc){ - nc->cursory = -1; - nc->cursorx = -1; + if(nc->cursorx < 0 || nc->cursory < 0){ + logerror(nc, "Cursor is not enabled"); + return -1; + } if(nc->ttyfd >= 0){ if(nc->tcache.civis){ - if(tty_emit("civis", nc->tcache.civis, nc->ttyfd) == 0){ + if(!tty_emit("civis", nc->tcache.civis, nc->ttyfd) && !fflush(nc->ttyfp)){ + nc->cursory = -1; + nc->cursorx = -1; return 0; } } @@ -1140,7 +1147,12 @@ int notcurses_cursor_disable(notcurses* nc){ } int notcurses_cursor_move_yx(notcurses* nc, int y, int x){ - if(nc->cursory >= 0 && nc->cursorx >= 0){ + if(nc->cursory < 0 || nc->cursorx < 0){ + logerror(nc, "Cursor is not enabled"); + return -1; + } + if(y < 0 || x < 0){ + logerror(nc, "Illegal cursor placement: %d, %d\n", y, x); return -1; } if(stage_cursor(nc, nc->ttyfp, y, x) || fflush(nc->ttyfp)){