I would probably do something like this: const ansi_colors: array[0..7] of char = ('0', '4', '2', '6', '1', '5', '3', '7');
procedure PrintColor(fg, bg: byte; s: string); var tmp: string; begin tmp:=#27+'[0;3'+ansi_colors[fg]+';4'+ansi_colors[bg]+'m'+s+#27+'[0m'; writeln(tmp); end; begin PrintColor(2, 0, 'derp'); end. Easy enough to remember pascal style color numbers. -- Alexander Grotewohl https://dcclost.com ________________________________ From: fpc-devel <fpc-devel-boun...@lists.freepascal.org> on behalf of J. Gareth Moreton via fpc-devel <fpc-devel@lists.freepascal.org> Sent: Sunday, November 22, 2020 7:59 PM To: Ryan Joseph via fpc-devel <fpc-devel@lists.freepascal.org> Cc: J. Gareth Moreton <gar...@moreton-family.com> Subject: Re: [fpc-devel] Compiler message colour scheme I'm getting there. I keep getting distracted or lost though! Hardware failures don't help! I'm trying a different approach this time and writing a whitepaper like I've done with my more major changes for Free Pascal, so I can describe its uses and how it works etc. It can be updated of course, but it means I have something to refer to if I lose my way, and others can better add to the concept. In the case of that PrintColor example, I don't think it could be inlined, for example, due to the call to IntToStr, among other things (like if you call PrintColor with a non-constant actual parameter), but if IntToStr were a pure function as well (and there's no reason why it can't), then logically GenerateColorCode could easily be pure. I'm glad there's still interest in pure functions. It may be a while though, and I'm being tempted with a bounty and Patreon pledges to implement "static single assignment" into the Free Pascal Compiler. That will take some research to see if it's even possible and not prone to completely breaking things! First things first though, I've got a bug to fix in AArch64, and on the same platform, I'm almost finshed implementing the optimisation that turns division by a constant into a multiplication and shift. Gareth aka. Kit On 22/11/2020 21:37, Ryan Joseph via fpc-devel wrote: > >> On Nov 22, 2020, at 10:09 AM, J. Gareth Moreton via fpc-devel >> <fpc-devel@lists.freepascal.org> wrote: >> >> Personally I'd write the function as something like "function >> GenerateColorCode(codes: array of Byte): ansistring;", mostly in >> anticipation of pure functions, because then the compiler can just replace >> the call with the relevant string at compile time, but that's a long way off! > That would great. Hopefully this gets finished some day. > > Regards, > Ryan Joseph > > _______________________________________________ > fpc-devel maillist - fpc-devel@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > -- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel