-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Thank you for the buffering.
There's one thing I did with the code here!
Since it's intended to run on Linux only. I added extra functions.
void hide_caret() {
printf("\e[?25l");
}
void show_caret() {
printf("\e[?25h");
}
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
The funcitons hide_caret()
and show_caret()
area called before and after the while loop.
Also I added one function to detect keyboard pressing to exit the while
loop. It's annoying to press "Ctrl+C" to exit the TUI Screen saver!
The kbhit()
function requires the headers down below:
#include <termios.h>
#include <fcntl.h>
The kbhit()
can be changed to return the keycode. Let's say we want to exit if it's ESC.
Just one more thing! This single line functions could be replaced by a DEFINE directive!
But I got what I wanted, so...
Metadata
Metadata
Assignees
Labels
No labels