10#include <initializer_list>
12#include <source_location>
111using event_content = std::variant<presentation::styled_text, presentation::report_builder>;
134 template <
typename String>
135 consteval format_string(String
const&
value, std::source_location location = std::source_location::current())
194 void row(std::vector<formatted_cell> cells, std::source_location where = std::source_location::current());
196 void row(std::vector<presentation::styled_text> cells,
197 std::source_location where = std::source_location::current());
198 void row(std::vector<std::string> cells, std::source_location where = std::source_location::current());
199 void row(std::initializer_list<std::string> cells, std::source_location where = std::source_location::current());
201 template <
typename... Values>
void row(Values&&... values);
215 std::vector<column_spec> columns_;
216 std::vector<std::size_t> widths_;
217 std::vector<std::optional<std::size_t>> decimal_positions_;
218 bool header_separator_ =
true;
219 bool header_emitted_ =
false;
220 bool widths_resolved_ =
false;
221 bool vertical_fallback_ =
false;
224 void ensure_can_change_schema()
const;
225 void resolve_widths();
226 void expand_fit_columns(std::vector<formatted_cell>
const& cells);
227 void emit_rows(std::vector<formatted_cell>
const& cells, std::source_location where);
235template <
typename... Args>
237 checked_format_string<Args...> format, Args&&... args);
241 std::source_location where = std::source_location::current());
245 std::source_location where = std::source_location::current());
248template <
typename... Args>
252template <
typename... Args>
void info(checked_format_string<Args...> format, Args&&... args);
255template <
typename... Args>
void success(checked_format_string<Args...> format, Args&&... args);
258template <
typename... Args>
void warning(checked_format_string<Args...> format, Args&&... args);
261template <
typename... Args>
void failure(checked_format_string<Args...> format, Args&&... args);
264template <
typename... Args>
void fatal(checked_format_string<Args...> format, Args&&... args);
267template <
typename... Args>
void partial(checked_format_string<Args...> format, Args&&... args);
270template <
typename... Args>
void deferred(checked_format_string<Args...> format, Args&&... args);
273template <
typename... Args>
void skipped(checked_format_string<Args...> format, Args&&... args);
280inline constexpr bool display_numeric_value =
281 std::is_arithmetic_v<std::remove_cvref_t<T>> && !std::is_same_v<std::remove_cvref_t<T>,
bool> &&
282 !std::is_same_v<std::remove_cvref_t<T>,
char> && !std::is_same_v<std::remove_cvref_t<T>,
signed char> &&
283 !std::is_same_v<std::remove_cvref_t<T>,
unsigned char>;
285[[nodiscard]]
inline bool expects_number(column_format
const& format)
292 auto const exception = expects_number(format);
293 return formatted_cell{.text = std::move(
value), .decimal_candidate =
false, .decimal_exception = exception};
298 return make_text_cell(std::move(
value), format);
301[[nodiscard]]
inline formatted_cell format_cell_value(column_format
const& format,
304 return make_text_cell(
value.content, format);
315[[nodiscard]]
inline formatted_cell format_cell_value(column_format
const& format,
char const*
value)
317 auto const exception = expects_number(format);
318 return formatted_cell{.text = make_plain_cell(
value !=
nullptr ? std::string_view(
value) :
std::string_view{},
319 exception ? format.exception_style : format.
style),
324template <
typename T> [[nodiscard]] formatted_cell format_cell_value(column_format
const& format, T&&
value)
327 if constexpr (display_numeric_value<T>)
329 auto const numeric = expects_number(format);
331 auto text = make_plain_cell(numeric ? fmt::format(fmt::runtime(format.pattern), std::forward<T>(
value))
333 finite ? format.
style : format.exception_style);
334 return formatted_cell{.text = std::move(
text),
335 .decimal_candidate = numeric && finite,
336 .decimal_exception = numeric && !finite,
337 .keep_together =
true};
339 else if constexpr (std::is_same_v<value_type, std::string>)
341 auto const exception = expects_number(format);
342 return formatted_cell{
343 .text = make_plain_cell(std::forward<T>(
value), exception ? format.exception_style : format.
style),
347 else if constexpr (std::is_same_v<value_type, std::string_view>)
349 auto const exception = expects_number(format);
350 return formatted_cell{.text = make_plain_cell(
value, exception ? format.exception_style : format.
style),
354 else if constexpr (std::is_array_v<value_type>)
356 auto const exception = expects_number(format);
357 return formatted_cell{
358 .text = make_plain_cell(std::string_view(
value), exception ? format.exception_style : format.
style),
362 else if constexpr (std::is_convertible_v<T, char const*>)
364 return format_cell_value(format,
static_cast<char const*
>(
value));
368 auto const exception = expects_number(format);
369 return formatted_cell{.text = make_plain_cell(fmt::format(
"{}", std::forward<T>(
value)),
370 exception ? format.exception_style : format.
style),
377template <
typename... Args>
387template <
typename... Args>
435 std::vector<formatted_cell> cells;
436 cells.reserve(
sizeof...(Values));
437 std::size_t column = 0;
438 ((cells.push_back(detail::format_cell_value(column < columns_.size() ? columns_[column].format :
column_format{},
439 std::forward<Values>(values))),
442 this->emit_rows(cells, std::source_location::current());
Definition terminal.hpp:262
Temporarily replace the display sink and restore it on destruction.
Definition display.hpp:153
scoped_sink & operator=(scoped_sink const &)=delete
~scoped_sink()
Definition display.cpp:838
scoped_sink(scoped_sink const &)=delete
Schema-first table for progress output where rows are emitted immediately.
Definition display.hpp:170
void row(std::vector< formatted_cell > cells, std::source_location where=std::source_location::current())
Emit preformatted cells without discarding their numeric alignment semantics.
Definition display.cpp:448
streaming_table & header_separator(bool enabled=true)
Definition display.cpp:441
streaming_table & output(sink destination, presentation::output_policy policy)
Route this table through an instance-owned sink and policy, without changing global display routing.
Definition display.cpp:779
streaming_table & column(std::string heading, column_width width_spec=width::share(), presentation::table_alignment alignment=presentation::table_alignment::right, column_format format={})
streaming_table & wrap_width(std::size_t width)
Definition display.cpp:434
streaming_table & column(std::string heading, presentation::table_alignment alignment, column_format format)
Add a flexible-width column with explicit alignment and format.
streaming_table & column(std::string heading, presentation::table_alignment alignment)
Add a flexible-width column with an explicit alignment.
Builder for simple terminal reports with headings, status lines, fields, and tables.
Definition presentation.hpp:602
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
locale_t value
Definition data_table.cpp:49
bool decimal_exception
Definition display.cpp:150
bool decimal_candidate
Definition display.cpp:149
std::size_t width
Definition display.cpp:142
constexpr bool isfinite(I const &x) noexcept
Returns whether an integer scalar is finite.
Definition math.hpp:121
column_width share(std::size_t weight, std::size_t minimum)
Request a flexible streaming table column with the given share weight.
Definition display.cpp:308
Definition display.cpp:16
void set_sink(sink replacement)
Replace the process-wide display sink.
Definition display.cpp:802
void warning(checked_format_string< Args... > format, Args &&... args)
Emit a non-fatal warning display message.
Definition display.hpp:403
void info(checked_format_string< Args... > format, Args &&... args)
Emit an informational display message.
Definition display.hpp:393
void skipped(checked_format_string< Args... > format, Args &&... args)
Emit a skipped/unavailable display message.
Definition display.hpp:428
presentation::styled_text status_cell(presentation::semantic_glyph glyph, checked_format_string< Args... > format, Args &&... args)
Build styled status text without emitting it.
Definition display.hpp:378
stream
Selects the ordinary display stream for a message.
Definition display.hpp:25
std::variant< presentation::styled_text, presentation::report_builder > event_content
Presentation payload carried to a display sink before final rendering.
Definition display.hpp:111
void emit(presentation::styled_text text, stream destination, bool newline, std::source_location where)
Emit styled text through the active display sink.
Definition display.cpp:843
streaming_table table(std::string title, stream destination)
Create a schema-first streaming display table.
Definition display.cpp:800
void deferred(checked_format_string< Args... > format, Args &&... args)
Emit an intentionally deferred display message.
Definition display.hpp:423
column_width_mode
Width allocation mode for a streaming display table column.
Definition display.hpp:32
void reset_sink()
Restore the default C++ terminal display sink.
Definition display.cpp:809
void failure(checked_format_string< Args... > format, Args &&... args)
Emit a failure display message.
Definition display.hpp:408
sink current_sink()
Return a copy of the active display sink.
Definition display.cpp:815
std::function< void(event const &)> sink
Callable that receives display events for final routing and rendering.
Definition display.hpp:126
column_value_kind
Semantic value type expected by a streaming table column.
Definition display.hpp:64
void fatal(checked_format_string< Args... > format, Args &&... args)
Emit a fatal-status display message.
Definition display.hpp:413
void status(presentation::semantic_glyph glyph, checked_format_string< Args... > format, Args &&... args)
Emit a semantic status message through the active display sink.
Definition display.hpp:388
std::type_identity_t< format_string< Args... > > checked_format_string
Non-deduced format-string parameter type used by display helper templates.
Definition display.hpp:141
typename optional_traits< T >::value_type value_type
Definition data_table.hpp:42
semantic_glyph
Names semantic glyphs independently of their rendered spelling.
Definition presentation.hpp:117
table_alignment
Selects table cell alignment in report-style output.
Definition presentation.hpp:89
terminal::TerminalStyle style
Definition presentation.cpp:2434
table_alignment alignment
Definition presentation.cpp:2018
std::optional< semantic_glyph > glyph
Definition presentation.cpp:2435
Schema-level width request for a streaming display table column.
Definition display.hpp:40
std::size_t value
Definition display.hpp:42
std::size_t minimum
Definition display.hpp:43
column_width_mode mode
Definition display.hpp:41
Human-facing display event routed through the active sink.
Definition display.hpp:115
std::string context
Definition display.hpp:119
bool newline
Definition display.hpp:118
stream destination
Definition display.hpp:116
event_content content
Definition display.hpp:117
std::source_location where
Definition display.hpp:120
bool preserve_layout
Sinks must retain the supplied line breaks without applying additional wrapping.
Definition display.hpp:122
Output policy shared by presentation renderers and layout helpers.
Definition presentation.hpp:186
Cell specification for table rows, including optional style, column span, and alignment.
Definition presentation.hpp:401