From 3f5b9cb68b3da6a63b2f70a69da04dfa51c59e09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michael=20G=C3=B6hler?= Date: Wed, 20 Aug 2014 00:37:07 +0200 Subject: [PATCH] some ncurses tests --- test/Makefile | 2 +- test/color.c | 29 +++++++++++++++++++++++ test/fade.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 test/color.c create mode 100644 test/fade.c diff --git a/test/Makefile b/test/Makefile index 6e8c05e..6d0f234 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ # set some compiler flags -CFLAGS= +CFLAGS=-g -lncurses # find *.c in the current directory SOURCES=$(wildcard *.c) diff --git a/test/color.c b/test/color.c new file mode 100644 index 0000000..b06410c --- /dev/null +++ b/test/color.c @@ -0,0 +1,29 @@ +#include + +WINDOW *w; + +void set_colors(void) +{ + int i; + initscr(); + start_color(); + use_default_colors(); + + for(i=1 ;i<256;i++) + { + init_pair(i, i, -1); + attron(COLOR_PAIR(i)); + printw(" %3.hd", i); + if(i % 15 == 0) printw("\n"); + refresh(); + } + standend(); + getch(); + endwin(); +} + +int main(void) +{ + set_colors(); + return 0; +} diff --git a/test/fade.c b/test/fade.c new file mode 100644 index 0000000..6dea34d --- /dev/null +++ b/test/fade.c @@ -0,0 +1,65 @@ +#include +#include +#include +#define COLOR_PAIR1 1 +#define COLOR_PAIR2 2 +int main() +{ + initscr(); + curs_set(0);//sets visability of cursor + noecho();//disable auto-echoing + cbreak();//making getch() work without a buffer + keypad(stdscr,TRUE);//allows use of special keys, namely the arrow keys + if(has_colors() == TRUE) + { + start_color(); + use_default_colors(); + init_pair(COLOR_PAIR1,123,-1); + init_pair(COLOR_PAIR2,255,-1); + wbkgd(stdscr,COLOR_PAIR(COLOR_PAIR1)); + wmove(stdscr,10,5); + printw("q = quit"); + WINDOW *test=newwin(10,20,5,20); + wbkgd(test,COLOR_PAIR(COLOR_PAIR2)); + wprintw(test,"try\nUP or DOWN"); + wrefresh(stdscr); + wrefresh(test); + + // fading colors + short blue_ramp[] = { 16, 17, 17, 18, 18, 19, + 19, 20, 20, 21, 27, 32, + 33, 38, 39, 44, 45, 45, + 81, 81, 51, 51, 123, 123}; + short white_ramp[] = {232, 233, 234, 235, 236, 237, + 238, 239, 240, 241, 242, 243, + 244, 245, 246, 247, 248, 249, + 250, 251, 252, 253, 254, 255}; + + short i = 23; + for (;;) + { + int c = getch(); + if(c == 'q') break; + + switch(c) { + case KEY_UP: + if(i < 23) i = i + 1; + break; + + case KEY_DOWN: + if(i > 0)i = i - 1; + break; + } + + init_pair(COLOR_PAIR1,blue_ramp[i],-1); + init_pair(COLOR_PAIR2,white_ramp[i],-1); + wrefresh(stdscr); + wrefresh(test); + } + + delwin(test); + } + + endwin(); + return 0; +} -- 2.20.1