Skip to content

Conversation

codeinred
Copy link
Contributor

This PR adds support for a break_before_filename option on the formatter (see #259 for examples & more information).

The following functions have been added to the API of the library:

class formatter {
    // ...

    // When printing the stacktrace, inserts a linebreak prior after the symbol name,
    // and inserts enough whitespace to align the filename with the symbol name.
    formatter& break_before_filename(bool do_break = true);

    // Formats an individual frame, with the given amount of extra whitespace added before the filename
    // in the event of a linebreak. This is needed because oftentimes an individual frame is printed
    // _after_ some identifier, such as the index of the frame within the trace, and if this information
    // is not taken into account, the filename will be misaligned.
    std::string format(const stacktrace_frame&, bool color, size_t filename_indent) const;

    // Same as above, but to a std::ostream&
    void print(std::ostream&, const stacktrace_frame&, bool color, size_t filename_indent) const;
    
    // Same as above, but with std::FILE*
    void print(std::FILE*, const stacktrace_frame&, bool color, size_t filename_indent) const;
}

Unit tests were added in test/unit/lib/formatting.cpp.

…y-rifkin#259)

Enables users to instruct the formatter to insert a linebreak before the
filename, when displaying a trace. The filename will be aligned with the
symbol.
Ensures that the break_before_filename() feature plays nice with other
formatting options, and correctly computes alignment in all cases.
Copy link
Owner

@jeremy-rifkin jeremy-rifkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

@jeremy-rifkin jeremy-rifkin merged commit becedb1 into jeremy-rifkin:dev Jun 23, 2025
105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants