Should INQUIRE have an ISATTY parameter?

I am wondering if others think it would be worthwhile for the INQUIRE statement to have an ISATTY parameter? It is sometimes useful to know that the output or input is attached to a terminal. Perhaps you want to use ANSI display device sequences to produce color only if the output is a terminal, for example. An ISATTY() function is a common compiler extension, equivalent to the C isatty(3c) function; indicating a common need for it. INQUIRE as-is cannot reliably be used to determine if a file is a TTY (or a FIFO or other type for that matter) and even options that might be used with a particular platform are not portable. Empirically, I found some compilers return SIZE=0 and others SIZE=-1, some return NAME=’’ or NAME=’/dev/tty/N’ or even ‘stdin’ and so on. And since it is quite unreliable to mix C and Fortran I/O ; using isatty(3c) via an ISO_C_BINDING interface is a bad idea as nothing requires there to be any reliable connection between Fortran LUNs and C file pointers. Do others feel this should be standardized as a function (or as I would prefer) or as an option on the INQUIRE statement? Does anyone use the ISATTY() function found in at least GNU/gfortran and Intel/ifort? I was thinking about requesting this to the Fortran Standards Committee but was wondering what a wider community might think first.

2 Likes

Hm, it’s never occurred to me to call gfortran’s isatty. Occasionally, I will test if a unit number equals one of the named constants in iso_fortran_env (output_unit, input_unit, or error_unit according to context). That’s not rock-solid, but I’ve personally never needed anything fancier. I also generally don’t write system-interface code.