Reputation: 655
I'm teaching myself C (c17) and playing with ncurses.
I have written a function that clears the screen and draws a random number of colored period characters in random X, Y locations. (I've removed the color stuff in this code sample.)
I use curs_set(0) and 90-95% of the time this works correctly. Intermittently, though, the cursor remains visible.
I ssh to a Debian 11 server from both Windows 11 and a Mac Mini 2 and the problem is the same.
Any ideas?
Source that reproduces the problem:
#include <ncurses.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
initscr();
curs_set(0);
timeout(0);
nodelay(stdscr, TRUE);
start_color();
bkgd(COLOR_PAIR(0));
for (int i = 0; i < (rand() % (COLS * 2)) + COLS / 2; i++) {
char ch;
int x, y;
do {
y = rand() % LINES;
x = rand() % COLS;
ch = mvinch(y, x) & A_CHARTEXT;
} while (ch != ' ');
curs_set(0);
mvprintw(y, x, ".");
curs_set(0);
}
curs_set(0);
refresh();
curs_set(0);
struct timespec req = {2, 0};
int result = nanosleep(&req, NULL);
timeout(1);
nodelay(stdscr, FALSE);
clear();
endwin();
flushinp();
return 0;
}
Upvotes: 1
Views: 46