> note that constants related to the windows 10 virtual terminal are not 
> defined in FPC yet.
Correction:  They were not added as of 3.0.4.rc1, they have been added now, not 
sure exactly which version they are/were included.

James

-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of 
James Richters
Sent: Wednesday, January 10, 2018 6:14 AM
To: 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org>
Subject: Re: [fpc-pascal] Problems with writing to console

If all you want is colors and simple positioning,  you could use Ansi escape 
codes instead of the CRT unit, then you would not have the issue with 
redirection and CRT not being supported.  Windows 10 builds after 10586 have 
re-enabled Ansi escape codes, however after build 14393 it is no longer enabled 
for executables by default.  It can be enabled with SetConsoleMode();   note 
that constants related to the windows 10 virtual terminal are not defined in 
FPC yet.  Here's a FPC example:

Const
   ENABLE_VIRTUAL_TERMINAL_PROCESSING =$0004;
Var dwOriginalOutMode, dwRequestedOutModes, dwRequestedInModes, dwOutMode:Dword;
Begin
GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), dwOriginalOutMode);
dwRequestedOutModes := ENABLE_VIRTUAL_TERMINAL_PROCESSING;
dwOutMode := dwOriginalOutMode OR dwRequestedOutModes;
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), dwOutMode);
Writeln('^<ESC^>[30m ',#27,'[30mBlack',#27,'[0m (black)');
Writeln('^<ESC^>[31m ',#27,'[31mRed',#27,'[0m');
Writeln('^<ESC^>[32m ',#27,'[32mGreen',#27,'[0m');
Writeln('^<ESC^>[33m ',#27,'[33mYellow',#27,'[0m');
Writeln('^<ESC^>[34m ',#27,'[34mBlue',#27,'[0m');
Writeln('^<ESC^>[35m ',#27,'[35mMagenta',#27,'[0m');
Writeln('^<ESC^>[36m ',#27,'[36mCyan',#27,'[0m');
Writeln('^<ESC^>[37m ',#27,'[37mWhite',#27,'[0m');
Readln;
End.

See full example attached.    Of course the program is intended to run on 
versions of random versions of windows, many of which had Ansi capability 
disabled, then this would not be a potential solution.  Windows 3.11, Windows 
95 and Windows 98 had Ansi capability, but Windows 2000, Windows XP, Widnows 7, 
and Windows 10 before build 10586 did not, then Windows 10 build 10586 had Ansi 
capability again by default until Build 14393 where it still had Ansi 
Capability but not turned on by default anymore.

James

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to