In more recent versions of Windows 10, the Command Prompt has been enhanced to
understand ANSI escape sequences. Indeed, I've seen the gfortran compiler,
as installed by
equation.com's Windows installer, change the foreground and
background colors of the command prompt window when it generates error
messages. I wrote a little program to try it out, but it failed to do what
I expected it to do. I googled the issue, and ran across a little test
program that also failed to do what I expected.
My test program:
PROGRAM TestColor
WRITE (6,'(A)') 'Hello'//CHAR(27)//'[38;2;255;255;255m' ! set foreground color to bright white
WRITE (6,'(A)') CHAR(27)//'[48;2;128;0;0m'//'World' ! set background color to dark red
END PROGRAM TestColor
produces the output:
Hello←[38;2;255;255;255m
←[48;2;128;0;0mWorld
with no change in colors. [N.B. Windows has its own "Color" program, which
I discovered the hard way when I just happened to use the same name for my
test program, and it behaved nothing like what I written, until I invoked it
with .\Color to avoid getting the built-in command. I changed the program
name above because of this.]
While writing the test program, I wondered if the first character in the
output stream would get stripped away as a carriage control character, but
the test program demonstrates that it wasn't getting stripped away, and
adding 1X to the format didn't make any difference either. It's been so
long since I've used carriage control that I had almost forgotten about it!
The test program I found from the google search:
program main
implicit none
character(len=*), parameter :: ESC = achar(27)
write (*, '(a)', advance='no') ESC // '[2J' ! Move cursor to top left.
write (*, '(a)', advance='no') ESC // '[44;1m' // ESC // '[38;5;200mThis text is colourised.'
write (*, '(a)') ESC // '[0m' ! Reset colours.
end program main
generated the output:
←[2J←[44;1m←[38;5;200mThis text is colourised.←[0m
No change in colors.
So I don't think it's a misunderstanding on my part of how to incorporate
escape sequences into the source code. Neither my own test program or
someone else's test program works as expected. Can somebody explain why,
and how to coax it into working?
On a completely different matter, I have another program that is signalling
IEEE_UNDERFLOW_FLAG after completion. I don't think it's a problem (the results
seem fine), but would still like to find out which statement is triggering the flag.
Looking over the various compiler options, it's not obvious to me which one might
cause the program to stop execution when it happens and inform me of the source
code line that caused the underflow. Nor it is obvious whether I would need to
recompile every single subroutine in the library with the same compiler option
to produce an executable that would crash when the error occurs. I'm pretty sure
that I can narrow down the triggering code to one of two subroutines, because I've
never seen the flag when I don't use the option that calls one particular subroutine
(which in turns calls the second subroutine). Would appreciate a recommendation on
how to proceed, otherwise I'll have to take the experimental approach.