Skip to content

Commit 333c0db

Browse files
committed
Added more comments, and Added a few more structs...
and two 'experimental' functions. Also rearranged things to better match curses.h
1 parent 0a48355 commit 333c0db

File tree

1 file changed

+109
-81
lines changed

1 file changed

+109
-81
lines changed

curses.d

Lines changed: 109 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
* and: Eric S. Raymond <[email protected]> *
3232
* and: Thomas E. Dickey 1996-on *
3333
****************************************************************************/
34-
/* $Id: curses.h.in,v 1.215 2010/04/29 09:46:38 tom Exp $ */
3534

35+
/* $Id: curses.h.in,v 1.215 2010/04/29 09:46:38 tom Exp $ */
3636
module curses;
3737

38-
39-
4038
/*
4139
* We need FILE, etc. Include this before checking any feature symbols.
4240
*/
43-
import std.c.stddef;
4441
import std.c.stdio;
45-
import std.c.stdarg;
46-
//public import unctrl;
42+
import std.c.stddef; /* we want wchar_t */
43+
import std.c.stdarg; /* we need va_list */
44+
45+
//#include <ncursesw/unctrl.h>
46+
public import unctrl;
4747

4848
//TODO check if needed... I don't have a windows machine...
4949
version(Win32)
@@ -76,19 +76,58 @@ alias chtype attr_t;
7676
alias int OPTIONS;
7777
alias void SCREEN;
7878

79-
/* global variables */
80-
__gshared WINDOW* stdscr;
81-
__gshared WINDOW* curscr;
82-
__gshared WINDOW* newscr;
83-
__gshared char ttytype[];
84-
__gshared int COLORS;
85-
__gshared int COLOR_PAIRS;
86-
__gshared int LINES;
87-
__gshared int COLS;
88-
__gshared int TABSIZE;
89-
__gshared int ESCDELAY;
90-
__gshared chtype acs_map[256];
9179

80+
/* attributes */
81+
//Thank you, Dejan Lekic, dejan.lekic @ (gmail.com || kcl.ac.uk)
82+
immutable ubyte NCURSES_ATTR_SHIFT = 8;
83+
84+
chtype NCURSES_BITS(uint mask, ubyte shift)
85+
{ return (mask << (shift + NCURSES_ATTR_SHIFT)); }
86+
87+
immutable enum :chtype
88+
{
89+
A_NORMAL = (1u - 1u),
90+
A_ATTRIBUTES = NCURSES_BITS(~(1u - 1u),0),
91+
A_CHARTEXT = (NCURSES_BITS(1u,0) - 1u),
92+
A_COLOR = NCURSES_BITS(((1u) << 8) - 1u,0),
93+
A_STANDOUT = NCURSES_BITS(1u,8),
94+
A_UNDERLINE = NCURSES_BITS(1u,9),
95+
A_REVERSE = NCURSES_BITS(1u,10),
96+
A_BLINK = NCURSES_BITS(1u,11),
97+
A_DIM = NCURSES_BITS(1u,12),
98+
A_BOLD = NCURSES_BITS(1u,13),
99+
A_ALTCHARSET = NCURSES_BITS(1u,14),
100+
A_INVIS = NCURSES_BITS(1u,15),
101+
A_PROTECT = NCURSES_BITS(1u,16),
102+
A_HORIZONTAL = NCURSES_BITS(1u,17),
103+
A_LEFT = NCURSES_BITS(1u,18),
104+
A_LOW = NCURSES_BITS(1u,19),
105+
A_RIGHT = NCURSES_BITS(1u,20),
106+
A_TOP = NCURSES_BITS(1u,21),
107+
A_VERTICAL = NCURSES_BITS(1u,22),
108+
109+
/*
110+
* X/Open attributes. In the ncurses implementation, they are identical to the
111+
* A_ attributes.
112+
*/
113+
WA_ATTRIBUTES = A_ATTRIBUTES,
114+
WA_NORMAL = A_NORMAL,
115+
WA_STANDOUT = A_STANDOUT,
116+
WA_UNDERLINE = A_UNDERLINE,
117+
WA_REVERSE = A_REVERSE,
118+
WA_BLINK = A_BLINK,
119+
WA_DIM = A_DIM,
120+
WA_BOLD = A_BOLD,
121+
WA_ALTCHARSET = A_ALTCHARSET,
122+
WA_INVIS = A_INVIS,
123+
WA_PROTECT = A_PROTECT,
124+
WA_HORIZONTAL = A_HORIZONTAL,
125+
WA_LEFT = A_LEFT,
126+
WA_LOW = A_LOW,
127+
WA_RIGHT = A_RIGHT,
128+
WA_TOP = A_TOP,
129+
WA_VERTICAL = A_VERTICAL
130+
}
92131

93132

94133
immutable enum :chtype
@@ -105,6 +144,21 @@ immutable enum :chtype
105144
}
106145

107146

147+
/* global variables */
148+
__gshared WINDOW* stdscr;
149+
__gshared WINDOW* curscr;
150+
__gshared WINDOW* newscr;
151+
__gshared char ttytype[];
152+
__gshared int COLORS;
153+
__gshared int COLOR_PAIRS;
154+
__gshared int LINES;
155+
__gshared int COLS;
156+
__gshared int TABSIZE;
157+
__gshared int ESCDELAY;
158+
__gshared chtype acs_map[256];
159+
160+
161+
108162
/* acs symbols */
109163
///I couldn't make it perfect, this is the best that I have come up with...
110164
///Instead of calling ACS_VAR, you use ACS_VAR().
@@ -244,6 +298,20 @@ immutable int _NOCHANGE = -1;
244298
*/
245299
immutable int _NEWINDEX = -1;
246300

301+
/*
302+
* cchar_t stores an array of CCHARW_MAX wide characters. The first is
303+
* normally a spacing character. The others are non-spacing. If those
304+
* (spacing and nonspacing) do not fill the array, a null L'\0' follows.
305+
* Otherwise, a null is assumed to follow when extracting via getcchar().
306+
*/
307+
immutable size_t CCHARW_MAX = 5;
308+
309+
struct cchar_t
310+
{
311+
attr_t attr;
312+
wchar_t chars[CCHARW_MAX];
313+
}
314+
247315
struct WINDOW
248316
{
249317
short cury, curx;
@@ -282,20 +350,33 @@ struct WINDOW
282350
cchar_t bkgrnd;
283351
}
284352

285-
/*
286-
* cchar_t stores an array of CCHARW_MAX wide characters. The first is
287-
* normally a spacing character. The others are non-spacing. If those
288-
* (spacing and nonspacing) do not fill the array, a null L'\0' follows.
289-
* Otherwise, a null is assumed to follow when extracting via getcchar().
290-
*/
291-
immutable size_t CCHARW_MAX = 5;
353+
struct _nc_event
354+
{
355+
int type;
356+
union data
357+
{
358+
long timeout_msec; /* _NC_EVENT_TIMEOUT_MSEC */
359+
struct fev
360+
{
361+
uint flags;
362+
int fd;
363+
uint result;
364+
} /* _NC_EVENT_FILE */
365+
}
366+
}
292367

293-
struct cchar_t
368+
369+
struct _nc_eventlist
294370
{
295-
attr_t attr;
296-
wchar_t chars[CCHARW_MAX];
371+
int count;
372+
int result_flags; /* _NC_EVENT_TIMEOUT_MSEC or _NC_EVENT_FILE_READABLE */
373+
_nc_event* events[1];
297374
}
298375

376+
int wgetch_events(WINDOW* win, _nc_eventlist* nc); /* experimental */
377+
int wgetnstr_events(WINDOW* win, char* str, int one, _nc_eventlist* nc);/* experimental */
378+
379+
299380
/*
300381
* Function prototypes. This is the complete X/Open Curses list of required
301382
* functions. Those marked `generated' will have sources generated from the
@@ -922,59 +1003,6 @@ void getbegyx(U:WINDOW*, T: int)(U win, ref T y, ref T x)
9221003
}
9231004

9241005

925-
/* attributes */
926-
927-
//Thank you, Dejan Lekic, dejan.lekic @ (gmail.com || kcl.ac.uk)
928-
immutable ubyte NCURSES_ATTR_SHIFT = 8;
929-
930-
chtype NCURSES_BITS(uint mask, ubyte shift)
931-
{ return (mask << (shift + NCURSES_ATTR_SHIFT)); }
932-
933-
immutable enum :chtype
934-
{
935-
A_NORMAL = (1u - 1u),
936-
A_ATTRIBUTES = NCURSES_BITS(~(1u - 1u),0),
937-
A_CHARTEXT = (NCURSES_BITS(1u,0) - 1u),
938-
A_COLOR = NCURSES_BITS(((1u) << 8) - 1u,0),
939-
A_STANDOUT = NCURSES_BITS(1u,8),
940-
A_UNDERLINE = NCURSES_BITS(1u,9),
941-
A_REVERSE = NCURSES_BITS(1u,10),
942-
A_BLINK = NCURSES_BITS(1u,11),
943-
A_DIM = NCURSES_BITS(1u,12),
944-
A_BOLD = NCURSES_BITS(1u,13),
945-
A_ALTCHARSET = NCURSES_BITS(1u,14),
946-
A_INVIS = NCURSES_BITS(1u,15),
947-
A_PROTECT = NCURSES_BITS(1u,16),
948-
A_HORIZONTAL = NCURSES_BITS(1u,17),
949-
A_LEFT = NCURSES_BITS(1u,18),
950-
A_LOW = NCURSES_BITS(1u,19),
951-
A_RIGHT = NCURSES_BITS(1u,20),
952-
A_TOP = NCURSES_BITS(1u,21),
953-
A_VERTICAL = NCURSES_BITS(1u,22),
954-
955-
/*
956-
* X/Open attributes. In the ncurses implementation, they are identical to the
957-
* A_ attributes.
958-
*/
959-
WA_ATTRIBUTES = A_ATTRIBUTES,
960-
WA_NORMAL = A_NORMAL,
961-
WA_STANDOUT = A_STANDOUT,
962-
WA_UNDERLINE = A_UNDERLINE,
963-
WA_REVERSE = A_REVERSE,
964-
WA_BLINK = A_BLINK,
965-
WA_DIM = A_DIM,
966-
WA_BOLD = A_BOLD,
967-
WA_ALTCHARSET = A_ALTCHARSET,
968-
WA_INVIS = A_INVIS,
969-
WA_PROTECT = A_PROTECT,
970-
WA_HORIZONTAL = A_HORIZONTAL,
971-
WA_LEFT = A_LEFT,
972-
WA_LOW = A_LOW,
973-
WA_RIGHT = A_RIGHT,
974-
WA_TOP = A_TOP,
975-
WA_VERTICAL = A_VERTICAL
976-
}
977-
9781006

9791007
/*
9801008
* Pseudo-character tokens outside ASCII range. The curses wgetch() function

0 commit comments

Comments
 (0)