12.03.2012 4:16, Chad J пишет:
I remember doing colored terminal output in Python. It was pretty
nifty, and allows for some slick CLI design. I think D can do better
by putting it in the standard library.
I was thinking something along the lines of this:
http://www.chadjoan.com/d/dmd.2.058/html/d/phobos/std_format.html
I figure it would probably be easy to get some of the basics down.
More advanced stuff would probably involve messing with terminfo or
<term.h>. Windows' (terribly bad) command prompt can have some of
these capabilities implemented too, but in a roundabout way because
Windows defines API functions that need to be called to affect
terminal graphics and coloring. I figure that would require the help
of the I/O routines if I were to work on that.
If there's interest, I might take a stab at it.
So, would this sort of thing make it in?
Oh, on an unrelated note, Phobos' documentation make target is quite
broken:
blahblah/dmd.git/src/phobos $ make -fposix.mak html
make: *** No rule to make target
`../web/phobos-prerelease/index.html', needed by `html'. Stop.
I examined the makefile and concocted this line of bash that
constructs my desired html file:
dmd -m32 -d -c -o- -version=StdDdoc -I../druntime/import std/format.d
std.ddoc -Dfstd_format.html
and copied std.ddoc from a release version of dmd (it's in src/phobos).
This is not exactly what you mean, but related. There are some graphics
manipulation functions in dmc runtime: http://digitalmars.com/rtl/disp.html
These are accessible from D, but there's no header, so you'll need to
declare them manually in your program.
Here's a translated example of outputting a red text:
//
extern( C ) void disp_open();
extern( C ) int disp_getattr();
extern( C ) void disp_setattr( int attr );
extern( C ) int disp_printf( char * format, ... );
extern( C ) void disp_close();
int main() {
int attr;
disp_open();
attr = disp_getattr();
disp_setattr(0x7C);
disp_printf( "hello world!\0".dup.ptr );
disp_setattr(attr);
disp_printf( "\r\n\0".dup.ptr );
disp_close();
return 0;
}
//