5 #include <Sawyer/CommandLine.h>
6 #include <Sawyer/Map.h>
111 static Ptr instance() {
129 return std::max(T(0), std::min(c, T(1)));
136 Component r_, g_, b_, a_;
143 RGB(): r_(1.0), g_(0.0), b_(0.0), a_(1.0) {}
146 RGB(Component r, Component g, Component b, Component a=1.0): r_(
clip(r)), g_(
clip(g)), b_(
clip(b)), a_(
clip(a)) {}
156 Component
r()
const {
return r_; }
157 Component
g()
const {
return g_; }
158 Component
b()
const {
return b_; }
159 Component
a()
const {
return a_; }
160 Component
red()
const {
return r_; }
161 Component
green()
const {
return g_; }
162 Component
blue()
const {
return b_; }
163 Component
alpha()
const {
return a_; }
167 std::string
toHtml()
const;
178 Component h_, s_, v_, a_;
185 HSV(): h_(0.0), s_(1.0), v_(0.5), a_(1.0) {}
188 HSV(Component h, Component s, Component v, Component a=1.0): h_(
clip(h)), s_(
clip(s)), v_(
clip(v)), a_(
clip(a)) {}
198 Component
h()
const {
return h_; }
199 Component
s()
const {
return s_; }
200 Component
v()
const {
return v_; }
201 Component
a()
const {
return a_; }
202 Component
hue()
const {
return h_; }
204 Component
value()
const {
return v_; }
205 Component
alpha()
const {
return a_; }
209 std::string
toHtml()
const;
250 colors_.
insert(0.0, color1);
251 colors_.
insert(1.0, color2);
276 HSV interpolate(
double)
const;
285 const ColorMap&
colorMap()
const {
return colors_; }
303 ROSE_UTIL_API HSV
darken(
const HSV&,
double amount);
309 ROSE_UTIL_API HSV
lighten(
const HSV&,
double amount);
315 ROSE_UTIL_API HSV
fade(
const HSV&,
double amount);
321 HSV
terminal(
const HSV &color,
const Colorization&);
326 ROSE_UTIL_API std::string
toHtml(
const RGB&);
338 std::ostream& operator<<(std::ostream&,
const RGB&);
339 std::ostream& operator<<(std::ostream&,
const HSV&);
340 std::ostream& operator<<(std::ostream&,
const Gradient&);
345 extern const HSV HSV_CLEAR;
346 extern const HSV HSV_BLACK;
347 extern const HSV HSV_WHITE;
348 extern const HSV HSV_RED;
349 extern const HSV HSV_GREEN;
350 extern const HSV HSV_BLUE;
351 extern const HSV HSV_CYAN;
352 extern const HSV HSV_MAGENTA;
353 extern const HSV HSV_YELLOW;
354 extern const HSV HSV_GRAY;
359 enum AnsiColor { ANSI_CLEAR, ANSI_RED, ANSI_GREEN, ANSI_YELLOW, ANSI_BLUE, ANSI_MAGENTA, ANSI_CYAN, ANSI_GRAY };
ROSE_UTIL_API HSV lighten(const HSV &, double amount)
Lighten a color.
std::vector< ParsedValue > ParsedValues
A vector of parsed values.
Control colored command output.
bool isEnabled() const
True if color is enabled in this situation.
void nanColor(const HSV &c)
Color for NaN lookups.
void insert(double where, const HSV &color)
Insert a point into the gradient.
const ValueSaver::Ptr valueSaver() const
Property: functor responsible for saving a parsed value in user storage.
RGB()
Default constructed color.
Colorization merge(const Colorization &) const
Merge this color and another to produce a result.
virtual Sawyer::CommandLine::ParsedValues operator()(const Sawyer::CommandLine::ParsedValues &prev, const Sawyer::CommandLine::ParsedValues &cur)
Called when a switch's value is about to be stored into the ParserResult.
HSV operator()(double x) const
Return a color for the specified position.
ColorMap & colorMap()
Reference to color map.
static Colorization parse(const char *input, const char **rest)
Parse a colorized output specification from a C string.
Component green() const
Component of color.
Component blue() const
Component of color.
Component red() const
Component of color.
Gradient()
Default constructor.
HSV()
Default constructed color.
Base class for value agumentors.
Main namespace for the ROSE library.
Map & clear()
Remove all nodes.
HSV terminal(const HSV &color, const Colorization &)
Adjust color for terminal.
HSV invertBrightness(const HSV &)
Invert the brightness.
AnsiColor
ANSI color names for terminal output.
Use colored output if standard output is a terminal.
const ColorMap & colorMap() const
Reference to color map.
static Ptr instance(const Sawyer::CommandLine::ValueSaver::Ptr &valueSaver)
Allocating constructor.
HSV(Component h, Component s, Component v, Component a=1.0)
Construct a color from components.
Sawyer::Optional< Enabled::Flag > enabled
Whether colored output is enabled.
void clear()
Remove all points from the gradient.
Information about a parsed switch value.
Component r() const
Component of color.
ROSE_UTIL_API std::string toAnsi(const RGB &, Layer::Flag layer)
Create an ANSI color escape.
static Ptr instance()
Allocating constructor.
Gradient(const HSV &color)
Construct a one-color gradient.
Component hue() const
Component of color.
static std::string docString()
Documentation for parser.
double Component
Type for color components.
ROSE_UTIL_API HSV darken(const HSV &, double amount)
Darken a color.
Light text on dark background.
Parses an output color specification.
Component value() const
Component of color.
Component g() const
Component of color.
Component a() const
Component of color.
Component alpha() const
Component of color.
Sawyer::Optional< Theme::Flag > theme
The color theme.
ROSE_UTIL_API HSV fade(const HSV &, double amount)
Make a color less saturated.
Sawyer::SharedPointer< ColorizationParser > Ptr
Shared ownership pointer to a ColorizationParser.
std::string ansiColorEscape(AnsiColor)
ANSI color escape for terminal output.
Gradient(const RGB &color)
Construct a one-color gradient.
Component b() const
Component of color.
Component a() const
Component of color.
Dark text on light background.
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
Position within a command-line.
Base class parsing a value from input.
ROSE_UTIL_API std::string toHtml(const RGB &)
Create an HTML color string.
Component h() const
Component of color.
Gradient(const HSV &color1, const HSV &color2)
Construct a mapping with two colors.
Component saturation() const
Component of color.
T clip(T c)
Clip a floating point value between 0 and 1.
Component s() const
Component of color.
Mapping from floating point to color.
const HSV & nanColor() const
Color for NaN lookups.
std::string colorName(AnsiColor)
Convert a color enum to a string.
Component v() const
Component of color.
Component alpha() const
Component of color.
RGB(Component r, Component g, Component b, Component a=1.0)
Construct a color specified by components.