Skip to content

Commit 120bb92

Browse files
committed
Examples: Unix line endings
1 parent 1cddbb7 commit 120bb92

File tree

12 files changed

+323
-323
lines changed

12 files changed

+323
-323
lines changed
Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,83 @@
1-
import deimos.ncurses.menu;
2-
import std.conv: to;
3-
4-
const int CTRLD = 4;
5-
6-
immutable char[][] choices = [ "Choice 1",
7-
"Choice 2",
8-
"Choice 3",
9-
"Choice 4",
10-
"Choice 5",
11-
"Choice 6",
12-
"Choice 7",
13-
"Exit" ];
14-
15-
int main()
16-
{
17-
ITEM*[] my_items;
18-
int c;
19-
MENU* my_menu;
20-
int n_choices, i;
21-
ITEM* cur_item;
22-
23-
/* Initialize curses */
24-
initscr();
25-
start_color();
26-
cbreak();
27-
noecho();
28-
keypad(stdscr, true);
29-
init_pair(1, COLOR_RED, COLOR_BLACK);
30-
init_pair(2, COLOR_GREEN, COLOR_BLACK);
31-
init_pair(3, COLOR_MAGENTA, COLOR_BLACK);
32-
33-
/* Initialize items */
34-
n_choices = choices.length.to!int;
35-
my_items.length = n_choices + 1;
36-
for(i = 0; i < n_choices; ++i)
37-
my_items[i] = new_item((choices[i]~'\0').ptr, (choices[i]~'\0').ptr);
38-
my_items[n_choices] = null;
39-
item_opts_off(my_items[3], O_SELECTABLE);
40-
item_opts_off(my_items[6], O_SELECTABLE);
41-
42-
/* Create menu */
43-
my_menu = new_menu(my_items.ptr);
44-
45-
/* Set fore ground and back ground of the menu */
46-
set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE);
47-
set_menu_back(my_menu, COLOR_PAIR(2));
48-
set_menu_grey(my_menu, COLOR_PAIR(3));
49-
50-
/* Post the menu */
51-
mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
52-
mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
53-
post_menu(my_menu);
54-
refresh();
55-
56-
while((c = getch()) != KEY_F(1))
57-
{ switch(c)
58-
{ case KEY_DOWN:
59-
menu_driver(my_menu, REQ_DOWN_ITEM);
60-
break;
61-
case KEY_UP:
62-
menu_driver(my_menu, REQ_UP_ITEM);
63-
break;
64-
case 10: /* Enter */
65-
move(20, 0);
66-
clrtoeol();
67-
mvprintw(20, 0, "Item selected is : %s",
68-
item_name(current_item(my_menu)));
69-
pos_menu_cursor(my_menu);
70-
break;
71-
default:
72-
break;
73-
}
74-
}
75-
unpost_menu(my_menu);
76-
for(i = 0; i < n_choices; ++i)
77-
free_item(my_items[i]);
78-
free_menu(my_menu);
79-
endwin();
80-
81-
return 0;
82-
}
83-
1+
import deimos.ncurses.menu;
2+
import std.conv: to;
3+
4+
const int CTRLD = 4;
5+
6+
immutable char[][] choices = [ "Choice 1",
7+
"Choice 2",
8+
"Choice 3",
9+
"Choice 4",
10+
"Choice 5",
11+
"Choice 6",
12+
"Choice 7",
13+
"Exit" ];
14+
15+
int main()
16+
{
17+
ITEM*[] my_items;
18+
int c;
19+
MENU* my_menu;
20+
int n_choices, i;
21+
ITEM* cur_item;
22+
23+
/* Initialize curses */
24+
initscr();
25+
start_color();
26+
cbreak();
27+
noecho();
28+
keypad(stdscr, true);
29+
init_pair(1, COLOR_RED, COLOR_BLACK);
30+
init_pair(2, COLOR_GREEN, COLOR_BLACK);
31+
init_pair(3, COLOR_MAGENTA, COLOR_BLACK);
32+
33+
/* Initialize items */
34+
n_choices = choices.length.to!int;
35+
my_items.length = n_choices + 1;
36+
for(i = 0; i < n_choices; ++i)
37+
my_items[i] = new_item((choices[i]~'\0').ptr, (choices[i]~'\0').ptr);
38+
my_items[n_choices] = null;
39+
item_opts_off(my_items[3], O_SELECTABLE);
40+
item_opts_off(my_items[6], O_SELECTABLE);
41+
42+
/* Create menu */
43+
my_menu = new_menu(my_items.ptr);
44+
45+
/* Set fore ground and back ground of the menu */
46+
set_menu_fore(my_menu, COLOR_PAIR(1) | A_REVERSE);
47+
set_menu_back(my_menu, COLOR_PAIR(2));
48+
set_menu_grey(my_menu, COLOR_PAIR(3));
49+
50+
/* Post the menu */
51+
mvprintw(LINES - 3, 0, "Press <ENTER> to see the option selected");
52+
mvprintw(LINES - 2, 0, "Up and Down arrow keys to naviage (F1 to Exit)");
53+
post_menu(my_menu);
54+
refresh();
55+
56+
while((c = getch()) != KEY_F(1))
57+
{ switch(c)
58+
{ case KEY_DOWN:
59+
menu_driver(my_menu, REQ_DOWN_ITEM);
60+
break;
61+
case KEY_UP:
62+
menu_driver(my_menu, REQ_UP_ITEM);
63+
break;
64+
case 10: /* Enter */
65+
move(20, 0);
66+
clrtoeol();
67+
mvprintw(20, 0, "Item selected is : %s",
68+
item_name(current_item(my_menu)));
69+
pos_menu_cursor(my_menu);
70+
break;
71+
default:
72+
break;
73+
}
74+
}
75+
unpost_menu(my_menu);
76+
for(i = 0; i < n_choices; ++i)
77+
free_item(my_items[i]);
78+
free_menu(my_menu);
79+
endwin();
80+
81+
return 0;
82+
}
83+

