some ncurses tests
authorMichael Göhler <somebody.here@gmx.de>
Tue, 19 Aug 2014 22:37:07 +0000 (00:37 +0200)
committerMichael Göhler <somebody.here@gmx.de>
Tue, 19 Aug 2014 22:37:07 +0000 (00:37 +0200)
test/Makefile
test/color.c [new file with mode: 0644]
test/fade.c [new file with mode: 0644]

index 6e8c05e..6d0f234 100644 (file)
@@ -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 (file)
index 0000000..b06410c
--- /dev/null
@@ -0,0 +1,29 @@
+#include <ncurses.h>
+
+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 (file)
index 0000000..6dea34d
--- /dev/null
@@ -0,0 +1,65 @@
+#include <ncurses.h>
+#include <signal.h>
+#include <stdlib.h>
+#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;
+}