Skip to content

szaghi/FACE

Repository files navigation

FACE

Fortran Ansi Colors and Styles Environment

A KISS pure Fortran 2008+ library for easy colorizing and stylizing strings with ANSI escape codes — one function, zero dependencies.

GitHub tag GitHub issues CI coverage

🎨 Single Function API
colorize(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.


Authors

Contributions are welcome — see the Contributing page.

Copyrights

This project is distributed under a multi-licensing system:

Anyone interested in using, developing, or contributing to this project is welcome — pick the license that best fits your needs.


A taste of FACE

use face
print '(A)', colorize('Hello', color_fg='red')//colorize(' World', color_fg='blue', style='underline_on')

Usage

FACE exposes only 3 procedures:

  1. colorize — the main function;
  2. colors_samples — prints a sample of all available colors to standard output;
  3. 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 available

colorize

colorize 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 colorize

Colors and style definitions are case insensitive. No warning is returned for unrecognized values — the color or style is simply not applied.

Available Colors and Styles

samples


Install

FoBiS.py

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/prefix

As a project dependency — declare PENF in your fobos and run fetch:

[dependencies]
deps_dir = src/third_party
FACE     = https://github.com/szaghi/FACE
FoBiS.py fetch           # fetch and build
FoBiS.py fetch --update  # re-fetch and rebuild

fpm

fpm build
fpm test

For dependencies add to your fpm.toml:

[dependencies]
FACE = { git = "https://github.com/szaghi/FACE" }

CMake

cmake -B build && cmake --build build

Makefile

make              # static library
make TESTS=yes    # build and run tests

Install script

FACE ships a bash script (install.sh, downloadable from the latest release) that automates download and build:

install.sh --download git --build cmake

Supported download methods: git, wget. Supported build systems: fobis, make, cmake.

About

Fortran Ansi Colors (and Styles) Environment

Topics

Resources

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors