On 10/23/2012 03:56 PM, Philippe Sigaud wrote:
writefln("The %c(red,white)(widgetometer%) is a device formeasuring"); //
for writing red on white

Would something like the following be possible?

// col is a string-accepting function that returns a correctly formatted string
// red and white are from a general Color enum
alias col!(Color.red, Color.white) rw;

writeln("The ", rw("widgetometer"), " is a device for measuring...");

Nope. Windows requires function calls to do color formatting. It does not use escape sequences.

That said, it is always possible to scan all text about to be sent off to Windows and look for escape sequences, then reinterpret them as WinAPI coloring calls. The difficulty then is getting the "rw" construct above to know if it should emit escape sequences or not: the text it creates might eventually be bound for a file, a network socket, or some buffer in memory, but not a terminal. If it's heading for a terminal it has to know which one because they might use different escape sequences. So there always has to be some way of contextualizing the color formatting to its destination so that it can select the right form of output, including no formatting if its inappropriate for the destination.

Also, it doesn't nest. It should be possible to push/pop terminal attributes in mid-string.

Reply via email to