Skip to content

Commit 2a58fae

Browse files
committed
review of simpleColor.d
1 parent c6d7f75 commit 2a58fae

File tree

5 files changed

+35
-157
lines changed

5 files changed

+35
-157
lines changed

examples/Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
DMD=rdmd -g -w --build-only -ofbin/$@ -L-lncursesw $^
1+
DMD=rdmd -g -w --build-only -ofbin/$@ -I../ -L-lncursesw $^
22

3-
all: helloUnicode helloWorld
3+
all: init helloUnicode helloWorld simpleColor simpleKey keyCode
4+
5+
init:
6+
@echo "building all examples..."
47

58
helloWorld: helloWorld.d
69
$(DMD)
@@ -14,5 +17,10 @@ simpleColor: simpleColor.d
1417
keyCode: keyCode.d
1518
$(DMD)
1619

20+
# TODO fix
21+
simpleKey: simpleKey.d
22+
$(DMD)
23+
1724
clean:
1825
@rm bin/*
26+
@echo "done."

examples/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ Here are a few examples to get you started.
55
The main site where these examples were originally found is here [tldp.org](http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/)
66
These examples need some work, but they should demonstrate that most everything is in working order.
77

8+
All of the files *should* be executable and set to link with ncursesw by default.
9+
If you have rdmd installed in /usr/bin/rdmd, then ./helloWorld.d should get you going!
10+
11+
if not, then make [filename], and the programs will be in ./bin/
12+
813
### Requirements:
914
- [rdmd](http://github.com/D-Programming-Language/tools)
1015
- ncursesw
1116

1217
### Files
18+
- helloWorld.d - a simple hello world example.
19+
- helloUnicode.d - a simple unicode example.
20+
- keyCode.d - returns the number code of the key you pressed.
21+
- simpleColor.d - a simple example that demonstrates color output.
1322

14-
23+
### TODO
24+
[ ] review, and fix anything that's broken.
25+
[ ] cosmetic alterations.
26+
[ ] add to travis.
27+
[ ] fix so that examples are compilable on Windows.
1528

1629
Again, please file any bugs that you come across.
1730
Even if you don't know if it is actually a bug, we appreciate the time.

examples/simpleColor.d

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#!/usr/bin/rdmd -L-lncursesw
22
//Modified by: 1100110
3-
import std.stdio: writeln;
4-
import std.string: toStringz;
3+
import std.conv: to;
4+
import std.stdio: writeln;
5+
import std.string: toStringz;
56
import deimos.ncurses.ncurses;
67

78

89
int main() {
9-
initscr(); //Start curses mode
10+
initscr();
11+
scope(failure) endwin();
12+
scope(exit) endwin();
1013

11-
if(has_colors() == false)
12-
{
14+
15+
if(has_colors() == false) {
1316
endwin();
1417
writeln("Your terminal does not support color... Goodbye");
1518
return 1;
@@ -19,17 +22,16 @@ int main() {
1922
init_pair(1, COLOR_RED, COLOR_BLACK);
2023

2124
attron(COLOR_PAIR(1));
22-
print_in_middle(stdscr, LINES/2, 0, 0, "Voila !!! In color... =)");
25+
print_in_middle(stdscr, "Voila !!! In color... =)", LINES/2, 0, 0,);
2326
attroff(COLOR_PAIR(1));
2427

2528
getch();
26-
endwin();
2729

2830
return 0;
2931
}
3032

3133

32-
void print_in_middle(WINDOW *win, int starty, int startx, int width, string str)
34+
void print_in_middle(WINDOW *win, string str, int starty = LINES/2, int startx=0, int width=0)
3335
{
3436
int length, x, y;
3537

@@ -48,7 +50,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width, string str)
4850

4951
//int already takes the floor, we can change temp to int.
5052
float temp = (width - str.length)/ 2;
51-
x = startx + cast(int)temp;
53+
x = startx + temp.to!int;
5254

5355
mvwprintw(win, y, x, "%s", toStringz(str));
5456

examples/simple_key.d

Lines changed: 0 additions & 86 deletions
This file was deleted.

examples/simple_spectrum.d

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)