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, 256-color palette, and RGB — 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 — the color or style is simply not applied.
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 testsFACE ships a bash script (install.sh, downloadable from the latest release) that automates download and build:
install.sh --download git --build cmakeSupported download methods: git, wget. Supported build systems: fobis, make, cmake.
