11#include <fmt/ostream.h>
17 return c ==
'(' || c ==
')' || c ==
'[' || c ==
']' || c ==
'{' || c ==
'}';
23 constexpr std::array pairing_color {
24 fmt::color::light_blue,
25 fmt::color::light_green,
26 fmt::color::light_salmon,
27 fmt::color::light_yellow,
28 fmt::color::light_cyan,
29 fmt::color::light_coral
32 constexpr std::size_t pairing_color_size = pairing_color.size();
34 for (
const char c : line)
70 const std::size_t pairing_color_index =
static_cast<std::size_t
>(std::abs(idx)) % pairing_color_size;
71 fmt::print(os,
"{}", fmt::styled(c, fmt::fg(pairing_color[pairing_color_index])));
74 fmt::print(os,
"{}", c);
79 const std::string& filename,
const std::size_t target_line,
80 const std::optional<std::size_t> end_target_line,
const bool colorize) :
81 m_should_colorize(colorize)
100 if (start.
line == end->line)
106 if (end->line - start.
line > 1)
108 for (std::size_t i = start.
line + 1; i <= end->line - 1; ++i)
114 code +=
"\n" +
m_source[end->line].substr(0, end->column);
128 assert(line_to_include <=
m_window.
start &&
"line_to_include has to be before the start of our base context, source of errors are always before our errors");
131 m_window.
start = line_to_include >= 3 ? line_to_include - 3 : 0;
155 fmt::print(os,
"\n");
163 fmt::print(os,
" ... |\n");
Lots of utilities about string, filesystem and more.
Constants used by ArkScript.
Lots of utilities about the filesystem.
Pretty printing utilities for diagnostics.
std::size_t m_current_line
std::string sliceCode(internal::FilePos start, const std::optional< internal::FilePos > &end) const
Slice the source code to get code between two cursors.
void extendWindow(std::size_t line_to_include)
Extend the window of lines to show, to include a given line. Useful to display the origin of an error...
Printer(const std::string &filename, std::size_t target_line, std::optional< std::size_t > end_target_line, bool colorize)
Create a new Printer object.
bool isTargetLine() const
Check if we printed the target line.
std::vector< std::string > m_source
LineColorContextCounts m_color_ctx
bool coversLine(std::size_t line_number) const
bool hasContent() const
Check if there are lines to print.
void printLine(std::ostream &os)
Print the current line and advance by one.
bool isPairableChar(const char c)
void colorizeLine(const std::string &line, LineColorContextCounts &ctx, std::ostream &os)
std::string readFile(const std::string &name)
Helper to read a file.
std::string & ltrim(std::string &s)
Remove spaces at the beginning of a string, in place.
std::vector< std::string > splitString(const std::string &source, const char sep)
Cut a string into pieces, given a character separator.
std::string & rtrim(std::string &s)
Remove spaces at the end of a string, in place.
std::optional< std::size_t > skip_start_at
std::optional< std::size_t > resume_at
std::size_t end
Last line of the context, not displayed.
std::size_t start
First line number to display.
std::size_t column
0-indexed column number
std::size_t line
0-indexed line number