On Friday, 8 June 2018 at 15:34:06 UTC, Uknown wrote:
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

Sure, I sort of know how that works, I did some stuff some time ago. Also, regarding Windows, the colorize-d library already handles what you described. I think I'll simply take the source of colorize-d and copy-paste the files in the Dub source, as I saw they've done with some parts of Vibe.d in order to avoid having to fetch Dub packages while compiling Dub itself.

I would love to help you on this. Is there anything in particular you need help with?

Actually, it's not a difficult task. But, being a bit of a perfectionst, I already spotted the possibility of writing a separate module handling all the terminal output, in order to better separate things. At the moment Dub uses the log module from Vibe.d (as I wrote before, which it seems they've just copy-pasted in dub/internal/vibecompat/core/log.d) to print stuff to the terminal, I think replacing it with a module that handles colors and "tags" like in the screenshots I attacched would be the best option. But in order to do something like this cleanly we should first define well how to structure the output and thus the module handling it. Also documenting stuff a bit. Then we'll need to replace all the calls to logInfo, logDiagnostic, logError, etc... in the entire codebase :P

A quicker option is to just leave the log calls there, add the escape sequences in order to color the wanted words (as it's currently done in the proof-of-concept) and then fix the Vibe.d log module to handle colors on Windows with the same "workaround" that colorize-d uses. That's a faster way indeed, but a bit dirty IMHO. Also, to handle different color schemes (for MacOS/white background terminals) it may become a mess.

So, having a module which handles all the terminal output seems the best option to me, if we want to do stuff cleanly. The main problem is to define its requirements, how it should interface with the rest of the code, how to structure it, etc... then writing the code is the simplest part, as always. I can handle this by myself, but if anyone wants to help that would be really appreciated, especially on planning how to structure the changes. Maybe we can discuss about the implementation on IRC or some other platform?

Reply via email to