10#include <uni20/config.hpp>
12#if UNI20_HAS_STACKTRACE
24struct stacktrace_format_options
26 std::size_t indent = 2;
42inline styled_text format_stacktrace(std::stacktrace
const& stacktrace, output_policy
const& policy,
43 stacktrace_format_options
const& options = {})
46 std::size_t frame_index = 0;
47 auto const frame_count = stacktrace.size();
49 for (
auto const& frame : stacktrace)
51 bool const is_last = frame_index + 1 == frame_count;
52 std::string description = frame.description();
53 if (description.empty())
55 description =
"(unknown)";
62 prefix.
append(fmt::format(
"#{}", frame_index), options.index_style);
65 styled_text frame_text;
66 frame_text.
append(description, options.description_style);
67 if (!frame.source_file().empty())
70 frame_text.
append(frame.source_file(), options.source_file_style);
71 frame_text.
append(fmt::format(
":{}", frame.source_line()), options.source_line_style);
74 std::vector<styled_text>
lines{frame_text};
76 if (policy.wrap_width.has_value() && *policy.wrap_width > prefix_width)
78 lines =
wrap_text(frame_text, std::max<std::size_t>(*policy.wrap_width - prefix_width, 1), policy);
86 for (std::size_t line = 1; line <
lines.size(); ++line)
89 styled_text connector;
92 auto const connector_width =
display_width(connector, policy);
93 text.
append(std::string(prefix_width - options.indent - connector_width,
' '));
101 text.
append(std::string(options.indent,
' '));
102 text.
append(
"(empty stacktrace)", options.description_style);
Definition terminal.hpp:262
styled_text & append(std::string_view text, terminal::TerminalStyle style={})
Append a text span.
Definition presentation.cpp:1164
presentation::styled_text text
Definition display.cpp:141
Definition data_table.cpp:8
semantic_glyph
Names semantic glyphs independently of their rendered spelling.
Definition presentation.hpp:117
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
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
std::vector< styled_text > lines
Definition presentation.cpp:2015