DUB colored output proposal/showcase

Uknown sireeshkodali1 at gmail.com
Fri Jun 8 15:34:06 UTC 2018


On Friday, 8 June 2018 at 13:51:05 UTC, gdelazzari wrote:
> On Friday, 8 June 2018 at 13:38:59 UTC, Steven Schveighoffer 
> wrote:
>> Looks excellent! Two thumbs up from me. Is it cross-platform?
>>
>> Note on some platforms (ahem, Macos) the background is white, 
>> so this should be correctly colored for that possibility.
>>
>> -Steve
>
> At the moment it's "probably" Linux-only, but that's because I 
> only wanted a proof of concept and I worked on it on my Linux 
> installation. I imported this library/Dub package 
> https://github.com/yamadapc/d-colorize and just used it. Which, 
> by the way, it's no-good at the moment since I saw that Dub 
> doesn't use Dub packages itself - probably because, otherwise, 
> you don't have a way to easily compile it without Dub itself, I 
> guess :P so I'll need to either write my custom color 
> outputting code within Dub's source or just import that library.
>
> Of course making it cross-platform is a mandatory thing to me. 
> Windows also needs some specific stuff to output colors, as you 
> can see in the library I linked, so there are definitely some 
> things to do to support all the platforms. I may even take a 
> look at how DMD itself outputs colored output, I guess it will 
> be nice to keeps things consistent.
>
> As for MacOS having a different background... I don't really 
> own a Mac nor I have ever used one before, so I don't even know 
> how tools usually output their colored text on it. At the 
> moment it just sets the foreground color to 
> green/yellow/blue/whatever, without changing the background, if 
> that was your concern. If you meant that yellow-on-white is not 
> readable... well... I guess so. Maybe two different color 
> palettes should be used? IDK, as I said I never used a Mac 
> before so I don't really know how other tools handle this, 
> maybe if some Mac user could help on this, it would be great.
>
> Thanks for the appreciation by the way!

I love it! I have very little experience with terminal colours, 
but as far as colourizing text on POSIX its fairly easy. You just 
need to emit the right ANSI escape sequences [0]. This is what 
the colorize-d library does.. For Windows before Windows 10, 
things are more messy. You need to use `handle`s, to get the 
current state and then correctly set the colours. The real hard 
part here is adjusting the colour scheme based on the terminal 
background colour.

[0]: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors


More information about the Digitalmars-d mailing list