Skip to content

Instantly share code, notes, and snippets.

@wmcbrine

wmcbrine/Makefile

Forked from reagent/.gitignore
Last active May 14, 2020
Embed
What would you like to do?
Curses Windowing Example
#include <curses.h>
int main(int argc, char *argv[]) {
int parent_x, parent_y, new_x, new_y;
int score_size = 3;
int key = ERR;
initscr();
noecho();
curs_set(FALSE);
keypad(stdscr, TRUE);
// set up initial windows
getmaxyx(stdscr, parent_y, parent_x);
WINDOW *field = newwin(parent_y - score_size, parent_x, 0, 0);
WINDOW *score = newwin(score_size, parent_x, parent_y - score_size, 0);
box(field, 0, 0);
box(score, 0, 0);
while(key != 'q') {
if (key == KEY_RESIZE) {
#ifdef PDCURSES
resize_term(0, 0);
#endif
getmaxyx(stdscr, new_y, new_x);
if (new_y != parent_y || new_x != parent_x) {
parent_x = new_x;
parent_y = new_y;
wresize(field, new_y - score_size, new_x);
wresize(score, score_size, new_x);
mvwin(score, new_y - score_size, 0);
wclear(stdscr);
wclear(field);
wclear(score);
box(field, 0, 0);
box(score, 0, 0);
}
}
// draw to our windows
mvwprintw(field, 1, 1, "Field");
mvwprintw(score, 1, 1, "Score");
// refresh each window
wrefresh(stdscr);
wrefresh(field);
wrefresh(score);
key = getch();
}
endwin();
return 0;
}
CFLAGS=-Wall
LDFLAGS=-lcurses
all: demo
clean:
rm -rf demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.