A KISS pure Fortran 2008+ library for easy colorizing and stylizing strings with ANSI escape codes β one function, zero dependencies.
π¨ Single Function APIcolorize(string, color_fg, color_bg, style) β one call does it all |
π Rich Color Support Named colors and 24-bit RGB ( #rrggbb) β foreground and background |
β¨ Text Styles Bold, italic, underline, blink, and more standard ANSI styles |
π€ Unicode Ready Optional UCS4/UTF-8 character kind support via preprocessor |
|---|---|---|---|
| β‘ Pure Fortran 2008+ No C, no external deps β tested with gfortran, ifx, lfortran, flang-new, nvfortran |
π Multi-licensed GPL v3 Β· BSD 2/3-Clause Β· MIT |
π¦ Multiple build systems fpm, FoBiS.py, CMake |
π Documented & Tested API reference + full test suite for colors and styles |
For full documentation (guide, API reference, examples, etc.) see the FACE website.
- Stefano Zaghi β @szaghi
Contributions are welcome β see the Contributing page.
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to this project is welcome β pick the license that best fits your needs.
use face
print '(A)', colorize('Hello', color_fg='red')//colorize(' World', color_fg='blue', style='underline_on')FACE exposes only 3 procedures:
colorizeβ the main function;colors_samplesβ prints a sample of all available colors to standard output;styles_samplesβ prints a sample of all available styles to standard output.
use face
character(len=:), allocatable :: error_message
error_message = colorize('error:', color_fg='red', style='underline_on')//' file not found!'
print '(A)', error_message
print '(A)', colorize('suggestion: check your configuration', color_fg='blue')
call colors_samples ! print samples of all colors available
call styles_samples ! print samples of all styles availablecolorize returns an allocatable character with the requested foreground color, background color, and style. All arguments except string are optional.
pure function colorize(string, color_fg, color_bg, style) result(colorized)
character(len=*), intent(in) :: string ! Input string.
character(len=*), intent(in), optional :: color_fg ! Foreground color definition.
character(len=*), intent(in), optional :: color_bg ! Background color definition.
character(len=*), intent(in), optional :: style ! Style definition.
character(len=:), allocatable :: colorized ! Colorized string.
end function colorizeColors and style definitions are case insensitive. No warning is returned for unrecognized values (including a malformed
#rrggbb) β the color or style is simply not applied.
A color is either one of the names below (red, green_intense, ...) or a 24-bit RGB value
#rrggbb, written as the SGR sequence ESC[38;2;r;g;bm (foreground) or ESC[48;2;r;g;bm
(background). Most modern terminals support 24-bit color; a terminal that does not may show
an approximation or ignore it.
print '(A)', colorize('188', color_fg='#2EF5C0')//colorize(' km/h', color_fg='#FFB000', color_bg='#101010')Standalone β clone, build, and install in one command:
FoBiS.py install szaghi/FACE -mode static-gnu
FoBiS.py install szaghi/FACE -mode static-gnu --prefix /path/to/prefixAs a project dependency β declare PENF in your fobos and run fetch:
[dependencies]
deps_dir = src/third_party
FACE = https://github.com/szaghi/FACEFoBiS.py fetch # fetch and build
FoBiS.py fetch --update # re-fetch and rebuildfpm build
fpm testFor dependencies add to your fpm.toml:
[dependencies]
FACE = { git = "https://github.com/szaghi/FACE" }cmake -B build && cmake --build buildmake # static library
make TESTS=yes # build and run testscurl -fsSL https://github.com/szaghi/FACE/releases/latest/download/install.sh | bashIt installs the latest release into ~/.local with the build system you choose among those FACE ships
(--build fobis|fpm|cmake: a menu asks when you do not say), the compiler you name (--fc, --gnu, --intel,
--nvidia), one install per compiler (lib/face/<compiler>-<version>/, include/face/<compiler>-<version>/), and
makes it usable through pkg-config (pkg-config --cflags --libs face, with PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig).
Pass options after bash -s --, e.g. ... | bash -s -- --build cmake --intel --prefix /opt/face; --help lists them
all, --uninstall removes the install. The installer is FoBiS's
(One-line installer).