Skip to content

Commit 37bfdc3

Browse files
committed
simple_spectrum: Samples of 256-colour wncurses output in D.
Extended colour support was added in ncurses 5.5 for the wncurses library.
1 parent 4f080cc commit 37bfdc3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

examples/simple_spectrum.d

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//Modified by: Wyatt
2+
3+
import std.stdio: writeln;
4+
import std.conv;
5+
import deimos.ncurses.ncurses;
6+
7+
int main()
8+
{
9+
initscr(); //Start curses mode
10+
if(has_colors() == false)
11+
{
12+
endwin();
13+
writeln("Your terminal does not support color...");
14+
return 1; //ends the program
15+
}
16+
start_color(); // Start color
17+
foreach(ushort i; 0 .. 256){ // Define all the colours with the default palette
18+
init_pair(i, 0, i); // We're only setting the background here;
19+
} // The space is rendered as nothing.
20+
auto w = COLS/9; // Let's just fill all the horizontal space
21+
foreach(ushort i; 0 .. 16){
22+
attron(COLOR_PAIR(i));
23+
mvwhline(stdscr, cast(int)(i%8),w*(i/8),to!size_t(' '),w);//chtype is a size_t by spec.
24+
attroff(COLOR_PAIR(i));
25+
}
26+
//foreach(ushort i; 8 .. 16){
27+
//attron(COLOR_PAIR(i));
28+
//mvwhline(stdscr, cast(int)(i-8),5,to!size_t(' '),5);
29+
//attroff(COLOR_PAIR(i));
30+
//}
31+
foreach(ushort i; 16 .. 232){
32+
attron(COLOR_PAIR(i));
33+
mvwhline(stdscr, cast(int)((i-16)%36),(2*w+w*((i-16)/36)),to!size_t(' '),w);
34+
attroff(COLOR_PAIR(i));
35+
}
36+
foreach(ushort i; 232 .. 256){
37+
attron(COLOR_PAIR(i));
38+
mvwhline(stdscr, cast(int)(i-232),(8*w),to!size_t(' '),w);
39+
attroff(COLOR_PAIR(i));
40+
}
41+
wmove(stdscr, LINES-1, COLS-1);
42+
getch();
43+
endwin();
44+
45+
return 0;
46+
}

0 commit comments

Comments
 (0)