Description
Colors Module
In order to support colors and styling (bold, underline and etc) I propose a small utility to handle colored output, namely stdlib_colors
. The use cases can vary, but the main application would be the richer logger and errors which helps a lot to visually identify what kind of message is right away.
Figure 1 - coloredlogs python library showing a use case
Few remarks from the community in #193
@mobius-eng commented on 20 May
(...)
Julia (and Python and R) are meant to be used interactively. Thus, colors play an important role with the output to the terminal. By contrast, Fortran programs are meant to be run in the "batch mode" with log going to the file.
@aradi commented on 24 May
As for colors: I am fine, as long as they are optional. I think most people typically run Fortran programs in batch systems with redirected output. Seeing a lot of color control sequences when opening the output files is rather disturbing...
@jvdp1 commented on 23 May
(...)
Colors are not needed for me.
@wclodius2
A problem with using colors is thatoutput_unit
can be directed to a file where the "color codes” will be distracting.
Proof of Concept and fixing the issue with redirection
- Well, gnu utils have support to colored output for eons and when it gets redirected it handles correctly, how is that possible? So I did some research in order to figure out how they are made and found this.
- So basically we test if there is a teletypewriter device (A interactive terminal) connected with the
isatty
function (from<unistd.h>
), ifisatty
returns true then we write the ANSI colors, otherwise no colors in the output. - A lot of compiler vendors support this function as a extension, however is not a standard so we can't rely on it. That being said I think it should be included in the
stdlib_system
module as a new function binding the C one (and alternatives to other platforms). - In order to show that it works I made a small change in a program to output colors from the fortran-wiki and its here
Some other related projects that could inspire the API
- FACE by @szaghi
- Foul, as pointed by @arjenmarkus]