BenBot 1.7.5
A chess engine
Loading...
Searching...
No Matches
util::strings::TextTable Struct Referencefinal

#include </home/runner/work/BenBot/BenBot/libutil/include/libutil/TextTable.hpp>

Public Types

using PrintFunc = std::function<void(string_view)>

Public Member Functions

auto append_column (string_view text) -> TextTable &
auto new_row () -> TextTable &
void print (PrintFunc &&printHeading, PrintFunc &&printCell, PrintFunc &&printOutline, std::function< void()> printNewline) const
auto to_string () const -> string

Detailed Description

This class allows you to construct a table of text with vertically aligned columns. Rows may have different numbers of columns; the table's size is based on the maximum number of columns. The first row is the header, and a separator row will be added between it and the second manually added row.

Definition at line 41 of file TextTable.hpp.

Member Typedef Documentation

◆ PrintFunc

using util::strings::TextTable::PrintFunc = std::function<void(string_view)>

Typedef for a function that accepts a string as an argument.

Definition at line 54 of file TextTable.hpp.

Member Function Documentation

◆ append_column()

auto util::strings::TextTable::append_column ( string_view text) -> TextTable &

Appends a column to the current row.

◆ new_row()

auto util::strings::TextTable::new_row ( ) -> TextTable &

Ends the current row. Subsequent calls to append_column() will write to the new row.

◆ print()

void util::strings::TextTable::print ( PrintFunc && printHeading,
PrintFunc && printCell,
PrintFunc && printOutline,
std::function< void()> printNewline ) const

Prints the table by calling lambda functions for each different element of the table. This allows you to do things like print the table to a terminal using ANSI color codes; using just the to_string() API would make it much more difficult to intersperse the needed escape codes to switch between styles for the cell text and outlines, etc.

Parameters
printHeadingFunction object that will be called to print the contents of each heading cell. Note that the strings sent to this function will include trailing whitespace, to create the table's alignment.
printCellFunction object that will be called to print the contents of each non-heading cell. Note that the strings sent to this function will include trailing whitespace, to create the table's alignment.
printOutlineFunction object that will be called to print outline/border characters between cells and surrounding the entire table.
printNewlineFunction object that accepts no arguments and should insert a single newline character into the text stream being constructed.

◆ to_string()

auto util::strings::TextTable::to_string ( ) const -> string
nodiscard

Concatenates all the rows in the table into a single string, with separators between rows and columns.


The documentation for this struct was generated from the following file: