Skip to content

Commit bb6721d

Browse files
committed
Merge pull request #8 from msoucy/master
Examples and documentation
2 parents 482920f + 91e8a6a commit bb6721d

File tree

10 files changed

+108
-18
lines changed

10 files changed

+108
-18
lines changed

README

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ There will be bugs. This is simply too large of a library for me to test every
44
If you have any trouble, or think that something should be fixed, create a bug report and I'll get right on it.
55

66
WARNINGS:
7-
ACS vars currently break from the norm, I'm looking into it, but I'm not sure if It can
8-
be done exactly the same that C does it.
9-
////instead of writing "addch(ACS_ULCORNER);", Instead write "addch(acs_map[ACS.ULCORNER]);". fixed
10-
Instead of writing "addch(ACS_ULCORNER);", Instead write "addch(ACS_ULCORNER());"
11-
I think that this is as close as we are going to get without digging through the source to extract what acs_map[] really is.
12-
137
This should work for most of your needs, however there are still one or two more things that need to be done.
148
I plan on having those completed in the next few days.
159
I'm actually not entirely sure what still needs to be done. Someone told me that this was a macro library.

deimos/ncurses/form.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
/* $Id: form.h,v 0.21 2009/11/07 19:31:11 tom Exp $ */
3434

35+
module deimos.ncurses.form;
36+
3537

3638
import std.c.stdarg;
3739
public import deimos.ncurses.ncurses;

deimos/ncurses/ncurses.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
module deimos.ncurses.ncurses;
3333

3434
public import deimos.ncurses.curses;
35+
alias deimos.ncurses.curses.clear nclear;

examples/hello_unicode.d

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** hello_unicode.d
2+
*
3+
* This is a demonstration of Unicode output with ncurses in D.
4+
*
5+
* The functionality of this code is otherwise identical to hello_world.d
6+
*
7+
* Requirements for Unicode in ncurses:
8+
* - You need to link against ncursesw instead of ncurses. If you don't have ncursesw, rebuild
9+
* ncurses with --enable-widec (and file a bug with your distro where applicable).
10+
* - You need to be using a Unicode locale. If your $LANG looks something like `en_US.utf8`,
11+
* then you're in good shape. Keep in mind that users don't like when you force a locale; do
12+
* it only if you think it's really necessary.
13+
*
14+
* Modified by: Wyatt
15+
*/
16+
import std.string: toStringz;
17+
import std.c.locale; // Need setlocale()
18+
import deimos.ncurses.ncurses;
19+
20+
void main()
21+
{
22+
setlocale(LC_CTYPE,""); // You need to set the empty locale to use upper-plane glyphs
23+
// This sets the locale based on local variables. On most Unix-
24+
// like systems, you can use the `locale` command to show the
25+
// current settings for your environment.
26+
27+
auto hello = toStringz("日本語からの「Hello World!」");
28+
29+
initscr(); //initialize the screen
30+
printw(hello); //prints the char[] hello to the screen
31+
refresh(); //actually does the writing to the physical screen
32+
getch(); //gets a single character from the screen.
33+
endwin(); //Routine to call before exiting, or leaving curses mode temporarily
34+
}

examples/menu_scroll.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ int main()
5555
/* Print a border around the main window and print a title */
5656
box(my_menu_win, 0, 0);
5757
print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1));
58-
mvwaddch(my_menu_win, 2, 0, acs_map[ACS.LTEE]);
59-
mvwhline(my_menu_win, 2, 1, acs_map[ACS.HLINE], 38);
60-
mvwaddch(my_menu_win, 2, 39, acs_map[ACS.RTEE]);
58+
mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
59+
mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38);
60+
mvwaddch(my_menu_win, 2, 39, ACS_RTEE);
6161

6262
/* Post the menu */
6363
post_menu(my_menu);
@@ -99,7 +99,7 @@ int main()
9999
}
100100

101101
void print_in_middle(WINDOW *win, int starty, int startx, int width, string strtemp, chtype color)
102-
{ int length, x, y;
102+
{ int x, y;
103103
float temp;
104104

105105
if(win == null)
@@ -112,7 +112,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, string strt
112112
if(width == 0)
113113
width = 80;
114114

115-
length = strtemp.length;
115+
auto length = strtemp.length;
116116
temp = (width - length)/ 2;
117117
x = startx + cast(int)temp;
118118
wattron(win, color);

examples/mouse_menu.d

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import std.string: toStringz;
32
import deimos.ncurses.ncurses;
43

@@ -18,7 +17,7 @@ void main()
1817
MEVENT event;
1918

2019
initscr(); //hopefully you've seen all of this before.
21-
clear();
20+
nclear();
2221
noecho();
2322
cbreak();
2423
keypad(stdscr, true);
@@ -83,7 +82,7 @@ void print_menu(WINDOW* menu_win, int highlight)
8382

8483
box(menu_win, 0, 0);
8584

86-
foreach(i, choice; choices)
85+
foreach(int i, choice; choices)
8786
{
8887
if(highlight == i + 1)
8988
wattron(menu_win, A_REVERSE);
@@ -100,7 +99,7 @@ int report_choice(int mouse_x, int mouse_y)
10099
int i = startx + 2;
101100
int j = starty + 3;
102101
int report = 0;
103-
foreach(choice, str; choices)
102+
foreach(int choice, str; choices)
104103
{
105104
if((mouse_y == j + choice) && (mouse_x >= i) && (mouse_x <= i+str.length))
106105
{

examples/printw_example.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//Modified by: 1100110
22

3+
import std.conv;
34
import std.string;
45
import deimos.ncurses.ncurses; /* ncurses.h includes stdio.h */
56

@@ -11,7 +12,7 @@ void main()
1112
initscr(); //start the curses mode
1213
getmaxyx(stdscr, row, col); //get the number of rows and columns
1314
//print the message at the center of the screen
14-
mvprintw(row/2, (col-(mesg.length - 1))/2, "%s", toStringz(mesg));
15+
mvprintw(row/2, to!uint((col-(mesg.length - 1))/2), "%s", toStringz(mesg));
1516
//Did you notice? there is a '%s' not toStringified.
1617
//In one of those great weird blips, D2 will pass small characters
1718
//like that, and yet will choke on larger strings.

examples/simple_key.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main()
1717
int c;
1818

1919
initscr();
20-
clear();
20+
nclear();
2121
noecho();
2222
cbreak(); /* Line buffering disabled. pass on everything */
2323
scope(exit) endwin();

examples/simple_spectrum.d

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
}

examples/with_chgat.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void main()
77

88
init_pair(1, COLOR_CYAN, COLOR_BLACK);
99
printw(toStringz("A Big string which i didn't care to type fully... "));
10-
mvchgat(0, 0, -1, cast(attr_t)A_BLINK, cast(short)1, null);
10+
mvchgat(0, 0, -1, cast(attr_t)A_BLINK, cast(short)1, cast(void*)null);
1111
/*
1212
* First two parameters specify the position at which to start
1313
* Third parameter number of characters to update. -1 means till

0 commit comments

Comments
 (0)