Jump to page: 1 25  
Page
Thread overview
How about colors and terminal graphics in std.format?
Mar 12, 2012
Chad J
Mar 12, 2012
Damian Ziemba
Mar 12, 2012
Chad J
Mar 12, 2012
James Miller
Mar 12, 2012
Damian Ziemba
Mar 12, 2012
Damian Ziemba
Mar 12, 2012
Adam D. Ruppe
Mar 12, 2012
Chad J
Mar 12, 2012
Damian Ziemba
Mar 12, 2012
Damian Ziemba
Mar 13, 2012
Kevin Cox
Mar 13, 2012
Damian Ziemba
Mar 13, 2012
Chad J
Mar 12, 2012
Adam D. Ruppe
Mar 12, 2012
Chad J
Mar 12, 2012
Adam D. Ruppe
Mar 12, 2012
Mantis
Mar 12, 2012
H. S. Teoh
Mar 12, 2012
Jacob Carlborg
Mar 12, 2012
H. S. Teoh
Mar 13, 2012
Chad J
Mar 13, 2012
James Miller
Mar 13, 2012
Chad J
Mar 13, 2012
Chad J
Mar 13, 2012
James Miller
Mar 13, 2012
Chad J
Mar 13, 2012
James Miller
Mar 13, 2012
Chad J
Mar 13, 2012
James Miller
Mar 13, 2012
Sean Cavanaugh
Mar 13, 2012
Christian Manning
Mar 13, 2012
Chad J
Mar 13, 2012
Christian Manning
Mar 13, 2012
H. S. Teoh
Mar 13, 2012
James Miller
Mar 13, 2012
H. S. Teoh
Mar 13, 2012
Chad J
Mar 13, 2012
Jacob Carlborg
Mar 13, 2012
Christian Manning
Mar 13, 2012
Jacob Carlborg
Mar 13, 2012
Christian Manning
March 12, 2012
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).

March 12, 2012
On 12-03-2012 03:16, 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.

There is!

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


-- 
- Alex
March 12, 2012
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
March 12, 2012
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

Some basic stuff like Colors can be portable.
I can share my work if somebody is interested.

Best regards,
Damian Ziemba

March 12, 2012
On 12-03-2012 03:52, 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.

It works for .NET: http://msdn.microsoft.com/en-us/library/system.consolecolor.aspx

This is implemented across all platforms in Mono.

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


-- 
- Alex
March 12, 2012
One concern I have with this is format() creates a
string, which isn't necessarily output; color is
a thing of output.

The unix implementation will use the ansi escape
sequences, surely, which isn't correct almost
anywhere else.

Of course, you could choose to not use these
special specifiers, and put a note in the
documentation explaining what it is, so
not a big deal... but I just think it is
somewhat wrong to put special control
sequences in the middle of a regular string
that might be used anywhere.
March 12, 2012
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;
}
//
March 12, 2012
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.
March 12, 2012
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

March 12, 2012
On 03/11/2012 11:05 PM, Adam D. Ruppe wrote:
> One concern I have with this is format() creates a
> string, which isn't necessarily output; color is
> a thing of output.
>
> The unix implementation will use the ansi escape
> sequences, surely, which isn't correct almost
> anywhere else.
>

I was kind of intending to /not/ do that, for exactly the reasons you mention.  ASCII escape sequences should work anyways.  I don't think anyone will panic if I waste a byte or two for every 3+ on fairly rare coloring/gfx operations.  And then there's always terminfo in the long picture.

> Of course, you could choose to not use these
> special specifiers, and put a note in the
> documentation explaining what it is, so
> not a big deal... but I just think it is
> somewhat wrong to put special control
> sequences in the middle of a regular string
> that might be used anywhere.

The primary intent of this is to be used with writefln or any other routines that will be writing to the terminal.

That this can emit escape sequences to other targets is a consequence of std.format being abstracted from the I/O routines.  I think it is fine.  I doubt people will put color formatting into strings that they know will not end up on a terminal.  And if they don't realize that limitation, then perhaps I should change the way it's documented so that it's /really obvious/ that the resulting strings will only colorize on process's attached terminal, and produce gobbledygook otherwise.

« First   ‹ Prev
1 2 3 4 5