Skip to content

Commit c873608

Browse files
authored
Merge pull request #29 from jaydg/examples_cleanup
Examples cleanup + new panels example
2 parents 350f147 + b471d8a commit c873608

File tree

57 files changed

+1409
-1130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1409
-1130
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
examples/*/bin
2+
examples/*/dub.selections.json
23

34
*.o
45
*.so

examples/COPYING

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

examples/README.md

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,45 @@
22

33
Here are a few examples to get you started.
44

5-
The main site where these examples were originally found is here [tldp.org](http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/)
6-
These examples need some work, but they should demonstrate that most everything is in working order.
5+
Most of these examples are part of the [NCURSES Programming HOWTO](http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/). The examples which were not taken from the HOWTO are marked with (N).
76

87
To run the examples, change to the specific directory and build and execute the example with "dub run".
98

10-
### Requirements:
11-
- [rdmd](http://github.com/D-Programming-Language/tools)
12-
- ncursesw
13-
14-
### Examples
15-
- helloWorld - a simple hello world example.
16-
- helloUnicode - a simple unicode example.
17-
- keyCode - returns the number code of the key you pressed.
18-
- simpleColor - a simple example that demonstrates color output.
19-
20-
### TODO
21-
[ ] review, and fix anything that's broken.
22-
[ ] cosmetic alterations.
23-
[ ] add to travis.
24-
[ ] fix so that examples are compilable on Windows.
9+
## Examples
10+
11+
### Basics
12+
- acs_vars - ACS variables example
13+
- hellounicode - a simple unicode example (N)
14+
- hello_world - a simple hello world example
15+
- key_code - returns the number code of the key you pressed
16+
- mouse_menu - A menu accessible by mouse
17+
- other_border - Shows usage of other border functions apart from box()
18+
- printbold - Gets a single character and displays it in bold (N)
19+
- printw_example - A very simple printw() example
20+
- simple_color - a simple example that demonstrates color output
21+
- simple_key - A menu accessible with keyboard UP, DOWN arrows
22+
- simplespectrum - Sample of 256-colour output (N)
23+
- temp_leave - Demonstrates temporarily leaving curses mode
24+
- win_border - Shows Creation of windows and borders
25+
- with_chgat - chgat() usage example
26+
27+
### Forms
28+
- form_attrib - Form attributes example
29+
30+
### Menus
31+
- menu_attrib - Usage of menu attributes
32+
- menu_scroll - Demonstrates scrolling capability of menus
33+
- menu_simple - A simple menu accessed by arrow keys
34+
35+
### Panels
36+
- panel_simple - A simple panel example
37+
- ptest - Panel test from PDCurses, shows moving, hiding and layering of panels (N)
38+
39+
40+
## TODO
41+
- [ ] review, and fix anything that's broken.
42+
- [ ] cosmetic alterations.
43+
- [ ] fix so that examples are compilable on Windows.
2544

2645
Again, please file any bugs that you come across.
2746
Even if you don't know if it is actually a bug, we appreciate the time.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"name": "chgat",
2+
"name": "acs_vars",
33
"description": "Example application for the D ncurses library",
44
"homepage": "https://github.com/D-Programming-Deimos/ncurses",
55
"authors": [
6-
"Jon \"ylixir\" Allen",
7-
"Dejan Lekic",
6+
"Pradeep Padala",
87
"Jude \"1100110\" Young"
98
],
109
"license": "ncurses",
@@ -13,5 +12,5 @@
1312
},
1413
"targetPath": "bin",
1514
"targetType": "executable",
16-
"targetName": "chgat"
15+
"targetName": "acs_vars"
1716
}

examples/acsvars/source/acsVars.d renamed to examples/acs_vars/source/acs_vars.d

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
#!/usr/bin/rdmd -L-lncurses
2-
import std.string: toStringz;
1+
import std.string : toStringz;
32
import deimos.ncurses.curses;
43

