|
| 1 | +//simple_spectrum: Sample of 256-colour ncurses output in D. |
1 | 2 | //Modified by: Wyatt
|
2 | 3 |
|
3 | 4 | import std.stdio: writeln;
|
4 | 5 | import std.conv;
|
5 | 6 | import deimos.ncurses.ncurses;
|
6 | 7 |
|
| 8 | +//Extended colour support was added in ncurses 5.5 for the wncurses |
| 9 | +//library. wncurses has generally been shipped by default in Linux |
| 10 | +//distros for roughly the last decade as of this writing (often as the |
| 11 | +//only version installed); if this doesn't work, check that your TERM |
| 12 | +//is compatible with 256-colour modes, that your terminal emulator |
| 13 | +//supports it, and that your copy of ncurses is built with |
| 14 | +//--enable-ext-colors. If the latter is false, you may wish to file a |
| 15 | +//bug with your distro. |
| 16 | + |
7 | 17 | int main()
|
8 | 18 | {
|
9 |
| - initscr(); //Start curses mode |
| 19 | + initscr(); |
10 | 20 | if(has_colors() == false)
|
11 | 21 | {
|
12 | 22 | endwin();
|
13 | 23 | writeln("Your terminal does not support color...");
|
14 | 24 | return 1; //ends the program
|
15 | 25 | }
|
16 |
| - start_color(); // Start color |
| 26 | + start_color(); |
17 | 27 | foreach(ushort i; 0 .. 256){ // Define all the colours with the default palette
|
18 | 28 | init_pair(i, 0, i); // We're only setting the background here;
|
19 | 29 | } // The space is rendered as nothing.
|
| 30 | + |
20 | 31 | auto w = COLS/9; // Let's just fill all the horizontal space
|
| 32 | + |
| 33 | + // Basic colours |
21 | 34 | foreach(ushort i; 0 .. 16){
|
22 | 35 | attron(COLOR_PAIR(i));
|
23 | 36 | mvwhline(stdscr, cast(int)(i%8),w*(i/8),to!size_t(' '),w);//chtype is a size_t by spec.
|
24 | 37 | attroff(COLOR_PAIR(i));
|
25 | 38 | }
|
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 |
| - //} |
| 39 | + |
| 40 | + // 6x6x6 cubemap |
31 | 41 | foreach(ushort i; 16 .. 232){
|
32 | 42 | attron(COLOR_PAIR(i));
|
33 | 43 | mvwhline(stdscr, cast(int)((i-16)%36),(2*w+w*((i-16)/36)),to!size_t(' '),w);
|
34 | 44 | attroff(COLOR_PAIR(i));
|
35 | 45 | }
|
| 46 | + |
| 47 | + // Greyscale |
36 | 48 | foreach(ushort i; 232 .. 256){
|
37 | 49 | attron(COLOR_PAIR(i));
|
38 | 50 | mvwhline(stdscr, cast(int)(i-232),(8*w),to!size_t(' '),w);
|
39 | 51 | attroff(COLOR_PAIR(i));
|
40 | 52 | }
|
41 |
| - wmove(stdscr, LINES-1, COLS-1); |
| 53 | + |
| 54 | + wmove(stdscr, LINES-1, COLS-1);//Moving this out of the way |
42 | 55 | getch();
|
43 | 56 | endwin();
|
44 | 57 |
|
|
0 commit comments