Projects · Tools & libraries
HPrint
Header-only C++23 utility for centred terminal headers, with compile-time border characters, UTF-8 aware width and terminal size detection.

$ ./hprint_demo
>>>>>>>>>>>>>>>>>>>>>>> Build started >>>>>>>>>>>>>>>>>>>>>>>
########################## Phase 1 ##########################
[[[[[[[[[[[[[[[[[[[[[[[ User: mattfor ]]]]]]]]]]]]]]]]]]]]]]]
~~~~~~~~~~~~~~~~~~~~~~~~~ Ünïcödé ~~~~~~~~~~~~~~~~~~~~~~~~~~
********************* 日本語のヘッダー *********************
─────────────────────── Box drawing ────────────────────────
---------------------- Done in 1.50s -----------------------
A tiny library that does one thing well: print a header centred in the terminal.
#include <hprint>
hp::print<'>'>("Build started");
hp::printf<'#'>("Phase {}", 1);
hp::print<'*'>("日本語のヘッダー", 60);
hp::print<"─">("Box drawing", 60);
hp::printf<'!'>(stderr, "{} warnings", 3);- Border characters are template parameters, so the choice is made at compile time. A border can be a single character or a short UTF-8 string such as
─or«. std::format-style formatting throughhp::printf/hp::printfw, to stdout, stderr or anystd::FILE*.- Display width is UTF-8 aware, so wide CJK characters stay centred. It follows the Unicode 16 width tables, and counts combining marks and escape sequences as zero and an emoji sequence (👨👩👧) as one emoji.
hp::make_header_linebuilds the line instead of printing it, at compile time too.- Terminal width is detected on POSIX and Windows, with
COLUMNS(on POSIX) or an 80-column fallback when output isn't a terminal. - No dependencies beyond the standard library, tested in CI on Linux, macOS and Windows.
- Consumable through CMake
FetchContentorfind_package, with an installable config package.
