From: Ricardo Markiewicz Date: Fri, 26 Mar 2004 03:12:58 +0000 (+0000) Subject: * Agrego ejemplos de ncurses X-Git-Tag: svn_import_r684~683 X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/commitdiff_plain/0b52d9d6ca062537af54ca7a82c36acb52eb6e2d?ds=sidebyside * Agrego ejemplos de ncurses --- 0b52d9d6ca062537af54ca7a82c36acb52eb6e2d diff --git a/ejemplos/Makefile b/ejemplos/Makefile new file mode 100644 index 0000000..f2f9768 --- /dev/null +++ b/ejemplos/Makefile @@ -0,0 +1,6 @@ + +all: + gcc -Wall -o ej1 ej_1.c -lncurses + gcc -Wall -o ej2 ej_2.c -lncurses + + diff --git a/ejemplos/ej_1.c b/ejemplos/ej_1.c new file mode 100644 index 0000000..51d5d0b --- /dev/null +++ b/ejemplos/ej_1.c @@ -0,0 +1,54 @@ + +#include +#include +#include + +static void finish(int sig); + +int main(int argc, char *argv[]) +{ + /* initialize your non-curses data structures here */ + WINDOW *mainwin; + + signal(SIGINT, finish); /* arrange interrupts to terminate */ + mainwin = initscr(); /* initialize the curses library */ + keypad(stdscr, TRUE); /* enable keyboard mapping */ + nonl(); /* tell curses not to do NL->CR/NL on output */ + cbreak(); /* take input chars one at a time, no wait for \n */ + noecho(); /* don't echo input */ + + if (has_colors()) { + start_color(); + /* Simple color assignment, often all we need. */ + init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); + init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); + init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); + init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); + init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); + init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); + init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); + init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); + } + + /* Ventana, caracter para linea vertical, caracter para linea horizontal*/ + box(mainwin, ACS_VLINE, ACS_HLINE); + /* Ventana, Y, X, Texto */ + mvwaddstr(mainwin, 10, 10, "Primer ejemplo!"); + mvwaddstr(mainwin, 11, 10, "Una sola ventana de toda la terminal"); + + getch(); + + delwin(mainwin); + endwin(); + return 0; +} + +static void finish(int sig) +{ + endwin(); + + /* do your non-curses wrapup here */ + + exit(0); +} + diff --git a/ejemplos/ej_2.c b/ejemplos/ej_2.c new file mode 100644 index 0000000..01a1fb1 --- /dev/null +++ b/ejemplos/ej_2.c @@ -0,0 +1,61 @@ + +#include +#include +#include + +static void finish(int sig); + +int main(int argc, char *argv[]) +{ + /* initialize your non-curses data structures here */ + WINDOW *mainwin, *otra; + + signal(SIGINT, finish); /* arrange interrupts to terminate */ + mainwin = initscr(); /* initialize the curses library */ + keypad(stdscr, TRUE); /* enable keyboard mapping */ + nonl(); /* tell curses not to do NL->CR/NL on output */ + cbreak(); /* take input chars one at a time, no wait for \n */ + noecho(); /* don't echo input */ + + if (has_colors()) { + start_color(); + /* Simple color assignment, often all we need. */ + init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); + init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); + init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); + init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); + init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); + init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); + init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); + init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); + } + + /* Ventana, caracter para linea vertical, caracter para linea horizontal*/ + box(mainwin, ACS_VLINE, ACS_HLINE); + /* Ventana, Y, X, Texto */ + mvwaddstr(mainwin, 3, 10, "Segundo Ejemplo!"); + mvwaddstr(mainwin, 4, 10, "Ventana Principal, Ocupa todo el terminal"); + + /* Creo una subventana! */ + otra = subwin(mainwin, 10, 10, 8, 20); + mvwaddstr(otra, 1, 1, "Esto es otra ventana (sin borde)"); + + refresh(); + + getch(); + + delwin(otra); + delwin(mainwin); + endwin(); + return 0; +} + +static void finish(int sig) +{ + endwin(); + + /* do your non-curses wrapup here */ + + exit(0); +} +