ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::io::layout Namespace Reference

Column-driven table formatting with ANSI-safe alignment. More...

Classes

struct  Column
 Column definition for table formatting. More...
 

Typedefs

using Row = std::vector<std::string>
 A row of pre-formatted cell strings.
 

Enumerations

enum class  Align { left , right }
 

Functions

std::string format_md_row (Row const &cells)
 Format a row as a markdown table row.
 
std::string format_md_separator (std::vector< Column > const &columns)
 Generate a markdown alignment row.
 
std::string format_row (std::vector< Column > const &columns, Row const &cells, std::string const &sep=" ")
 Format a row of cells according to column definitions.
 
std::string format_separator (std::vector< Column > const &columns, std::string const &sep=" ")
 Generate a separator line spanning the full table width.
 
Row header_labels (std::vector< Column > const &columns)
 Extract header labels from column definitions as a Row.
 
std::string pad (std::string const &s, int width, Align align=Align::right)
 Pad a string to a target visual width, handling ANSI codes.
 
int visual_width (std::string const &s)
 Compute the visual width of a string, ignoring ANSI escape codes.
 

Detailed Description

Column-driven table formatting with ANSI-safe alignment.

Provides primitives for building aligned text tables that correctly handle ANSI escape codes when computing column widths. Used for terminal output of confusion matrices, benchmark results, and evaluation summaries.

Typedef Documentation

◆ Row

using ppforest2::io::layout::Row = std::vector<std::string>

A row of pre-formatted cell strings.

Enumeration Type Documentation

◆ Align

enum class ppforest2::io::layout::Align
strong
Enumerator
left 
right 

Function Documentation

◆ format_md_row()

std::string ppforest2::io::layout::format_md_row ( Row const & cells)
inline

Format a row as a markdown table row.

◆ format_md_separator()

std::string ppforest2::io::layout::format_md_separator ( std::vector< Column > const & columns)
inline

Generate a markdown alignment row.

◆ format_row()

std::string ppforest2::io::layout::format_row ( std::vector< Column > const & columns,
Row const & cells,
std::string const & sep = "  " )
inline

Format a row of cells according to column definitions.

Each cell is padded to its column's width using ANSI-safe padding.

◆ format_separator()

std::string ppforest2::io::layout::format_separator ( std::vector< Column > const & columns,
std::string const & sep = "  " )
inline

Generate a separator line spanning the full table width.

◆ header_labels()

Row ppforest2::io::layout::header_labels ( std::vector< Column > const & columns)
inline

Extract header labels from column definitions as a Row.

◆ pad()

std::string ppforest2::io::layout::pad ( std::string const & s,
int width,
Align align = Align::right )
inline

Pad a string to a target visual width, handling ANSI codes.

Unlike fmt::format width specifiers, this correctly handles strings containing ANSI escape codes by computing visual width separately.

◆ visual_width()

int ppforest2::io::layout::visual_width ( std::string const & s)
inline

Compute the visual width of a string, ignoring ANSI escape codes.

Skips any ESC [ ... m (SGR) sequences when counting characters.