Recent

Author Topic: Colorizing text in the console  (Read 378 times)

acerm

  • Newbie
  • Posts: 2
Colorizing text in the console
« on: November 27, 2019, 01:02:06 pm »
Hello! Does anyone know how can I write colored text to the console?

I have a c ++ example that works, but I can't make it work on obj pascal

Code: Pascal  [Select]
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     std::cout << "\033[033;31m  red text" << std::endl;
  6.     return(0);
  7. }

Output:
red text

Obj pascal:
Code: Pascal  [Select]
  1. writeln('\033[033;31m  red text');
  2.  

Output:
\033[033;31m  red text

Thanks

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7613
Re: Colorizing text in the console
« Reply #1 on: November 27, 2019, 01:24:03 pm »
Change the C escapes like \033 to proper Pascal writeln syntax using # ?


acerm

  • Newbie
  • Posts: 2
Re: Colorizing text in the console
« Reply #2 on: November 27, 2019, 02:45:47 pm »
Thanks a lot marcov!
Now is working fine.

Code: Pascal  [Select]
  1. writeln(#27'[31mred text');

« Last Edit: November 27, 2019, 07:25:15 pm by acerm »

bee

  • Sr. Member
  • ****
  • Posts: 365
Re: Colorizing text in the console
« Reply #3 on: November 28, 2019, 04:42:07 am »
I've made ansiCRT unit for that purpose. You may take a look at it here.

Hope it helps. :)
-Bee-

A long time pascal lover.