C Library Functions  - M_attr (3)

NAME

M_attr(3f) - [M_attr::INTRO] control text attributes on terminals (LICENSE:MIT)

CONTENTS

Synopsis
Description
Access
Limitations
Example
Author
License
See Also

SYNOPSIS

use M_attr, only : attr, attr_mode, attr_update

use M_attr, only : alert ! generate standard messages

DESCRIPTION

M_attr(3f) is a Fortran module that uses common ANSI escape sequences to control terminal text attributes.

        use M_attr
        write(*,*)attr(’<red>Red Text!</red> <green>Green Text!</green>’)
        end

It is designed to use three simple procedures to

    + Specify attributes using simple HTML-like syntax
    + allow the sequences to be suppressed when desired
    + permit the  user program to completely customize the keywords.
      The user can add, delete and replace the sequences associated with
      a keyword without changing the code.

One advantage of the approach of using formatting directives which are replaced with in-band escape sequences is that it is easy to turn off when running batch.

Another important capability is that programs can be run in "raw" mode and create a simple text file with the formatting directives in it that can then be read back in by a simple filter program that strips it back to plain text( see app/plain.f90), or displays it to a screen in color(see app/light.f90) or perhaps converts it to another format.

So this approach makes it trivial to read specially-formatted data from a file like a message catalog (perhaps with various versions in different languages) and colorize it or display it as plain text

By making each line self-contained (by default) lines can be filtered by external utilities and still display correctly.

ACCESS

Via git(1):

       git clone https://github.com/urbanjost/M_attr.git
       cd M_attr/src
       # change Makefile if not using one of the listed compilers
       make clean; make gfortran    # for gfortran
       make clean; make ifort       # for ifort
       make clean; make nvfortran   # for nvfortran

This will compile the M_attr module and example programs.

Alternatively, via fpm (see https://github.com/fortran-lang/fpm):

        git clone https://github.com/urbanjost/M_attr.git

or just list it as a dependency in your fpm.toml project file.

        [dependencies]
        M_attr = { git = "https://github.com/urbanjost/M_attr.git" }

LIMITATIONS

o colors are not nestable.
o keywords are case-sensitive,
o ANSI escape sequences are not universally supported by all terminal emulators; and normally should be suppressed when not going to a tty device. Therefore, you should use M_system::system_istty(3f) or the common Fortran extension ISATTY() to set the default to "plain" instead of "color" when the output file is not a conforming terminal. On basic MSWindows console windows, it is best to use Windows 10+ and/or the Linux mode; you may have to enable ANSI escape sequence mode on MSWindows. It does work as-is with CygWin and MinGW and Putty windows and mintty(1) as tested.

EXAMPLE

Sample program

    program demo_M_attr
    use M_attr, only : attr, attr_mode, attr_update, alert
    implicit none
    character(len=256) :: line
    character(len=*),parameter :: f=’( &
     &"   <bo><w><G> GREAT: </G></w>&
     &The new value <Y><b>",f8.4,1x,"</b></Y> is in range"&
     &)’
    real :: value

write(*,’(a)’)& &attr(’ <r><W><bo> ERROR: </W>red text on a white background</y>’)

value=3.4567 write(line,fmt=f) value write(*,’(a)’)attr(trim(line))

! write same string as plain text write(*,*) call attr_mode(manner=’plain’) write(*,’(a)’)attr(trim(line))

call attr_mode(manner=’color’) ! use pre-defined or user defined strings write(*,*) write(*,’(a)’)attr(’<ERROR> Woe is nigh.’) write(*,’(a)’)attr(’<WARNING> The night is young.’) write(*,’(a)’)attr(’<INFO> It is Monday’)

call alert(’<ERROR>’, ’Woe is nigh.’) call alert(’<WARNING>’, ’The night is young.’) call alert(’<INFO>’, ’It is Monday’)

! create a custom mnemonic call attr_update(’MYERROR’,attr(& ’ <R><e> E<w>-<e>R<w>-<e>R<w>-<e>O<w>-<e>R: </e></R></bo>’& )) write(*,*) write(*,’(a)’)attr(’<MYERROR> my custom message style’)

end program demo_M_attr

AUTHOR

John S. Urban, 2021

LICENSE

    MIT

SEE ALSO

attr(3f), attr_mode(3f), attr_update(3f)

Related information:

    terminfo(3c), termlib(3c), tput(1), reset(1), clear(1),
    console_codes(4), ECMA-48,
    https://en.wikipedia.org/wiki/ANSI_escape_code


Nemo Release 3.1 M_attr (3) July 22, 2023
Generated by manServer 1.08 from 0a1af4f0-e476-4238-8a45-dc9aa65d0231 using man macros.