Originally Posted by
PedroTuga
curses like libraries, that, if I understand it correctly, are more like a widget library than a canvas so to speak.
They do include the "canvas" level, too. For example, save the following as example.c,
Code:
#include <curses.h>
#include <string.h>
int main(void)
{
static const char msg[] = "Press Q to Quit";
int c;
/* Start curses. Also sets LINES and COLS. */
initscr();
/* Pass every character immediately, not buffered. */
cbreak();
do {
/* Clear the screen. */
erase();
/* Print "X" at the center of the screen, */
mvaddch(LINES/2, COLS/2, 'X');
/* and msg centered at the bottom. */
mvaddstr(LINES-1, (COLS-strlen(msg))/2, msg);
/* Move the cursor to the center of the screen too. */
move(LINES/2, COLS/2);
/* Refresh the screen. */
refresh();
/* Wait for a keypress. */
c = getch();
} while (c != 'Q' && c != 'q');
/* Done. Return the terminal back to its normal state. */
endwin();
return 0;
}
then compile and run it using e.g.
Code:
cc example.c -lcurses -o example
./example
It is pretty much the lowest level you should bother.
If you resize the terminal window -- mine are practically never exactly 80 columns wide, nowadays --, it is seen as a keypress by the above program. Since it is not Q, it will redraw the screen. However, that screen update "keypress" also updates LINES and COLS, which means that the next iteration of the loop will redraw everything correctly, as per the resized terminal window. It's quite nifty, and pretty much exactly what I want from such a "terminal canvas".
As a programmer, all you need to remember is that COLS is not always 80, and LINES is not always 25 or 43 or 50, and both may change at any point if the user resizes the terminal window.
In Windows, you can use pdcurses, but I have no idea about the installation or compilation details since I don't use Windows at all. Maybe someone else can point out those details?