On 03/11/2012 10:52 PM, Andrei Alexandrescu wrote:
On 3/11/12 9:16 PM, Chad J wrote:
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

...

If there's interest, I might take a stab at it.

So, would this sort of thing make it in?

I don't know, seems interesting but I wonder how portable that could be.
Probably I'd define a more general means a la %q to mean "send a control
sequence" and then would define control sequences as functions or
constants.


My intent is to make it easy to use. If it's not easy to use, I wouldn't use it. If someone wants low-level, they can help themselves to curses. It should be possible to do this reasonably portably. I know Python was able to do this well on both my Linux install and my Windows install.

If other OSes have known issues, it can be solved by using either better feature detection or simply version()'ing out the code that inserts control sequences on those OSes.

My plan would be something like this:

version(Windows)
{
        // There is only one possible way to do this:
        // Call WinAPI functions.
}
else version(Posix)
{
        Look for the terminfo database.
        Check $TERMINFO,
                then ~/.terminfo,
                then /usr/share/terminfo,
                then /usr/lib/terminfo,
                then /etc/terminfo,
                then give up if not found.
        if ( terminfo found )
        {
                query terminfo for terminal capabilities and sequences
                emit sequences as appropriate
        }
        else
        {
                Don't output control sequences.
        }

        // Using <term.h> might be easier,
        //   but I don't know how portable it is. :/
}
else
{
        // Don't output control sequences.
}


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).

Since recently the Phobos doc build is meant to be driven from the site
build. I'll fix the standalone thing because it's useful too, just I
don't know when.



Andrei

Alright, thanks!

Btw, did we ever get a git repo that includes the release files for D and tracks dmd/druntime/phobos as sub-repositories at the correct paths? Such a thing would be really useful for me if I want to feel like working on this stuff very much. I don't think I have the ability to update DMD documentation from git right now.

Reply via email to