Porytiles
Loading...
Searching...
No Matches
porytiles::FileHighlightPrinter Class Reference

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.
 

Detailed Description

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:

8: some_config: value
9: another_config: value
> 10: highlighted_line: value
11: next_config: value
12: last_config: value

Definition at line 31 of file file_highlight_printer.hpp.

Constructor & Destructor Documentation

◆ FileHighlightPrinter()

porytiles::FileHighlightPrinter::FileHighlightPrinter ( gsl::not_null< const TextFormatter * >  format)
explicit

Constructs a FileHighlightPrinter with a text formatter for styling.

Parameters
formatThe text formatter to use for styled output

Definition at line 85 of file file_highlight_printer.cpp.

Member Function Documentation

◆ print() [1/4]

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.

Parameters
fileThe path to the file for printing
line_indices_to_highlight0-indexed line indices to highlight (index 0 is the first line)
window_sizeTotal number of context lines to show around highlighted line, defaults to 9
Precondition
All indices in line_indices_to_highlight must be < lines.size()
Returns
Formatted output lines ready for display

Definition at line 197 of file file_highlight_printer.cpp.

◆ print() [2/4]

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.

Parameters
fileThe path to the file for printing
line_index_to_highlight0-indexed line index to highlight
col_to_highlight0-indexed column position to highlight within the line
window_sizeTotal number of context lines to show around highlighted line, defaults to 9
Precondition
line_index_to_highlight must be < lines.size()
col_to_highlight must be < lines[line_index_to_highlight].size()
Returns
Formatted output lines ready for display

Definition at line 206 of file file_highlight_printer.cpp.

◆ print() [3/4]

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).

Parameters
linesThe file contents as a vector of strings (one per line)
line_indices_to_highlight0-indexed line indices to highlight (index 0 is the first line)
window_sizeTotal number of context lines to show around highlighted line, defaults to 9
Precondition
All indices in line_indices_to_highlight must be < lines.size()
Returns
Formatted output lines ready for display

Definition at line 87 of file file_highlight_printer.cpp.

◆ print() [4/4]

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.

Parameters
linesThe file contents as a vector of strings (one per line)
line_index_to_highlight0-indexed line index to highlight
col_to_highlight0-indexed column position to highlight within the line
window_sizeTotal number of context lines to show around highlighted line, defaults to 9
Precondition
line_index_to_highlight must be < lines.size()
col_to_highlight must be < lines[line_index_to_highlight].size()
Returns
Formatted output lines ready for display

Definition at line 135 of file file_highlight_printer.cpp.


The documentation for this class was generated from the following files: