Skip to content

Commit 0a0d261

Browse files
committed
Examples: formatting
1 parent 120bb92 commit 0a0d261

File tree

19 files changed

+472
-438
lines changed

19 files changed

+472
-438
lines changed

examples/acsvars/source/acsVars.d

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import std.string: toStringz;
1+
import std.string : toStringz;
22
import deimos.ncurses.curses;
33

44
void main()
55
{
66
initscr();
7-
scope(exit) endwin();
8-
scope(failure) endwin();
9-
//Please note: you might want to maximize your terminal before you try to
10-
//run this. It does not check the size or enable scrolling.
11-
//In other word, if your terminal is <= 23 by 79, it will do weird things.
12-
//The spaces are for readability on the screen when you run the program.
7+
scope (exit)
8+
endwin();
9+
scope (failure)
10+
endwin();
11+
// Please note: you might want to maximize your terminal before you try to
12+
// run this. It does not check the size or enable scrolling.
13+
// In other word, if your terminal is <= 23 by 79, it will do weird things.
14+
// The spaces are for readability on the screen when you run the program.
1315

1416
printw(toStringz("Upper left corner "));
1517
addch(ACS_ULCORNER());
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import deimos.ncurses.menu;
2-
import std.conv: to;
2+
import std.conv : to;
33

44
const int CTRLD = 4;
55

@@ -23,18 +23,18 @@ int main()
2323
/* Initialize curses */
2424
initscr();
2525
start_color();
26-
cbreak();
27-
noecho();
26+
cbreak();
27+
noecho();
2828
keypad(stdscr, true);
2929
init_pair(1, COLOR_RED, COLOR_BLACK);
3030
init_pair(2, COLOR_GREEN, COLOR_BLACK);
3131
init_pair(3, COLOR_MAGENTA, COLOR_BLACK);
3232

3333
/* 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);
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);
3838
my_items[n_choices] = null;
3939
item_opts_off(my_items[3], O_SELECTABLE);
4040
item_opts_off(my_items[6], O_SELECTABLE);
@@ -53,31 +53,31 @@ int main()
5353
post_menu(my_menu);
5454
refresh();
5555

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;
56+
while ((c = getch()) != KEY_F(1))
57+
{
58+
switch (c)
59+
{
60+
case KEY_DOWN:
61+
menu_driver(my_menu, REQ_DOWN_ITEM);
62+
break;
63+
case KEY_UP:
64+
menu_driver(my_menu, REQ_UP_ITEM);
65+
break;
66+
case 10: /* Enter */
67+
move(20, 0);
68+
clrtoeol();
69+
mvprintw(20, 0, "Item selected is : %s", item_name(current_item(my_menu)));
70+
pos_menu_cursor(my_menu);
71+
break;
72+
default:
73+
break;
7374
}
7475
}
7576
unpost_menu(my_menu);
76-
for(i = 0; i < n_choices; ++i)
77+
for (i = 0; i < n_choices; ++i)
7778
free_item(my_items[i]);
7879
free_menu(my_menu);
7980
endwin();
8081

81-
return 0;
82+
return 0;
8283
}
83-

examples/chgat/source/chgat.d

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import std.string: toStringz;
2-
import std.conv: to;
1+
import std.string : toStringz;
2+
import std.conv : to;
33
import deimos.ncurses.ncurses;
44

55
void main()
66
{
7-
initscr(); //Start curses mode
8-
scope(failure) endwin();
9-
scope(exit) endwin();
7+
initscr(); // Start curses mode
8+
scope (failure)
9+
endwin();
10+
scope (exit)
11+
endwin();
1012

11-
start_color(); //Start color functionality
13+
start_color(); // Start color functionality
1214

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

examples/form_attrib/source/form_attrib.d

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,74 @@ import std.string;
44
void main()
55
{
66
FIELD*[3] field;
7-
FORM* my_form;
7+
FORM* my_form;
88
int ch;
99

10-
//Initialize curses
10+
// Initialize curses
1111
initscr();
1212
start_color();
1313
cbreak();
1414
noecho();
1515
keypad(stdscr, true);
16-
scope(exit) endwin();
16+
scope (exit)
17+
endwin();
1718

18-
//Initialize a few color pairs
19+
// Initialize a few color pairs
1920
init_pair(1, COLOR_WHITE, COLOR_BLUE);
2021
init_pair(2, COLOR_WHITE, COLOR_BLUE);
2122

22-
//Initialize the fields
23+
// Initialize the fields
2324
field[0] = new_field(1, 10, 4, 18, 0, 0);
2425
field[1] = new_field(1, 10, 6, 18, 0, 0);
2526
field[2] = null;
2627

27-
//Set field options
28-
set_field_fore(field[0], COLOR_PAIR(1)); //Put the field with blue background
29-
set_field_back(field[0], COLOR_PAIR(2)); //and white foreground (characters
30-
//are printed in white
31-
field_opts_off(field[0], O_AUTOSKIP); //Don't go to next field when this
32-
//Field is filled up
28+
// Set field options
29+
set_field_fore(field[0], COLOR_PAIR(1)); // Put the field with blue background
30+
set_field_back(field[0], COLOR_PAIR(2)); // and white foreground (characters
31+
// are printed in white
32+
field_opts_off(field[0], O_AUTOSKIP); // Don't go to next field when this
33+
// Field is filled up
3334
set_field_back(field[1], A_UNDERLINE);
3435
field_opts_off(field[1], O_AUTOSKIP);
3536

36-
//Create the form and post it
37+
// Create the form and post it
3738
my_form = new_form(field.ptr);
3839
post_form(my_form);
3940
refresh();
4041

41-
set_current_field(my_form, field[0]); //Set focus to the colored field
42+
set_current_field(my_form, field[0]); // Set focus to the colored field
4243
mvprintw(4, 10, toStringz("Value 1:"));
4344
mvprintw(6, 10, toStringz("Value 2:"));
4445
mvprintw(LINES - 2, 0, toStringz("Use UP, DOWN arrow keys to switch between fields"));
4546
refresh();
4647

47-
//Loop through to get user requests
48-
while_loop:
49-
while((ch = getch()) != KEY_F(1))
48+
// Loop through to get user requests
49+
while_loop: while ((ch = getch()) != KEY_F(1))
5050
{
51-
switch(ch)
51+
switch (ch)
5252
{
53-
case KEY_DOWN:
54-
//Go to the next field
55-
form_driver(my_form, REQ_NEXT_FIELD);
56-
//Go to the end of the present buffer
57-
//Leaves nicely at the last character
58-
form_driver(my_form, REQ_END_LINE);
59-
break;
60-
case KEY_UP:
61-
//Go to previous field
62-
form_driver(my_form, REQ_PREV_FIELD);
63-
form_driver(my_form, REQ_END_LINE);
64-
break;
65-
default:
66-
//If this is a normal character, it gets Printed
67-
form_driver(my_form, ch);
68-
break;
69-
}//switch
70-
}//while
53+
case KEY_DOWN:
54+
// Go to the next field
55+
form_driver(my_form, REQ_NEXT_FIELD);
56+
// Go to the end of the present buffer
57+
// Leaves nicely at the last character
58+
form_driver(my_form, REQ_END_LINE);
59+
break;
60+
case KEY_UP:
61+
// Go to previous field
62+
form_driver(my_form, REQ_PREV_FIELD);
63+
form_driver(my_form, REQ_END_LINE);
64+
break;
65+
default:
66+
// If this is a normal character, it gets Printed
67+
form_driver(my_form, ch);
68+
break;
69+
} // switch
70+
} // while
7171

72-
//Un post form and free the memory
72+
// Un post form and free the memory
7373
unpost_form(my_form);
7474
free_form(my_form);
7575
free_field(field[0]);
7676
free_field(field[1]);
77-
}//main
77+
} // main

examples/hellounicode/source/helloUnicode.d

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** hello_unicode.d
1+
/**
22
*
33
* This is a demonstration of Unicode output with ncurses in D.
44
* The functionality of this code is otherwise identical to hello_world.d
@@ -12,8 +12,8 @@
1212
*
1313
* Modified by: Wyatt
1414
*/
15-
import std.string: toStringz;
16-
import core.stdc.locale; // Need setlocale()
15+
import std.string : toStringz;
16+
import core.stdc.locale; // Need setlocale()
1717
import deimos.ncurses.ncurses;
1818

1919
void main()
@@ -25,11 +25,12 @@ void main()
2525

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

28-
initscr(); //initialize the screen
29-
scope(exit) endwin(); //for the love of all that is holy, alway exit cleanly.
28+
initscr(); // initialize the screen
29+
scope(exit)
30+
endwin(); // for the love of all that is holy, alway exit cleanly.
3031

31-
printw(hello); //prints the char[] hello to the screen
32-
refresh(); //actually does the writing to the physical screen
32+
printw(hello); // prints the char[] hello to the screen
33+
refresh(); // actually does the writing to the physical screen
3334

34-
getch(); //gets a single character from the screen.
35+
getch(); // gets a single character from the screen.
3536
}
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** hello_world.d
1+
/**
22
*
33
* I'm assuming that you are starting here, so I've included
44
* lots of info. These build, so I won't explain everything over and over.
@@ -11,15 +11,16 @@
1111
*
1212
* Modified by: 1100110
1313
*/
14-
import std.string: toStringz;
14+
import std.string : toStringz;
1515
import deimos.ncurses;
1616

1717
void main()
18-
{ //toStringz returns immutable char* Which is what most of these
19-
//functions expect. I had to modify things a bit to get that to
20-
//work as nicely as it does.
21-
//D string d = "stuff" will never work with these functions.
22-
//they expect char* see below.
18+
{
19+
// toStringz returns immutable char*, which is what most of these
20+
// functions expect. I had to modify things a bit to get that to
21+
// work as nicely as it does.
22+
// D string d = "stuff" will never work with these functions.
23+
// they expect char* see below.
2324
immutable hello = toStringz("Hello ncurses World!\nPress any key to continue...");
2425

2526
/* D char[]s are not 0 terminated, so you'll probably want to do that manually
@@ -30,15 +31,16 @@ void main()
3031
* embedded 0's in the string already.
3132
*/
3233

33-
initscr(); //initialize the screen
34-
scope(exit) endwin(); //always exit cleanly
35-
printw(hello); //prints the char[] hello to the screen
36-
refresh(); //actually does the writing to the physical screen
34+
initscr(); // initialize the screen
35+
scope (exit)
36+
endwin(); // always exit cleanly
37+
printw(hello); // prints the char[] hello to the screen
38+
refresh(); // actually does the writing to the physical screen
3739

38-
getch(); //gets a single character from the screen.
39-
//here it is just used to hold the terminal open.
40+
getch(); // gets a single character from the screen.
41+
// here it is just used to hold the terminal open.
4042

41-
endwin(); //Routine to call before exiting, or leaving curses mode temporarily
42-
//failure to endwin() seems to clear all terminal history
43-
//as well as other bad things. just endwin().
43+
endwin(); // Routine to call before exiting, or leaving curses mode temporarily
44+
// failure to endwin() seems to clear all terminal history
45+
// as well as other bad things. just endwin().
4446
}

examples/keycode/source/keyCode.d

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//Modified by: 1100110
2-
import std.stdio: writefln;
2+
import std.stdio : writefln;
33
import deimos.ncurses.ncurses;
44

5-
65
void main()
76
{
87
int ch;

0 commit comments

Comments
 (0)