Projects · Tools & libraries

HPrint

Stable 2026 Author

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

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 through hp::printf / hp::printfw, to stdout, stderr or any std::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_line builds 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 FetchContent or find_package, with an installable config package.