Skip to content

Commit 5e454c5

Browse files
committed
simplePanel.d, printw.d
1 parent 0255cbd commit 5e454c5

File tree

4 files changed

+87
-43
lines changed

4 files changed

+87
-43
lines changed

examples/Makefile

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

3-
all: init helloUnicode helloWorld simpleColor simpleKey simpleSpectrum keyCode chgat acsVars printw.d
3+
all: init helloUnicode helloWorld simpleColor simpleKey simpleSpectrum keyCode chgat acsVars printw simplePanel
44

55
init:
66
@echo "building all examples..."
@@ -14,7 +14,7 @@ helloUnicode: helloUnicode.d
1414
simpleColor: simpleColor.d
1515
$(DC)
1616

17-
keyCode: keyCode.d
17+
simplePanel: simplePanel.d
1818
$(DC)
1919

2020
# TODO fix
@@ -27,13 +27,18 @@ simpleSpectrum: simpleSpectrum.d
2727
acsVars: acsVars.d
2828
$(DC)
2929

30-
3130
chgat: chgat.d
3231
$(DC)
3332

33+
keyCode: keyCode.d
34+
$(DC)
35+
3436
tempLeave: tempLeave.d
3537
$(DC)
3638

39+
printw: printw.d
40+
$(DC)
41+
3742
clean:
3843
@rm bin/*
3944
@echo "done."

examples/panel_simple.d

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

examples/printw.d

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/rdmd -L-lncurses
2+
//Modified by: 1100110
3+
4+
import std.conv: to;
5+
import std.string;
6+
import deimos.ncurses.ncurses;
7+
8+
void main()
9+
{
10+
immutable mesg = "Just a string...";
11+
int row, col;
12+
initscr();
13+
14+
scope(failure) endwin();
15+
scope(exit) endwin();
16+
17+
getmaxyx(stdscr, row, col);
18+
19+
//print the message at the center of the screen
20+
mvprintw(row/2, ((col-(mesg.length - 1))/2).to!int, "%s", toStringz(mesg));
21+
22+
//Did you notice? there is a '%s' not toStringified.
23+
24+
auto rowcol = "This screen has %d rows and %d columns\n".toStringz;
25+
mvprintw(row-2, 0, rowcol, row+1, col+1);
26+
27+
printw(toStringz("Try resizing your window(if possible) and then run this program again"));
28+
refresh();
29+
30+
getch();
31+
}

examples/simplePanel.d

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env rdmd
2+
3+
import deimos.ncurses.panel;
4+
5+
pragma(lib, "ncurses");
6+
pragma(lib, "panel");
7+
8+
int main()
9+
{
10+
WINDOW*[3] my_wins;
11+
PANEL*[3] my_panels;
12+
immutable lines = 10, cols = 40, y = 2, x = 4;
13+
14+
initscr();
15+
//scope(failure) endwin();
16+
scope(exit) endwin();
17+
18+
cbreak();
19+
noecho();
20+
21+
/* Create windows for the panels */
22+
my_wins[0] = newwin(lines, cols, y, x);
23+
my_wins[1] = newwin(lines, cols, y + 1, x + 5);
24+
my_wins[2] = newwin(lines, cols, y + 2, x + 10);
25+
26+
/*
27+
* Create borders around the windows so that you can see the effect
28+
* of panels
29+
*/
30+
foreach(i; 0..3)
31+
box(my_wins[i], 0, 0);
32+
33+
/* Attach a panel to each window */ /* Order is bottom up */
34+
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
35+
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
36+
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
37+
38+
/* Update the stacking order. 2nd panel will be on top */
39+
update_panels();
40+
41+
/* Show it on the screen */
42+
doupdate();
43+
44+
getch();
45+
46+
return 0;
47+
}
48+

0 commit comments

Comments
 (0)