14#include <initializer_list>
237 [[nodiscard]]
bool empty()
const noexcept;
241 [[nodiscard]] std::vector<presentation_span>
const&
spans()
const noexcept;
244 std::vector<presentation_span> spans_;
287 return (*
this)(
text !=
nullptr ? std::string_view(
text) : std::string_view{});
304 template <
typename T>
305 requires(!std::is_convertible_v<T &&, std::string_view> && !std::same_as<std::remove_cvref_t<T>,
semantic_glyph>)
309 result.
append(fmt::format(
"{}", std::forward<T>(
value)), style_);
318 template <
typename... Args>
319 requires(
sizeof...(Args) > 0)
323 result.
append(fmt::format(format, std::forward<Args>(args)...), style_);
344 return (*
this)(
glyph,
text !=
nullptr ? std::string_view(
text) : std::string_view{});
353 template <
typename... Args>
354 requires(
sizeof...(Args) > 0)
404 std::optional<table_alignment>
alignment = std::nullopt;
407 table_cell(std::string_view
text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
412 table_cell(
char const*
text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
415 table_cell(std::string
text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
429 std::optional<table_alignment>
alignment = std::nullopt)
440 std::optional<table_alignment>
alignment = std::nullopt)
451 std::optional<table_alignment>
alignment = std::nullopt)
458[[nodiscard]]
inline table_cell make_table_cell(table_cell
const&
value) {
return value; }
459[[nodiscard]]
inline table_cell make_table_cell(styled_text
const&
value) {
return table_cell(
value); }
460[[nodiscard]]
inline table_cell make_table_cell(std::string
const&
value) {
return table_cell(
value); }
461[[nodiscard]]
inline table_cell make_table_cell(std::string_view
value) {
return table_cell(
value); }
462[[nodiscard]]
inline table_cell make_table_cell(
char const*
value) {
return table_cell(
value); }
464template <
typename T> [[nodiscard]] table_cell make_table_cell(T
const&
value)
466 return table_cell(fmt::format(
"{}",
value));
566 return this->
row(std::vector<table_cell>{detail::make_table_cell(values)...});
571 [[nodiscard]] std::string
const&
title() const noexcept;
598 bool preserve_tokens_ = false;
629 return this->field(std::move(key), fmt::format(
"{}",
value));
639 [[nodiscard]] std::string
const&
title() const noexcept;
647 [[nodiscard]]
std::vector<
std::pair<
std::
string,
std::
string>> const& fields() const noexcept;
656 std::vector<
std::pair<
std::
string,
std::
string>> fields_;
738 std::FILE* stream = stdout);
752 std::
size_t initial_column = 0);
760 std::
size_t initial_column = 0);
811 std::
size_t initial_column = 0);
821 std::string_view marker = "",
std::
size_t initial_column = 0);
832 std::
size_t initial_column = 0);
841 bool prefix_first = true);
850 bool indent_first = true);
874 if constexpr (std::is_same_v<std::remove_cv_t<T>,
float>)
876 return options.float32_precision;
878 else if constexpr (std::is_same_v<std::remove_cv_t<T>,
double>)
880 return options.float64_precision;
882#if UNI20_HAS_FLOAT128
883 else if constexpr (std::is_same_v<std::remove_cv_t<T>, uni20::float128>)
885 return options.float128_precision;
890 return options.long_double_precision;
927template <uni20::Complex T>
945 using value_type = std::remove_cvref_t<T>;
956 return fmt::format(
"{}",
value);
979 using value_type = std::remove_cvref_t<T>;
Definition terminal.hpp:262
Builder for simple terminal reports with headings, status lines, fields, and tables.
Definition presentation.hpp:602
report_builder & field(std::string key, Value const &value)
Add a labeled field after formatting the value with fmt.
Definition presentation.hpp:627
A small report table builder for command-line examples and diagnostics.
Definition presentation.hpp:479
report_table & grid(bool enabled=true)
Enable or disable a full table grid.
Definition presentation.cpp:1422
report_table & column(std::string heading, table_alignment alignment=table_alignment::right)
Add a column to the table.
Definition presentation.cpp:1341
report_table & preserve_tokens(bool enabled=true)
Wrap only at whitespace, allowing the table to exceed the requested width to preserve tokens.
Definition presentation.cpp:1433
report_table & row(Values const &... values)
Add a row by formatting each value with fmt.
Definition presentation.hpp:564
report_table & top_separator(table_rule_style style=table_rule_style::single)
Insert a separator before the generated heading row.
Definition presentation.cpp:1374
report_table & borders(table_border_options options)
Set table border and rule options.
Definition presentation.cpp:1386
report_table & outer_border(bool enabled=true)
Enable or disable an outer border around the table.
Definition presentation.cpp:1398
std::vector< table_rule_style > const & top_separators() const noexcept
Return explicit separators rendered before the heading row.
Definition presentation.cpp:1447
report_table & header_separator(bool enabled=true)
Enable or disable a horizontal rule after the heading row.
Definition presentation.cpp:1416
report_table & separator(table_rule_style style=table_rule_style::single)
Insert a separator at the current body position.
Definition presentation.cpp:1380
report_table & border_style(table_rule_style style)
Set the rule style used by automatic borders and separators.
Definition presentation.cpp:1392
std::string const & title() const noexcept
Return the table title.
Definition presentation.cpp:1441
std::vector< table_column > const & columns() const noexcept
Return the column specifications.
Definition presentation.cpp:1443
table_border_options const & border_options() const noexcept
Return table border and rule options.
Definition presentation.cpp:1449
bool preserves_tokens() const noexcept
Whether column fitting must keep whitespace-delimited tokens intact.
Definition presentation.cpp:1439
report_table & column_separators(bool enabled=true)
Enable or disable vertical rules between columns.
Definition presentation.cpp:1404
std::vector< table_entry > const & entries() const noexcept
Return table entries, including row and separator entries.
Definition presentation.cpp:1445
report_table & row_separators(bool enabled=true)
Enable or disable horizontal rules between rows.
Definition presentation.cpp:1410
A sequence of styled text spans and semantic glyph tokens.
Definition presentation.hpp:216
styled_text & append(std::string_view text, terminal::TerminalStyle style={})
Append a text span.
Definition presentation.cpp:1164
std::vector< presentation_span > const & spans() const noexcept
Return the stored presentation spans.
Definition presentation.cpp:1184
bool empty() const noexcept
Return whether this document has no spans.
Definition presentation.cpp:1182
Callable style wrapper that builds styled presentation text.
Definition presentation.hpp:251
styled_text operator()(semantic_glyph glyph, char const *text) const
Build a styled semantic glyph followed by styled literal text.
Definition presentation.hpp:342
styled_text operator()(semantic_glyph glyph, std::string_view text) const
Build a styled semantic glyph followed by styled literal text.
Definition presentation.hpp:331
terminal::TerminalStyle const & terminal_style() const noexcept
Return the terminal style metadata carried by this wrapper.
Definition presentation.hpp:270
styled_text operator()(semantic_glyph glyph) const
Build a styled semantic glyph span.
Definition presentation.hpp:293
text_style()=default
Construct an empty style wrapper.
styled_text operator()(semantic_glyph glyph, fmt::format_string< Args... > format, Args &&... args) const
Build a styled semantic glyph followed by formatted styled text.
Definition presentation.hpp:355
styled_text operator()(std::string_view text) const
Build a styled text span from literal text.
Definition presentation.hpp:275
text_style(std::string_view spec)
Construct from a terminal style specification string.
Definition presentation.hpp:262
styled_text operator()(char const *text) const
Build a styled text span from literal text.
Definition presentation.hpp:285
styled_text operator()(fmt::format_string< Args... > format, Args &&... args) const
Format text with fmt and apply this style.
Definition presentation.hpp:320
text_style(char const *spec)
Construct from a terminal style specification string.
Definition presentation.hpp:266
text_style(terminal::TerminalStyle style)
Construct from an existing terminal style.
Definition presentation.hpp:258
Concept for complex scalar types.
Definition scalar_concepts.hpp:75
Concept for types that are either real or complex.
Definition scalar_concepts.hpp:87
Concept for real scalar types (float, double, etc.).
Definition scalar_concepts.hpp:69
locale_t value
Definition data_table.cpp:49
presentation::styled_text text
Definition display.cpp:141
std::string format_complex(T const &value, scalar_format_options const &options={})
Format a Uni20 complex scalar as real+imagi.
Definition scalar_io.hpp:342
typename make_real< T >::type make_real_t
Alias for the underlying real-valued type of T.
Definition scalar_traits.hpp:168
std::string format_real(T value, scalar_format_options const &options={})
Format a Uni20 real scalar.
Definition scalar_io.hpp:306
real_format_notation
Selects how real scalar values are rendered as text.
Definition scalar_io.hpp:29
constexpr bool isfinite(I const &x) noexcept
Returns whether an integer scalar is finite.
Definition math.hpp:121
Scalar math helper utilities.
std::string color_text(std::string_view s, const TerminalStyle &ts)
Definition terminal.hpp:345
Definition data_table.cpp:8
std::string render_strict_ascii(styled_text const &text, text_charset charset, output_policy policy)
Render styled text under strict ASCII fallback.
Definition presentation.cpp:1331
table_cell cell(styled_text content, std::size_t span=1, std::optional< table_alignment > alignment=std::nullopt)
Build a table cell from styled presentation text.
Definition presentation.hpp:428
ambiguous_width
Selects how East Asian ambiguous-width code points are measured.
Definition presentation.hpp:59
int real_precision(numeric_format_options const &options)
Select the configured precision for a Uni20 real scalar type.
Definition presentation.hpp:872
std::string format_scalar_for_output(T const &value, numeric_format_options const &options, output_policy const &policy)
Format a scalar for policy-aware presentation output.
Definition presentation.hpp:998
std::string pad_right(std::string_view text, std::size_t target_width, output_policy const &policy)
Right-pad rendered text to a target width.
Definition presentation.cpp:2588
semantic_glyph
Names semantic glyphs independently of their rendered spelling.
Definition presentation.hpp:117
@ box_single_vertical_cross_double_horizontal
@ box_double_vertical_cross_single_horizontal
@ box_double_vertical_tee_left_single
@ box_single_up_double_horizontal
@ box_double_vertical_tee_right_single
@ box_double_up_single_horizontal
@ box_double_bottom_right
@ box_single_vertical_tee_left_double
@ box_single_down_double_horizontal
@ box_single_vertical_tee_right_double
@ box_double_down_single_horizontal
std::string render_text(std::string_view text, output_policy const &policy)
Render raw UTF-8 text through charset and ASCII fallback policy.
Definition presentation.cpp:1231
std::string indent_text(std::string_view text, std::size_t spaces, output_policy const &policy, bool indent_first)
Indent each rendered line by a fixed number of spaces.
Definition presentation.cpp:2690
bool should_emit_color(output_policy const &policy)
Return whether a policy currently permits ANSI color output.
Definition presentation.cpp:1211
output_policy plain_policy()
Build a policy for plain file/log rendering with no ANSI color.
Definition presentation.cpp:1195
invalid_utf8
Selects how invalid UTF-8 bytes are represented.
Definition presentation.hpp:66
std::variant< styled_text_span, semantic_glyph_span > presentation_span
Definition presentation.hpp:213
std::string render_glyph(semantic_glyph glyph, output_policy const &policy)
Render a semantic glyph according to an output policy.
Definition presentation.cpp:1218
uni20::real_format_notation core_notation(real_notation notation)
Definition presentation.hpp:894
real_notation
Selects how real floating-point values are formatted.
Definition presentation.hpp:81
std::string clip_to_width(std::string_view text, std::size_t max_width, output_policy const &policy, std::size_t initial_column)
Clip rendered text to a target width without appending a marker.
Definition presentation.cpp:2629
std::vector< std::string > wrap_text(std::string_view text, std::size_t max_width, output_policy const &policy)
Wrap rendered text by display cells or bytes.
Definition presentation.cpp:2831
ornament_mode
Selects the richness of decorative line and tree glyphs.
Definition presentation.hpp:73
std::string style_nonfinite_scalar(std::string text, T const &value, output_policy const &policy)
Apply the default non-finite scalar style to already-formatted presentation text.
Definition presentation.hpp:977
std::string render_plain(styled_text const &text, output_policy policy)
Render styled text without ANSI escape sequences.
Definition presentation.cpp:1325
color_mode
Selects when terminal color/style control sequences may be emitted.
Definition presentation.hpp:28
text_charset
Selects how non-ASCII text code points are rendered.
Definition presentation.hpp:44
std::string format_real(T value, numeric_format_options const &options)
Format a real scalar value according to numeric presentation options.
Definition presentation.hpp:913
table_alignment
Selects table cell alignment in report-style output.
Definition presentation.hpp:89
std::string format_complex(T const &value, numeric_format_options const &options)
Format a complex value as real+imagi.
Definition presentation.hpp:928
std::string prefix_lines(std::string_view text, std::string_view prefix, output_policy const &policy, bool prefix_first)
Prefix each rendered line with fixed text.
Definition presentation.cpp:2657
output_policy terminal_policy(std::FILE *stream)
Build a policy for terminal rendering.
Definition presentation.cpp:1186
std::string pad_left(std::string_view text, std::size_t target_width, output_policy const &policy)
Left-pad rendered text to a target width.
Definition presentation.cpp:2571
table_rule_style
Selects the glyph family used for table rules and borders.
Definition presentation.hpp:98
std::string pad_center(std::string_view text, std::size_t target_width, output_policy const &policy)
Center rendered text within a target width.
Definition presentation.cpp:2606
output_policy strict_ascii_policy(text_charset charset)
Build a strict ASCII policy.
Definition presentation.cpp:1203
std::string format_scalar(T const &value, numeric_format_options const &options)
Format an arbitrary scalar-like value for presentation output.
Definition presentation.hpp:943
std::string render_terminal(styled_text const &text, output_policy policy, std::FILE *stream)
Render styled text for a terminal stream.
Definition presentation.cpp:1319
std::string truncate_to_width(std::string_view text, std::size_t max_width, output_policy const &policy, std::string_view marker, std::size_t initial_column)
Truncate rendered text to a target width and optionally append a marker.
Definition presentation.cpp:2635
std::string render(styled_text const &text, output_policy const &policy)
Render styled text with color/style sequences only when policy allows.
Definition presentation.cpp:1289
std::variant< std::vector< table_cell >, table_separator > table_entry
Definition presentation.hpp:476
glyph_set
Selects the preferred glyph family for semantic symbols and ornaments.
Definition presentation.hpp:36
std::string truncate_left_to_width(std::string_view text, std::size_t max_width, output_policy const &policy, std::string_view marker, std::size_t initial_column)
Truncate rendered text from the left to a target width and optionally prepend a marker.
Definition presentation.cpp:2649
width_mode
Selects the unit used by alignment and clipping helpers.
Definition presentation.hpp:52
styled_text render_report(report_builder const &report, output_policy const &policy)
Format a high-level report builder into styled text.
Definition presentation.cpp:2366
std::size_t display_width(std::string_view text, output_policy const &policy, std::size_t initial_column)
Measure rendered text width under the selected policy.
Definition presentation.cpp:2560
Definition async/async.hpp:26
terminal::TerminalStyle style
Definition presentation.cpp:2434
table_alignment alignment
Definition presentation.cpp:2018
std::optional< semantic_glyph > glyph
Definition presentation.cpp:2435
std::size_t span
Definition presentation.cpp:2017
Output policy shared by presentation renderers and layout helpers.
Definition presentation.hpp:186
color_mode color
Definition presentation.hpp:187
ornament_mode ornaments
Definition presentation.hpp:195
width_mode width
Definition presentation.hpp:190
glyph_set glyphs
Definition presentation.hpp:188
invalid_utf8 invalid
Definition presentation.hpp:192
std::FILE * output_stream
Definition presentation.hpp:196
std::optional< std::size_t > wrap_width
Definition presentation.hpp:194
ambiguous_width ambiguous
Definition presentation.hpp:191
text_charset charset
Definition presentation.hpp:189
std::size_t tab_width
Definition presentation.hpp:193
A semantic glyph token carrying style metadata but no rendered spelling.
Definition presentation.hpp:208
terminal::TerminalStyle style
Definition presentation.hpp:210
semantic_glyph glyph
Definition presentation.hpp:209
A text span carrying style metadata but no terminal escape sequences.
Definition presentation.hpp:201
terminal::TerminalStyle style
Definition presentation.hpp:203
std::string text
Definition presentation.hpp:202
Rule and border controls for report tables.
Definition presentation.hpp:390
table_rule_style rule_style
Definition presentation.hpp:395
bool row_separators
Definition presentation.hpp:393
bool header_separator
Definition presentation.hpp:394
bool column_separators
Definition presentation.hpp:392
std::size_t horizontal_padding
Definition presentation.hpp:396
bool outer
Definition presentation.hpp:391
Cell specification for table rows, including optional style, column span, and alignment.
Definition presentation.hpp:401
table_cell(char const *text, std::size_t span_=1, std::optional< table_alignment > alignment_=std::nullopt)
Definition presentation.hpp:412
std::size_t span
Definition presentation.hpp:403
std::optional< table_alignment > alignment
Definition presentation.hpp:404
table_cell(styled_text text, std::size_t span_=1, std::optional< table_alignment > alignment_=std::nullopt)
Definition presentation.hpp:418
table_cell(std::string text, std::size_t span_=1, std::optional< table_alignment > alignment_=std::nullopt)
Definition presentation.hpp:415
table_cell(std::string_view text, std::size_t span_=1, std::optional< table_alignment > alignment_=std::nullopt)
Definition presentation.hpp:407
styled_text content
Definition presentation.hpp:402
Column specification for report tables.
Definition presentation.hpp:383
table_alignment alignment
Definition presentation.hpp:385
std::string heading
Definition presentation.hpp:384
Explicit separator row inserted between table data rows.
Definition presentation.hpp:472
table_rule_style style
Definition presentation.hpp:473