77 lines
1.6 KiB
C
77 lines
1.6 KiB
C
#include <locale.h>
|
|
#include <unistd.h>
|
|
|
|
#include "curse.h"
|
|
|
|
#define BASE_DELAY 1000000
|
|
#define CRS_LOCALE "en_US.UTF-8"
|
|
|
|
/* Set ncurses terminal mode (buffering, character processing,
|
|
* Key->SIG handling, and other termios(3) functionality).
|
|
*/
|
|
inline int termmode(enum crs_mode mode) {
|
|
switch (mode) {
|
|
case WMODE_CBREAK:
|
|
return cbreak();
|
|
case WMODE_RAW:
|
|
return raw();
|
|
case WMODE_NOCBREAK:
|
|
return nocbreak();
|
|
case WMODE_NORAW:
|
|
return noraw();
|
|
/* defaulting is not possible. */
|
|
}
|
|
}
|
|
|
|
/* Initialise ncurses for our usecase.
|
|
* WARNING: This function should only be called once.
|
|
*/
|
|
inline void init_ncurses(void) {
|
|
// ncurses expects a locale for consistent behaviour
|
|
setlocale(LC_ALL, CRS_LOCALE);
|
|
|
|
/* NCurses Init */
|
|
*stdscr = initscr();
|
|
start_color();
|
|
|
|
/* Screen Configuration */
|
|
termmode(WMODE_CBREAK);
|
|
noecho(); // manually echo <- getch(3x)
|
|
nodelay(*stdscr, TRUE); // getch(3x) nonblocking IO
|
|
keypad(*stdscr, TRUE); // allow function keys
|
|
// intrflush(3x) - flush terminal input buffer on interrupt key
|
|
intrflush(*stdscr, FALSE);
|
|
|
|
curs_set(0); // hide cursor
|
|
|
|
// init_pair(1, COLOR_BLACK, COLOR_CYAN);
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
WINDOW *stdscr;
|
|
crs_init(&stdscr);
|
|
|
|
// Set background
|
|
wbkgd(stdscr, COLOR_PAIR(1));
|
|
|
|
attron(COLOR_PAIR(1));
|
|
attron(A_BOLD);
|
|
int counter = 0;
|
|
while (1) {
|
|
mvprintw(0, 0, "COUNTER %d", counter++);
|
|
refresh();
|
|
|
|
switch (getch()) {
|
|
case 'q':
|
|
goto end;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
usleep(BASE_DELAY);
|
|
}
|
|
|
|
end:
|
|
endwin();
|
|
return 0;
|
|
}
|