examples/chgat/source/chgat.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import std.conv: to;
33
import deimos.ncurses.ncurses;
44

55
void main()
6-
{
6+
{
77
initscr(); //Start curses mode
88
scope(failure) endwin();
99
scope(exit) endwin();
@@ -12,7 +12,7 @@ void main()
1212

1313
init_pair(1, COLOR_CYAN, COLOR_BLACK);
1414
printw(toStringz("A Big string which i didn't care to type fully... "));
15-
//type attr_t
15+
//type attr_t
1616
mvchgat(0, 0, -1, A_BLINK.to!attr_t, 1.to!short, null.to!(void*));
1717
/*
1818
* First two parameters specify the position at which to start

examples/hellounicode/source/helloUnicode.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void main()
2020
{
2121
setlocale(LC_CTYPE,""); // You need to set the empty locale to use upper-plane glyphs
2222
// This sets the locale based on local variables. On most Unix-
23-
// like systems, you can use the `locale` command to show the
23+
// like systems, you can use the `locale` command to show the
2424
// current settings for your environment.
2525

2626
immutable hello = toStringz("日本語からの「Hello World!」");

examples/printbold/source/printBold.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This is rather interesting, it prints the bold version
22
* of whatever you type on the screen.
33
*
4-
*/
4+
*/
55

66
import std.string: toStringz;
77
import deimos.ncurses.ncurses;
@@ -18,10 +18,10 @@ void main()
1818
printw(toStringz("Type any character to see it in bold!\n"));
1919
ch = getch(); //If raw() hadn't been called
2020
//we have to press enter before it
21-
//gets to the program
21+
//gets to the program
2222

2323
if(ch == KEY_F(1)) //Without keypad enabled this will not get to us either
24-
printw(toStringz("F1 Key pressed"));
24+
printw(toStringz("F1 Key pressed"));
2525
//Without noecho() some ugly escape
2626
//charachters might have been printed
2727
//to the screen

examples/printw/source/printw.d

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import std.conv: to;
44
import std.string;
55
import deimos.ncurses.ncurses;
6-
6+
77
void main()
88
{
99
immutable mesg = "Just a string...";
@@ -14,12 +14,12 @@ void main()
1414
scope(exit) endwin();
1515

1616
getmaxyx(stdscr, row, col);
17-
18-
//print the message at the center of the screen
17+
18+
//print the message at the center of the screen
1919
mvprintw(row/2, ((col-(mesg.length - 1))/2).to!int, "%s", toStringz(mesg));
20-
20+
2121
//Did you notice? there is a '%s' not toStringified.
22-
22+
2323
auto rowcol = "This screen has %d rows and %d columns\n".toStringz;
2424
mvprintw(row-2, 0, rowcol, row+1, col+1);
2525

0 commit comments

Comments
 (0)