hyperion::assert::highlight#
- group highlight
This module provides an API for setting and querying
hyperion::assert’s syntax highlighting, powered by libfmt styling functionality, as well functionality to syntax highlight arbitrary strings containing C++ code in a libfmt-compatible way.Example#
constexpr auto keyword_color = hyperion::assert::highlight::Color(0xC67ADA_u32); constexpr auto keyword_highlight = hyperion::assert::highlight::Highlight { .kind = hyperion::assert::tokens::Keyword{}, .color = keyword_color, }; hyperion::assert::highlight::register_highlight(keyword_highlight); highlighted = hyperion::assert::highlight::highlight("auto my_cpp_code = 42;");
Functions
-
auto highlight(std::string_view str, bool first_token_is_function = false) -> std::string#
Highlights the given string in a way compatible with libfmt’s styling functionality, according to the currently configured highlighting style, and returns the result as a new
std::string- Parameters:
str – the string to do syntax highlighting on
first_token_is_function – Whether the first token in the given string is known to represent a function (to prevent it from being highlighted as a variable)
- Returns:
The syntax highlighted string
-
auto register_highlight(const Highlight &_highlight)#
Registers the given syntax highlighting setting in
hyperion::assert’s syntax highlighting configuration.- Parameters:
_highlight – The syntax highlighting setting to register
-
auto register_highlight(Highlight &&_highlight)#
Registers the given syntax highlighting setting in
hyperion::assert’s syntax highlighting configuration.- Parameters:
_highlight – The syntax highlighting setting to register
-
auto register_highlights(const std::vector<Highlight> &highlights)#
Registers the given syntax highlighting settings in
hyperion::assert’s syntax highlighting configuration.- Parameters:
highlights – The syntax highlighting settings to register
-
auto register_highlights(std::vector<Highlight> &&highlights)#
Registers the given syntax highlighting settings in
hyperion::assert’s syntax highlighting configuration.- Parameters:
highlights – The syntax highlighting settings to register
-
auto get_color(const tokens::Kind &kind) noexcept -> Color#
Returns the syntax highlighting color currently registered in
hyperion::assert’s syntax highlighting configuration.- Parameters:
kind – The token kind to get the registered highlight color for
- Returns:
The registered color syntax highlight color for
kind
-
struct RgbColor#
- #include <hyperion/assert/highlight.h>
RgbColorrepresents a red-green-blue color, typically defined as a six-digit hexadecimal number (e.g.0x61AFEF)Public Functions
-
inline explicit(false) const expr RgbColor(const u32 hex) noexcept#
Constructs an
RgbColorfrom a six-digit hex number.- Parameters:
hex – the six-digit hex number representing the red, green, and blue color values
- inline explicit (false) const expr RgbColor(const fmt
Constructs an
RgbColorfrom a libfmtfmt::colortype.- Parameters:
color – the color
-
inline constexpr RgbColor(const u8 _red, const u8 _green, const u8 _blue) noexcept#
Constructs an
RgbColorfrom individual red, green, and blue color values.- Parameters:
_red – the red value
_green – the green value
_blue – the blue value
-
inline explicit(false) const expr operator u32() const noexcept#
Implicit conversion operator for
RgbColorto its numeric representation.- Returns:
the numeric representation of this
RgbColor
- explicit(false) const expr operator fmt constexpr auto operator== (const RgbColor &other) const noexcept -> bool=default
Implicit conversion operator for
RgbColorto the corresponding libfmtfmt::detail::color_typerepresentation.three-way comparison operator for
RgbColors
equality comparison operator for
RgbColors
-
inline explicit(false) const expr RgbColor(const u32 hex) noexcept#
-
class Color#
- #include <hyperion/assert/highlight.h>
Colorrepresents either a red-green-blue color value (i.e. anRgbColor), typically defined as a six-digit hexadecimal number (e.g.0x61AFEF), OR a libfmt terminal emulator color value (i.e.fmt::terminal_color)Public Functions
- inline explicit (false) const expr Color(const fmt
Constructs a
Coloras the given libfmtfmt::terminal_colorvalue.- Parameters:
color – The
fmt::terminal_colorvalue to construct thisColoras
-
inline explicit(false) const expr Color(const u32 rgb_hex) noexcept#
Constructs a
Coloras the given red-blue-green color.- Parameters:
rgb_hex – The red-blue-green color to construct this
Coloras, represented as a 6-digit hexadecimal number
-
inline constexpr auto is_term_color() const noexcept#
Returns whether this
Colorrepresents a terminal emulator color.- Returns:
whether this
Colorrepresents a libfmt terminal emulator color, i.e. afmt::terminal_color
-
inline constexpr auto term_color() const noexcept -> std::optional<fmt::terminal_color>#
Returns the libfmt terminal color this
Colorrepresents, if it represents one.- Returns:
the
fmt::terminal_colorthisColorrepresents, orstd::nulloptif it doesn’t represent anfmt::terminal_color
-
inline constexpr auto is_rgb_color() const noexcept#
-
union storage#
- #include <highlight.h>
implicit conversion operator for
Colorto the corresponding libfmtfmt::detail::color_typerepresentationthree-way comparison operator for
ColorsWhen `this` and `other` represent different types of colors (i.e. `this->is_term_color() != other.is_term_color()`), `this` is defined to compare as less than `other` when both of `this->is_term_color()` and `other.is_rgb_color()` are true, and vice versa @return how this `Color` orders relative to `other`
equality comparison operator for
ColorsWhen `this` and `other` represent the same type of color (i.e. `this->is_term_color() == other.is_term_color()`), returns the result of directly comparing the color values they represent. Otherwise, returns `false`. @return whether this `Color` is equal to `other`
storage implementation for
Color- Return:
the libfmt color type representation of this
Color
Public Functions
- inline explicit (false) const expr storage(const fmt
-
auto highlight(std::string_view str, bool first_token_is_function = false) -> std::string#