- 1 year ago
How to enable ANSI escape sequences in command prompt on Windows 10 by Fortran code?
Enabling ANSI escape sequences in the Windows Command Prompt for output from Fortran code requires using specific escape sequences and configuring the console properly. Here's how you can achieve it:
Install the
winio
library for Fortran, which provides functions to enable ANSI escape sequences. You can find the library and installation instructions in the following repository: https://github.com/interkosmos/WinIOInclude the
winio
module in your Fortran code:fortranuse winio
Call the
winio_initialize
subroutine at the beginning of your code to initialize the library:fortrancall winio_initialize()
Use the escape sequences to modify the console output. For example, to change the text color to red, you can use the escape sequence
\x1B[31m
. Here's an example of printing colored text:fortranwrite(*, '(a)') '\x1B[31mThis is red text\x1B[0m'
In this example, the sequence
\x1B[31m
sets the text color to red, and\x1B[0m
resets the color back to the default.Finally, call the
winio_finalize
subroutine at the end of your code to clean up resources:fortrancall winio_finalize()
By following these steps, you should be able to enable ANSI escape sequences in the Windows Command Prompt for output from your Fortran code. Remember to link against the winio
library during compilation.