[fpc-devel] Compiler message colour scheme

Ryan Joseph genericptr at gmail.com
Sun Nov 22 17:58:29 CET 2020



> On Nov 22, 2020, at 9:29 AM, Florian Klämpfl via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> 
> Because I have no Mac so I couldn't test it.

I see. It's this easy. 

const
  ANSI_FORE_BLACK           = 30;
  ANSI_FORE_RED             = 31;
  ANSI_FORE_GREEN           = 32;
  ANSI_FORE_YELLOW          = 33;
  ANSI_FORE_BLUE            = 34;
  ANSI_FORE_MAGENTA         = 35;
  ANSI_FORE_CYAN            = 36;
  ANSI_FORE_WHITE           = 37;
  ANSI_FORE_RESET           = 39;

  ANSI_BACK_BLACK           = 40;
  ANSI_BACK_RED             = 41;
  ANSI_BACK_GREEN           = 42;
  ANSI_BACK_YELLOW          = 43;
  ANSI_BACK_BLUE            = 44;
  ANSI_BACK_MAGENTA         = 45;
  ANSI_BACK_CYAN            = 46;
  ANSI_BACK_WHITE           = 47;
  ANSI_BACK_RESET           = 49;

  ANSI_STYLE_BOLD           = 1;
  ANSI_STYLE_ITALIC         = 3;
  ANSI_STYLE_UNDERLINE      = 4;
  ANSI_STYLE_BLINK          = 5;


procedure PrintColor(codes: array of byte; str: ansistring);
var
  attrs: string;
  code: byte;
begin
  attrs := '';
  for code in codes do
    begin
      if attrs <> '' then
        attrs += ';';
      attrs += IntToStr(code);
    end;
  writeln(#&033,'[',attrs,'m',str,#&033,'[',0,'m');
end;

// prints a blinking, bold red text on a white background
PrintColor([ANSI_BACK_WHITE, ANSI_FORE_RED, ANSI_STYLE_BLINK, ANSI_STYLE_BOLD], 'Hello World');

Regards,
	Ryan Joseph



More information about the fpc-devel mailing list