|
Porytiles
|
A service for printing file lines with highlighted lines and line numbers. More...
#include <file_highlight_printer.hpp>
Public Member Functions | |
| FileHighlightPrinter (gsl::not_null< const TextFormatter * > format) | |
| Constructs a FileHighlightPrinter with a text formatter for styling. | |
| std::vector< std::string > | print (const std::vector< std::string > &lines, const std::vector< std::size_t > &line_indices_to_highlight, std::size_t window_size=9) const |
| Prints lines with specified lines highlighted and line numbers shown. | |
| std::vector< std::string > | print (const std::vector< std::string > &lines, std::size_t line_index_to_highlight, std::size_t col_to_highlight, std::size_t window_size=9) const |
| Prints lines with a specific line and column highlighted. | |
| std::vector< std::string > | print (const std::filesystem::path &file, const std::vector< std::size_t > &line_indices_to_highlight, std::size_t window_size=9) const |
| Filesystem path-based overload. | |
| std::vector< std::string > | print (const std::filesystem::path &file, std::size_t line_index_to_highlight, std::size_t col_to_highlight, std::size_t window_size=9) const |
| Filesystem path-based overload. | |
A service for printing file lines with highlighted lines and line numbers.
FileHighlightPrinter formats file content for display with specific lines highlighted. It's useful for showing contextual views of source files around error or warning locations. The output includes line numbers and visual highlighting (arrow prefix and styling) for the specified lines.
Example output:
Definition at line 31 of file file_highlight_printer.hpp.
|
explicit |
Constructs a FileHighlightPrinter with a text formatter for styling.
| format | The text formatter to use for styled output |
Definition at line 85 of file file_highlight_printer.cpp.
| std::vector< std::string > porytiles::FileHighlightPrinter::print | ( | const std::filesystem::path & | file, |
| const std::vector< std::size_t > & | line_indices_to_highlight, | ||
| std::size_t | window_size = 9 |
||
| ) | const |
Filesystem path-based overload.
| file | The path to the file for printing |
| line_indices_to_highlight | 0-indexed line indices to highlight (index 0 is the first line) |
| window_size | Total number of context lines to show around highlighted line, defaults to 9 |
Definition at line 197 of file file_highlight_printer.cpp.
| std::vector< std::string > porytiles::FileHighlightPrinter::print | ( | const std::filesystem::path & | file, |
| std::size_t | line_index_to_highlight, | ||
| std::size_t | col_to_highlight, | ||
| std::size_t | window_size = 9 |
||
| ) | const |
Filesystem path-based overload.
| file | The path to the file for printing |
| line_index_to_highlight | 0-indexed line index to highlight |
| col_to_highlight | 0-indexed column position to highlight within the line |
| window_size | Total number of context lines to show around highlighted line, defaults to 9 |
Definition at line 206 of file file_highlight_printer.cpp.
| std::vector< std::string > porytiles::FileHighlightPrinter::print | ( | const std::vector< std::string > & | lines, |
| const std::vector< std::size_t > & | line_indices_to_highlight, | ||
| std::size_t | window_size = 9 |
||
| ) | const |
Prints lines with specified lines highlighted and line numbers shown.
Creates a formatted view of the given lines, showing a window of context around the highlighted lines. Each line in the output includes a prefix (arrow for highlighted lines), line number, and the line content. Highlighted lines are styled with bold/italic/yellow formatting.
When multiple lines are highlighted, the window expands to show all highlighted lines plus context around them. Line numbers are displayed as 1-indexed in the output (matching user expectations), but the input indices are 0-indexed (matching vector indices).
| lines | The file contents as a vector of strings (one per line) |
| line_indices_to_highlight | 0-indexed line indices to highlight (index 0 is the first line) |
| window_size | Total number of context lines to show around highlighted line, defaults to 9 |
Definition at line 87 of file file_highlight_printer.cpp.
| std::vector< std::string > porytiles::FileHighlightPrinter::print | ( | const std::vector< std::string > & | lines, |
| std::size_t | line_index_to_highlight, | ||
| std::size_t | col_to_highlight, | ||
| std::size_t | window_size = 9 |
||
| ) | const |
Prints lines with a specific line and column highlighted.
Creates a formatted view showing a window of context around the highlighted line. The specified column is highlighted with underline styling, and a caret indicator line is added below the highlighted line pointing to the column position.
| lines | The file contents as a vector of strings (one per line) |
| line_index_to_highlight | 0-indexed line index to highlight |
| col_to_highlight | 0-indexed column position to highlight within the line |
| window_size | Total number of context lines to show around highlighted line, defaults to 9 |
Definition at line 135 of file file_highlight_printer.cpp.