Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
presentation.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "terminal.hpp"
4
5#include <uni20/core/math.hpp>
7
8#include <cmath>
9#include <complex>
10#include <cstddef>
11#include <cstdio>
12#include <deque>
13#include <fmt/core.h>
14#include <initializer_list>
15#include <optional>
16#include <string>
17#include <string_view>
18#include <type_traits>
19#include <utility>
20#include <variant>
21#include <vector>
22
23namespace uni20::presentation
24{
25
27enum class color_mode
28{
29 never,
31 always
32};
33
35enum class glyph_set
36{
37 unicode,
38 emoji,
39 ascii
40};
41
43enum class text_charset
44{
45 utf8,
48};
49
51enum class width_mode
52{
53 bytes,
55};
56
59{
60 narrow,
61 wide
62};
63
65enum class invalid_utf8
66{
67 escape,
69};
70
72enum class ornament_mode
73{
74 none,
75 minimal,
76 rich
77};
78
80enum class real_notation
81{
82 general,
83 fixed,
85};
86
89{
90 left,
91 right,
92 center,
94};
95
98{
99 single,
101};
102
114
117{
118 success,
119 failure,
120 fatal,
121 warning,
122 info,
123 partial,
124 deferred,
125 skipped,
128 arrow_up,
131 ellipsis,
146 box_cross,
172 tree_last,
175 bullet,
182};
183
198
205
212
213using presentation_span = std::variant<styled_text_span, semantic_glyph_span>;
214
217 public:
222 styled_text& append(std::string_view text, terminal::TerminalStyle style = {});
223
229
233 styled_text& append(styled_text const& other);
234
237 [[nodiscard]] bool empty() const noexcept;
238
241 [[nodiscard]] std::vector<presentation_span> const& spans() const noexcept;
242
243 private:
244 std::vector<presentation_span> spans_;
245};
246
252 public:
254 text_style() = default;
255
258 explicit text_style(terminal::TerminalStyle style) : style_(std::move(style)) {}
259
262 explicit text_style(std::string_view spec) : style_(spec) {}
263
266 explicit text_style(char const* spec) : text_style(spec != nullptr ? std::string_view(spec) : std::string_view{}) {}
267
270 [[nodiscard]] terminal::TerminalStyle const& terminal_style() const noexcept { return style_; }
271
275 [[nodiscard]] styled_text operator()(std::string_view text) const
276 {
277 styled_text result;
278 result.append(text, style_);
279 return result;
280 }
281
285 [[nodiscard]] styled_text operator()(char const* text) const
286 {
287 return (*this)(text != nullptr ? std::string_view(text) : std::string_view{});
288 }
289
294 {
295 styled_text result;
296 result.append(glyph, style_);
297 return result;
298 }
299
304 template <typename T>
305 requires(!std::is_convertible_v<T &&, std::string_view> && !std::same_as<std::remove_cvref_t<T>, semantic_glyph>)
306 [[nodiscard]] styled_text operator()(T&& value) const
307 {
308 styled_text result;
309 result.append(fmt::format("{}", std::forward<T>(value)), style_);
310 return result;
311 }
312
318 template <typename... Args>
319 requires(sizeof...(Args) > 0)
320 [[nodiscard]] styled_text operator()(fmt::format_string<Args...> format, Args&&... args) const
321 {
322 styled_text result;
323 result.append(fmt::format(format, std::forward<Args>(args)...), style_);
324 return result;
325 }
326
331 [[nodiscard]] styled_text operator()(semantic_glyph glyph, std::string_view text) const
332 {
333 styled_text result;
334 result.append(glyph, style_).append(" ").append(text, style_);
335 return result;
336 }
337
342 [[nodiscard]] styled_text operator()(semantic_glyph glyph, char const* text) const
343 {
344 return (*this)(glyph, text != nullptr ? std::string_view(text) : std::string_view{});
345 }
346
353 template <typename... Args>
354 requires(sizeof...(Args) > 0)
355 [[nodiscard]] styled_text operator()(semantic_glyph glyph, fmt::format_string<Args...> format, Args&&... args) const
356 {
357 styled_text result;
358 result.append(glyph, style_).append(" ").append(fmt::format(format, std::forward<Args>(args)...), style_);
359 return result;
360 }
361
362 private:
364};
365
369[[nodiscard]] inline text_style style(terminal::TerminalStyle style) { return text_style(std::move(style)); }
370
374[[nodiscard]] inline text_style style(std::string_view spec) { return text_style(spec); }
375
379[[nodiscard]] inline text_style style(char const* spec) { return text_style(spec); }
380
387
398
401{
403 std::size_t span = 1;
404 std::optional<table_alignment> alignment = std::nullopt;
405
406 table_cell() = default;
407 table_cell(std::string_view text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
408 : span(span_), alignment(alignment_)
409 {
411 }
412 table_cell(char const* text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
413 : table_cell(text != nullptr ? std::string_view(text) : std::string_view{}, span_, alignment_)
414 {}
415 table_cell(std::string text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
416 : table_cell(std::string_view(text), span_, alignment_)
417 {}
418 table_cell(styled_text text, std::size_t span_ = 1, std::optional<table_alignment> alignment_ = std::nullopt)
419 : content(std::move(text)), span(span_), alignment(alignment_)
420 {}
421};
422
428[[nodiscard]] inline table_cell cell(styled_text content, std::size_t span = 1,
429 std::optional<table_alignment> alignment = std::nullopt)
430{
431 return table_cell(std::move(content), span, alignment);
432}
433
439[[nodiscard]] inline table_cell cell(std::string_view text, std::size_t span = 1,
440 std::optional<table_alignment> alignment = std::nullopt)
441{
442 return table_cell(text, span, alignment);
443}
444
450[[nodiscard]] inline table_cell cell(char const* text, std::size_t span = 1,
451 std::optional<table_alignment> alignment = std::nullopt)
452{
453 return table_cell(text, span, alignment);
454}
455
456namespace detail
457{
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); }
463
464template <typename T> [[nodiscard]] table_cell make_table_cell(T const& value)
465{
466 return table_cell(fmt::format("{}", value));
467}
468} // namespace detail
469
475
476using table_entry = std::variant<std::vector<table_cell>, table_separator>;
477
480 public:
483 explicit report_table(std::string title = {});
484
490
494 report_table& row(std::vector<std::string> cells);
495
499 report_table& row(std::vector<table_cell> cells);
500
504 report_table& row(std::initializer_list<table_cell> cells);
505
510
515
520
525
529 report_table& outer_border(bool enabled = true);
530
534 report_table& column_separators(bool enabled = true);
535
539 report_table& row_separators(bool enabled = true);
540
544 report_table& header_separator(bool enabled = true);
545
549 report_table& grid(bool enabled = true);
550
555
558 report_table& preserve_tokens(bool enabled = true);
559
564 template <typename... Values> report_table& row(Values const&... values)
565 {
566 return this->row(std::vector<table_cell>{detail::make_table_cell(values)...});
567 }
568
571 [[nodiscard]] std::string const& title() const noexcept;
572
575 [[nodiscard]] std::vector<table_column> const& columns() const noexcept;
576
579 [[nodiscard]] std::vector<table_entry> const& entries() const noexcept;
580
583 [[nodiscard]] std::vector<table_rule_style> const& top_separators() const noexcept;
584
587 [[nodiscard]] table_border_options const& border_options() const noexcept;
588
590 [[nodiscard]] bool preserves_tokens() const noexcept;
591
592 private:
593 std::string title_;
594 std::vector<table_column> columns_;
595 std::vector<table_entry> entries_;
596 std::vector<table_rule_style> top_separators_;
597 table_border_options border_options_;
598 bool preserve_tokens_ = false;
599};
600
603 public:
606 explicit report_builder(std::string title = {});
607
612 report_builder& status(semantic_glyph glyph, std::string label);
613
620 report_builder& field(std::string key, std::string value);
621
627 template <typename Value> report_builder& field(std::string key, Value const& value)
628 {
629 return this->field(std::move(key), fmt::format("{}", value));
630 }
631
635 report_table& table(std::string title);
636
639 [[nodiscard]] std::string const& title() const noexcept;
640
643 [[nodiscard]] std::vector<std::pair<semantic_glyph, std::string>> const& statuses() const noexcept;
644
647 [[nodiscard]] std::vector<std::pair<std::string, std::string>> const& fields() const noexcept;
648
651 [[nodiscard]] std::deque<report_table> const& tables() const noexcept;
652
653 private:
654 std::string title_;
655 std::vector<std::pair<semantic_glyph, std::string>> statuses_;
656 std::vector<std::pair<std::string, std::string>> fields_;
657 std::deque<report_table> tables_;
658};
659
663[[nodiscard]] output_policy terminal_policy(std::FILE* stream = stdout);
664
667[[nodiscard]] output_policy plain_policy();
668
673
677[[nodiscard]] bool should_emit_color(output_policy const& policy);
678
683[[nodiscard]] std::string render_glyph(semantic_glyph glyph, output_policy const& policy);
684
689[[nodiscard]] std::string render_text(std::string_view text, output_policy const& policy);
690
695[[nodiscard]] std::string render(styled_text const& text, output_policy const& policy);
696
702[[nodiscard]] std::string render_terminal(styled_text const& text, output_policy policy, std::FILE* stream = stdout);
703
708[[nodiscard]] std::string render_plain(styled_text const& text, output_policy policy = plain_policy());
709
715[[nodiscard]] std::string render_strict_ascii(styled_text const& text,
718
730[[nodiscard]] styled_text render_report(report_builder const& report, output_policy const& policy);
731
737[[nodiscard]] std::string render_terminal(report_builder const& report, output_policy policy,
738 std::FILE* stream = stdout);
739
744[[nodiscard]] std::string render_plain(report_builder const& report, output_policy policy = plain_policy());
745
751[[nodiscard]] std::size_t display_width(std::string_view text, output_policy const& policy,
752 std::size_t initial_column = 0);
753
759[[nodiscard]] std::size_t display_width(styled_text const& text, output_policy const& policy,
760 std::size_t initial_column = 0);
761
767[[nodiscard]] std::string pad_left(std::string_view text, std::size_t target_width, output_policy const& policy);
768
774[[nodiscard]] styled_text pad_left(styled_text const& text, std::size_t target_width, output_policy const& policy);
775
781[[nodiscard]] std::string pad_right(std::string_view text, std::size_t target_width, output_policy const& policy);
782
788[[nodiscard]] styled_text pad_right(styled_text const& text, std::size_t target_width, output_policy const& policy);
789
795[[nodiscard]] std::string pad_center(std::string_view text, std::size_t target_width, output_policy const& policy);
796
802[[nodiscard]] styled_text pad_center(styled_text const& text, std::size_t target_width, output_policy const& policy);
803
810[[nodiscard]] std::string clip_to_width(std::string_view text, std::size_t max_width, output_policy const& policy,
811 std::size_t initial_column = 0);
812
820[[nodiscard]] std::string truncate_to_width(std::string_view text, std::size_t max_width, output_policy const& policy,
821 std::string_view marker = "", std::size_t initial_column = 0);
822
830[[nodiscard]] std::string truncate_left_to_width(std::string_view text, std::size_t max_width,
831 output_policy const& policy, std::string_view marker = "",
832 std::size_t initial_column = 0);
833
840[[nodiscard]] std::string prefix_lines(std::string_view text, std::string_view prefix, output_policy const& policy,
841 bool prefix_first = true);
842
849[[nodiscard]] std::string indent_text(std::string_view text, std::size_t spaces, output_policy const& policy,
850 bool indent_first = true);
851
857[[nodiscard]] std::vector<std::string> wrap_text(std::string_view text, std::size_t max_width,
858 output_policy const& policy);
859
865[[nodiscard]] std::vector<styled_text> wrap_text(styled_text const& text, std::size_t max_width,
866 output_policy const& policy);
867
872template <uni20::Real T> [[nodiscard]] int real_precision(numeric_format_options const& options)
873{
874 if constexpr (std::is_same_v<std::remove_cv_t<T>, float>)
875 {
876 return options.float32_precision;
877 }
878 else if constexpr (std::is_same_v<std::remove_cv_t<T>, double>)
879 {
880 return options.float64_precision;
881 }
882#if UNI20_HAS_FLOAT128
883 else if constexpr (std::is_same_v<std::remove_cv_t<T>, uni20::float128>)
884 {
885 return options.float128_precision;
886 }
887#endif
888 else
889 {
890 return options.long_double_precision;
891 }
892}
893
907
913template <uni20::Real T> [[nodiscard]] std::string format_real(T value, numeric_format_options const& options)
914{
916 uni20::scalar_format_options{.precision = real_precision<T>(options),
917 .notation = core_notation(options.notation),
918 .normalize_negative_zero = options.normalize_negative_zero,
919 .imaginary_unit = std::string_view(options.imaginary_unit)});
920}
921
927template <uni20::Complex T>
928[[nodiscard]] std::string format_complex(T const& value, numeric_format_options const& options)
929{
930 using real_type = uni20::make_real_t<T>;
932 value, uni20::scalar_format_options{.precision = real_precision<real_type>(options),
933 .notation = core_notation(options.notation),
934 .normalize_negative_zero = options.normalize_negative_zero,
935 .imaginary_unit = std::string_view(options.imaginary_unit)});
936}
937
943template <typename T> [[nodiscard]] std::string format_scalar(T const& value, numeric_format_options const& options)
944{
945 using value_type = std::remove_cvref_t<T>;
946 if constexpr (uni20::Real<value_type>)
947 {
948 return format_real(value, options);
949 }
950 else if constexpr (uni20::Complex<value_type>)
951 {
952 return format_complex(value, options);
953 }
954 else
955 {
956 return fmt::format("{}", value);
957 }
958}
959
960namespace detail
961{
962[[nodiscard]] inline terminal::TerminalStyle nonfinite_scalar_style()
963{
964 return terminal::TerminalStyle(std::string_view("Red;Bold"));
965}
966} // namespace detail
967
976template <typename T>
977[[nodiscard]] std::string style_nonfinite_scalar(std::string text, T const& value, output_policy const& policy)
978{
979 using value_type = std::remove_cvref_t<T>;
981 {
982 if (!uni20::isfinite(value) && should_emit_color(policy) && !text.empty())
983 {
984 return terminal::color_text(text, detail::nonfinite_scalar_style());
985 }
986 }
987 return text;
988}
989
997template <typename T>
998[[nodiscard]] std::string format_scalar_for_output(T const& value, numeric_format_options const& options,
999 output_policy const& policy)
1000{
1001 return style_nonfinite_scalar(format_scalar(value, options), value, policy);
1002}
1003
1004} // namespace uni20::presentation
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.
Definition qnum.hpp:403
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
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
Numeric scalar formatting controls shared by tensor-style renderers.
Definition presentation.hpp:105
int float64_precision
Definition presentation.hpp:107
std::string imaginary_unit
Definition presentation.hpp:112
real_notation notation
Definition presentation.hpp:110
int float128_precision
Definition presentation.hpp:109
int float32_precision
Definition presentation.hpp:106
int long_double_precision
Definition presentation.hpp:108
bool normalize_negative_zero
Definition presentation.hpp:111
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
Formatting options for Uni20 real and complex scalars.
Definition scalar_io.hpp:38
int precision
Definition scalar_io.hpp:39