|
| 1 | +//simple_spectrum: Sample of 256-colour ncurses output in D. |
| 2 | +//Modified by: Wyatt |
| 3 | + |
| 4 | +import std.stdio: writeln; |
| 5 | +import std.conv; |
| 6 | +import deimos.ncurses.ncurses; |
| 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 | + |
| 17 | +int main() |
| 18 | +{ |
| 19 | + initscr(); |
| 20 | + if(has_colors() == false) |
| 21 | + { |
| 22 | + endwin(); |
| 23 | + writeln("Your terminal does not support color..."); |
| 24 | + return 1; //ends the program |
| 25 | + } |
| 26 | + start_color(); |
| 27 | + foreach(ushort i; 0 .. 256){ // Define all the colours with the default palette |
| 28 | + init_pair(i, 0, i); // We're only setting the background here; |
| 29 | + } // The space is rendered as nothing. |
| 30 | + |
| 31 | + auto w = COLS/9; // Let's just fill all the horizontal space |
| 32 | + |
| 33 | + // Basic colours |
| 34 | + foreach(ushort i; 0 .. 16){ |
| 35 | + attron(COLOR_PAIR(i)); |
| 36 | + mvwhline(stdscr, cast(int)(i%8),w*(i/8),to!size_t(' '),w);//chtype is a size_t by spec. |
| 37 | + attroff(COLOR_PAIR(i)); |
| 38 | + } |
| 39 | + |
| 40 | + // 6x6x6 cubemap |
| 41 | + foreach(ushort i; 16 .. 232){ |
| 42 | + attron(COLOR_PAIR(i)); |
| 43 | + mvwhline(stdscr, cast(int)((i-16)%36),(2*w+w*((i-16)/36)),to!size_t(' '),w); |
| 44 | + attroff(COLOR_PAIR(i)); |
| 45 | + } |
| 46 | + |
| 47 | + // Greyscale |
| 48 | + foreach(ushort i; 232 .. 256){ |
| 49 | + attron(COLOR_PAIR(i)); |
| 50 | + mvwhline(stdscr, cast(int)(i-232),(8*w),to!size_t(' '),w); |
| 51 | + attroff(COLOR_PAIR(i)); |
| 52 | + } |
| 53 | + |
| 54 | + wmove(stdscr, LINES-1, COLS-1);//Moving this out of the way |
| 55 | + getch(); |
| 56 | + endwin(); |
| 57 | + |
| 58 | + return 0; |
| 59 | +} |
0 commit comments