54
void main()
65
{
76
initscr();
8-
scope(exit) endwin();
9-
scope(failure) endwin();
10-
//Please note: you might want to maximize your terminal before you try to
11-
//run this. It does not check the size or enable scrolling.
12-
//In other word, if your terminal is <= 23 by 79, it will do weird things.
13-
//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.
1415

1516
printw(toStringz("Upper left corner "));
1617
addch(ACS_ULCORNER());

examples/form_attrib/dub.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"description": "Example application for the D ncurses library",
44
"homepage": "https://github.com/D-Programming-Deimos/ncurses",
55
"authors": [
6-
"Jon \"ylixir\" Allen",
7-
"Dejan Lekic",
6+
"Pradeep Padala",
87
"Jude \"1100110\" Young"
98
],
109
"license": "ncurses",
Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,77 @@
1-
#!/usr/bin/rdmd
21
import deimos.ncurses.form;
32
import std.string;
4-
//TODO fix
5-
pragma(lib, "ncursesw");
6-
pragma(lib, "form");
73

84
void main()
95
{
106
FIELD*[3] field;
11-
FORM* my_form;
7+
FORM* my_form;
128
int ch;
139

14-
//Initialize curses
10+
// Initialize curses
1511
initscr();
1612
start_color();
1713
cbreak();
1814
noecho();
1915
keypad(stdscr, true);
20-
scope(exit) endwin();
16+
scope (exit)
17+
endwin();
2118

22-
//Initialize a few color pairs
19+
// Initialize a few color pairs
2320
init_pair(1, COLOR_WHITE, COLOR_BLUE);
2421
init_pair(2, COLOR_WHITE, COLOR_BLUE);
2522

26-
//Initialize the fields
23+
// Initialize the fields
2724
field[0] = new_field(1, 10, 4, 18, 0, 0);
2825
field[1] = new_field(1, 10, 6, 18, 0, 0);
2926
field[2] = null;
3027

31-
//Set field options
32-
set_field_fore(field[0], COLOR_PAIR(1)); //Put the field with blue background
33-
set_field_back(field[0], COLOR_PAIR(2)); //and white foreground (characters
34-
//are printed in white
35-
field_opts_off(field[0], O_AUTOSKIP); //Don't go to next field when this
36-
//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
3734
set_field_back(field[1], A_UNDERLINE);
3835
field_opts_off(field[1], O_AUTOSKIP);
3936

40-
//Create the form and post it
37+
// Create the form and post it
4138
my_form = new_form(field.ptr);
4239
post_form(my_form);
4340
refresh();
4441

45-
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
4643
mvprintw(4, 10, toStringz("Value 1:"));
4744
mvprintw(6, 10, toStringz("Value 2:"));
4845
mvprintw(LINES - 2, 0, toStringz("Use UP, DOWN arrow keys to switch between fields"));
4946
refresh();
5047

51-
//Loop through to get user requests
52-
while_loop:
53-
while((ch = getch()) != KEY_F(1))
48+
// Loop through to get user requests
49+
while_loop: while ((ch = getch()) != KEY_F(1))
5450
{
55-
switch(ch)
51+
switch (ch)
5652
{
57-
case KEY_DOWN:
58-
//Go to the next field
59-
form_driver(my_form, REQ_NEXT_FIELD);
60-
//Go to the end of the present buffer
61-
//Leaves nicely at the last character
62-
form_driver(my_form, REQ_END_LINE);
63-
break;
64-
case KEY_UP:
65-
//Go to previous field
66-
form_driver(my_form, REQ_PREV_FIELD);
67-
form_driver(my_form, REQ_END_LINE);
68-
break;
69-
default:
70-
//If this is a normal character, it gets Printed
71-
form_driver(my_form, ch);
72-
break;
73-
}//switch
74-
}//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
7571

76-
//Un post form and free the memory
72+
// Un post form and free the memory
7773
unpost_form(my_form);
7874
free_form(my_form);
7975
free_field(field[0]);
8076
free_field(field[1]);
81-
}//main
77+
} // main
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"name": "printw",
2+
"name": "hello_world",
33
"description": "Example application for the D ncurses library",
44
"homepage": "https://github.com/D-Programming-Deimos/ncurses",
55
"authors": [
6-
"Jon \"ylixir\" Allen",
7-
"Dejan Lekic",
6+
"Pradeep Padala",
87
"Jude \"1100110\" Young"
98
],
109
"license": "ncurses",
@@ -13,5 +12,5 @@
1312
},
1413
"targetPath": "bin",
1514
"targetType": "executable",
16-
"targetName": "printw"
15+
"targetName": "hello_world"
1716
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
*
3+
* I'm assuming that you are starting here, so I've included
4+
* lots of info. These build, so I won't explain everything over and over.
5+
*
6+
* You will either need to use the makefile (now fixed)
7+
* or fix the import path manually.
8+
*
9+
* Also see http://d-programming-language.org/arrays.html for more info
10+
* on strings and char[]s
11+
*
12+
* Modified by: 1100110
13+
*/
14+
import std.string : toStringz;
15+
import deimos.ncurses;
16+
17+
void main()
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.
24+
immutable hello = toStringz("Hello ncurses World!\nPress any key to continue...");
25+
26+
/* D char[]s are not 0 terminated, so you'll probably want to do that manually
27+
* with hello ~= '\0';
28+
* char[] hello = ['h','e','l','l','o',' ','w','o','r','l','d','!'];
29+
* hello ~= '\0';
30+
* Or use toStringz() like the example above. just make sure there are no
31+
* embedded 0's in the string already.
32+
*/
33+
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
39+
40+
getch(); // gets a single character from the screen.
41+
// here it is just used to hold the terminal open.
42+
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().
46+
}

examples/hellounicode/dub.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"description": "Example application for the D ncurses library",
44
"homepage": "https://github.com/D-Programming-Deimos/ncurses",
55
"authors": [
6-
"Jon \"ylixir\" Allen",
7-
"Dejan Lekic",
8-
"Jude \"1100110\" Young"
6+
"Wyatt"
97
],
108
"license": "ncurses",
119
"dependencies": {

0 commit comments

Comments
 (0)