Code:
#include <curses.h>
void putch(WINDOW *scr, int x, int y, char c, attr_t a) {
mvwaddch(scr, y, x, c | a);
}
void putstr(WINDOW *scr, int x, int y, const char *c, int len, attr_t a) {
wmove(scr, y, x);
int index;
for (int index = 0; index < len; index++) {
char curc = c[index];
waddch(scr, curc | a);
}
}
void drawscr(WINDOW *scr) {
werase(scr);
int y = 1;
int x;
for (x = 1; x < (COLS - 1); x++) {
putch(scr, x, y, ' ', A_REVERSE);
}
x--;
for (y = y + 1; y < (LINES - 1); y++) {
putch(scr, x, y, ' ', A_REVERSE);
}
y--;
for (x = x - 1; x > 0; x--) {
putch(scr, x, y, ' ', A_REVERSE);
}
x++;
for (y = y - 1; y > 0; y--) {
putch(scr, x, y, ' ', A_REVERSE);
}
char str[] = "This is a string!";
putstr(scr, 10, 4, str, 17, A_BOLD);
putstr(scr, 10, 6, str, 17, A_REVERSE);
putstr(scr, 10, 8, str, 17, A_UNDERLINE);
mvwaddstr(scr, 10, 10, str);
putstr(scr, 10, 12, str, 17, A_REVERSE | A_BOLD);
putstr(scr, 10, 14, str, 17, A_BOLD | A_UNDERLINE);
}
int main() {
WINDOW *mainscr = initscr();
cbreak();
noecho();
keypad(mainscr, TRUE);
drawscr(mainscr);
refresh();
int in = ' ';
char buf[30];
while (in != 'q') {
in = wgetch(mainscr);
if (in == 126) { // ~ key (can't seem to get fn keys to work)
sprintf(buf, "%d x %d", COLS, LINES);
drawscr(mainscr);
mvwaddstr(mainscr, LINES-1, 0, buf);
}
refresh();
}
endwin();
return 0;
}