[UP]


Manual Reference Pages  - esc (3)

NAME

esc(3f) - [M_escape] substitute escape sequences for XML-like syntax in strings

CONTENTS

Synopsis
Description
Options
Keywords
Limitations
Example

SYNOPSIS

function esc(string,clear_at_end) result (expanded)

      character(len=*),intent(in) :: string
      logical,intent(in),optional :: clear_at_end
      character(len=:),allocatable :: expanded

DESCRIPTION

Use XML-like syntax to add attributes to terminal output such as color.

ANSI escape sequences are not universally supported by all terminal emulators; and normally should be suppressed when not going to a tty device. This routine provides the basic structure to support such behaviors.

OPTIONS

string input string of form
                   "<attribute_name>string</attribute_name> ...".

  where the current attributes are color names, bold, italic, underline, ...
clear_at_end
  By default, a sequence to clear all text attributes is sent at the end of the returned text if an escape character appears in the output string. This can be turned off by setting this value to false.

KEYWORDS

current keywords

    colors:
      r,         red,       R,  RED
      g,         green,     G,  GREEN
      b,         blue,      B,  BLUE
      m,         magenta,   M,  MAGENTA
      c,         cyan,      C,  CYAN
      y,         yellow,    Y,  YELLOW
      e,         ebony,     E,  EBONY
      w,         white,     W,  WHITE
    attributes:
      it,        italic
      bo,        bold
      un,        underline
     other:
      clear
      esc,       escape
      default
      gt
      lt

By default, if the color mnemonics (ie. the keywords) are uppercase they change the background color. If lowercase, the foreground color.

The "default" keyword is typically used explicitly when clear_at_end=.false.

Add, delete, and replace what strings are produced using UPDATE(3f).

LIMITATIONS

o colors are not nestable, keywords are case-sensitive,
o not all terminals obey the sequences. On Windows, it is best if you use Windows 10+ and/or the Linux mode; although it has worked with all CygWin and MinGW and Putty windows and mintty.
o you should use "<gt>" and "<lt>" instead of ">" and "<" in a string processed by esc(3f) instead of in any plain text output so that the raw mode will create correct input for the esc(3f) function if read back in.

EXAMPLE

Sample program

   program demo_esc
   use M_escape, only : esc, esc_mode, update
      write(*,’(a)’) esc(’<clear>TEST DEFAULTS:’)
      call printstuff()

write(*,’(a)’) esc(’TEST MANNER=PLAIN:’) call esc_mode(manner=’plain’) call printstuff()

write(*,’(a)’) esc(’TEST MANNER=RAW:’) call esc_mode(manner=’raw’) call printstuff()

write(*,’(a)’) esc(’TEST MANNER=color:’) call esc_mode(manner=’color’) call printstuff()

write(*,’(a)’) esc(’TEST ADDING A CUSTOM SEQUENCE:’) call update(’blink’,char(27)//’[5m’) call update(’/blink’,char(27)//’[38m’) write(*,’(a)’) esc(’<blink>Items for Friday</blink>’)

contains subroutine printstuff()

write(*,’(a)’) esc(’<r>RED</r>,<g>GREEN</g>,<b>BLUE</b>’) write(*,’(a)’) esc(’<c>CYAN</c>,<m>MAGENTA</g>,<y>YELLOW</y>’) write(*,’(a)’) esc(’<w>WHITE</w> and <e>EBONY</e>’)

write(*,’(a)’) esc(’Adding <bo>bold</bo>’) write(*,’(a)’) esc(’<bo><r>RED</r>,<g>GREEN</g>,<b>BLUE</b></bo>’) write(*,’(a)’) esc(’<bo><c>CYAN</c>,<m>MAGENTA</g>,<y>YELLOW</y></bo>’) write(*,’(a)’) esc(’<bo><w>WHITE</w> and <e>EBONY</e></bo>’)

write(*,’(a)’) esc(’Adding <ul>underline</ul>’) write(*,’(a)’) esc(& &’<bo><ul><r>RED</r>,<g>GREEN</g>,<b>BLUE</b></ul></bo>’) write(*,’(a)’) esc(& &’<bo><ul><c>CYAN</c>,<m>MAGENTA</g>,<y>YELLOW</y></ul></bo>’) write(*,’(a)’) esc(’<bo><ul><w>WHITE</w> and <e>EBONY</e></ul></bo>’)

write(*,’(a)’) esc(’Adding <ul>italic</ul>’) write(*,’(a)’) esc(& &’<bo><ul><it><r>RED</r>,<g>GREEN</g>,<b>BLUE</b></it></ul></bo>’) write(*,’(a)’) esc(& &’<bo><ul><it><c>CYAN</c>,<m>MAGENTA</g>,<y>YELLOW</it></y></ul></bo>’) write(*,’(a)’) esc(’<bo><ul><it><w>WHITE</w> and <e>EBONY</e></ul></bo>’)

write(*,’(a)’) esc(’Adding <in>inverse</in>’) write(*,’(a)’) esc(& &’<in><bo><ul><it><r>RED</r>,<g>GREEN</g>,& &<b>BLUE</b></it></ul></bo></in>’) write(*,’(a)’) esc(& &’<in><bo><ul><it><c>CYAN</c>,<m>MAGENTA</g>,& &<y>YELLOW</it></y></ul></bo></in>’) write(*,’(a)’) esc(& &’<in><bo><ul><it><w>WHITE</w> and <e>EBONY</e></ul></bo></in>’)

end subroutine printstuff

end program demo_esc


esc (3) March 11, 2021
Generated by manServer 1.08 from ad1bdf05-b824-4d67-b2f7-b00d07dd8ea4 using man macros.