color(3f) - [M_escape] colorize text using a simple function-based approach (LICENSE:PD)
Synopsis
Description
Options
Example
Author
License
use M_escape, only : color, color_mode, &
! FOREGROUND COLORS & fg_red, fg_cyan, fg_magenta, fg_blue, & & fg_green, fg_yellow, fg_white, fg_ebony, & & fg_default, & ! BACKGROUND COLORS & bg_red, bg_cyan, bg_magenta, bg_blue, & & bg_green, bg_yellow, bg_white, bg_ebony, & & bg_default, & ! ATTRIBUTES & bold, italic, inverse, underline, & & unbold, unitalic, uninverse, ununderline, & & reset, & ! DISPLAY & clearfunction color(string,fg,bg,style) result (out)
character(len=*),intent(in) :: string character(len=*),intent(in),optional :: fg character(len=*),intent(in),optional :: bg character(len=*),intent(in),optional :: style
The color constant strings can be used directly but unconditionally in an output statement. To allow the attributes to be ignored they can be called with the color(3f) routine, which the color_mode(3f) procedure can be used to toggle on and off. Note that this routine does an implicit reset at the end of each use.
string string to assign attributes to fg foreground color constant bg background color constant style style keyword or concatenated style keywords
Sample program
program demo_color use M_escape, only : color, color_mode, & ! FOREGROUND COLORS & fg_red, fg_cyan, fg_magenta, fg_blue, & & fg_green, fg_yellow, fg_white, fg_ebony, & & fg_default, & ! BACKGROUND COLORS & bg_red, bg_cyan, bg_magenta, bg_blue, & & bg_green, bg_yellow, bg_white, bg_ebony, & & bg_default, & ! ATTRIBUTES & bold, italic, inverse, underline, & & unbold, unitalic, uninverse, ununderline, & & reset, & ! DISPLAY & clear implicit none write(*,(*(g0)))fg_red,bg_green,bold, Hello! ,resetwrite(*,(a))color( Hello! ,& & fg=fg_white,bg=bg_red,style=italic//bold) call color_mode(.false.) write(*,(a))color( Hello! ,& & fg=fg_red,bg=bg_red,style=italic//bold) end program demo_color
John S. Urban, 2020
Public Domain
color (3) | March 11, 2021 |