mint is a single C++11 header to format terminal text using a simple tag-based markup syntax.
mint.hpp offers the mint::mint() function which transforms a
string containing terminal attribute tags into another string containing
actual terminal
SGR codes.
mint::mint() automatically detects terminal support. If the standard
output isn’t connected to a compatible terminal, it removes the
attribute tags instead of converting them to SGR codes.
|
Important
|
You may copy mint.hpp as is to your project. The only
requirements are Linux and C++11.
|
mint tags allow you to specify text attributes like colors, bold, underline, and italic formatting.
The mint markup syntax is straightforward and composable.
An opening tag is, between [ and ], an unordered sequence of (all
optional, but at least one):
!-
Bold.
--
Dim.
_-
Underline.
#-
Italic.
*-
Bright foreground color.
:COLOR(background)COLOR(foreground)-
COLORis one of:dDefault
kBlack
rRed
gGreen
yYellow
bBlue
mMagenta
cCyan
wWhite
A closing tag contains one or more / characters between [ and ].
Each / closes one level.
Escape [ with \[ and \ with \\. Use mint::escape() to
escape text for mint::mint(). Use mint::escapeAnsi() to return to a
plain string (no SGR codes) from the result of mint::mint().
Opening and closing tags may be nested (maximum four levels of depth) and must be balanced. Note that nesting is additive: a nested tag cannot cancel an active attribute.
|
Important
|
The SGR code of any opening and closing tag always starts with a reset. |
Because you must balance opening and closing tags, mint is more suited
to {fmt} and printf() than I/O streams:
Include the mint.hpp header in your C++ code:
#include "mint.hpp"See the documentation of mint::mint(), mint::escape(),
mint::escapeAnsi(), and mint::hasTerminalSupport() in the header
file itself.
To test mint:
-
Build the testers:
$ mkdir -p build && cd build && cmake .. && make
-
Test with pytest, providing the build directory:
$ MINT_BUILD_DIR=$PWD pytest ../tests
To report a bug, create a GitHub issue.


