Recent

Author Topic: TextColor and StdOut  (Read 650 times)

Matze

  • Newbie
  • Posts: 1
TextColor and StdOut
« on: September 18, 2022, 01:48:20 pm »
Hello,
why does this dont work?

assign(FO, '');
rewrite(FO);
TextColor(Red);
write(FO,'some Text');

The TextColor is not set to red.
Can you help?
Thanks.

jamie

  • Hero Member
  • *****
  • Posts: 6133
Re: TextColor and StdOut
« Reply #1 on: September 18, 2022, 03:03:34 pm »
That looks like you need to use the CRT unit to start with.

Also, remove the Assign and Rewrite.

If you are trying to do terminal output, then you need to use Ansi Escape codes or whatever the terminal understands.

The only true wisdom is knowing you know nothing

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 1059
Re: TextColor and StdOut
« Reply #2 on: September 18, 2022, 08:56:52 pm »
You have to use assigncrt instead of assign if you want to use the functionality of the crt unit with it.

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: TextColor and StdOut
« Reply #3 on: September 19, 2022, 04:47:14 pm »
Something like so:
Code: Pascal  [Select][+][-]
  1. uses Crt;
  2. var
  3.   FO : Text;
  4. begin
  5.   AssignCrt(FO);
  6.   Rewrite(FO);
  7.   TextBackground(white);
  8.   ClrEol;
  9.   TextColor(Red);
  10.   WriteLn(FO,'Some text');
  11.   Close(FO);
  12. end.

Taken and adapted from the example in the manual for Assigncrt:
https://www.freepascal.org/docs-html/rtl/crt/assigncrt.html
« Last Edit: September 19, 2022, 04:56:11 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018