Skip to content

Instantly share code, notes, and snippets.

@lesovsky
Created August 18, 2016 14:20
Show Gist options
  • Select an option

  • Save lesovsky/8340468011e181ef66bbf0070ad5b9ff to your computer and use it in GitHub Desktop.

Select an option

Save lesovsky/8340468011e181ef66bbf0070ad5b9ff to your computer and use it in GitHub Desktop.
Simple ncurses program with two windows.
#include <stdio.h>
#include <ncurses.h>
#include <limits.h> /* INT_MAX */
#include <unistd.h> /* sleep */
int main (void)
{
int i = 0;
WINDOW * w1, * w2;
initscr();
w1 = newwin(LINES / 2, COLS, 0, 0);
w2 = newwin(LINES / 2, COLS, (LINES / 2) + 1, 0);
while (1) {
wclear(w1);
wclear(w2);
if (++i == INT_MAX - 1) {
wprintw(w1, "counter overflow, restart it.");
i = 0;
continue;
}
wprintw(w1, "counter: %i (lines = %i, cols = %i)", i, LINES, COLS);
wprintw(w2, "shifted: %i", i + 666);
wrefresh(w1);
wrefresh(w2);
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment