How about colors and terminal graphics in std.format?

Damian Ziemba spam at dzfl.pl
Sun Mar 11 20:30:08 PDT 2012


On Monday, 12 March 2012 at 03:27:41 UTC, Damian Ziemba wrote:
> On Monday, 12 March 2012 at 02:52:15 UTC, 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
>>>
>>> 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?
>>
>> 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.
>>
>>> 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
>
> It could work.
> In my small framework I use version blocks and I use ansi 
> escape sequences for posix and SetConsoleTextAttribute for 
> windoze.
>
> Ofcourse there would be a need to create unified enumeration 
> with colors as they differ on those platforms too.
>
>
>                 public enum Font
> 		{
> 			Normal = 0,
> 			Underline = 0x8000,
> 			Reverse   = 0x4000,
> 		}
> 		
> 		public enum Color
> 		{
> 			Default = 0x0000,
> 			Blue  = 0x0001,
> 			Green = 0x0002,
> 			Aqua  = 0x0003,
> 			Red   = 0x0004,
> 			Purple= 0x0005,
> 			Yellow= 0x0006,
> 			Gray  = 0x0008,
> 			LightBlue  = 0x0009,
> 			LightGreen = 0x000A,
> 			LightAqua  = 0x000B,
> 			LightRed   = 0x000C,
> 			LightPurple= 0x000D,
> 		}
>
> Those are colors and font-attributes that I found to match both 
> Windows and Posix

Those numbers are for Windows btw :p


More information about the Digitalmars-d mailing list