HIPO  4.3.0
High Performance Output data format for experimental physics
style.h
Go to the documentation of this file.
1 
6 #ifndef INCLUDE_ASCII_STYLE_H_
7 #define INCLUDE_ASCII_STYLE_H_
8 #include "color.h"
9 
10 namespace ascii {
12 
19 class Style {
20 public:
23  : fg_(Foreground::From(Color::RESET)),
24  bg_(Background::From(Color::RESET)), decorations_({}) {}
25 
32  fg_ = fg;
33  return *this;
34  }
35 
42  bg_ = bg;
43  return *this;
44  }
45 
52  decorations_.push_back(decoration);
53  return *this;
54  }
55 
61  friend std::ostream &operator<<(std::ostream &os, const Style &val) {
62  for (auto &item : val.decorations_) {
63  os << item;
64  }
65  os << Foreground(val.fg_) << Background(val.bg_);
66  return os;
67  }
68 
69 private:
70  Foreground fg_;
71  Background bg_;
72  std::vector<Decoration> decorations_;
73 };
74 
75 } // namespace ascii
76 #endif // !INCLUDE_ASCII_STYLE_H_
ANSI background color escape sequence generator.
Definition: color.h:210
ANSI text decoration (bold, italic, underline, etc.).
Definition: color.h:105
ANSI foreground color escape sequence generator.
Definition: color.h:154
Combines foreground, background, and text decorations into a terminal style.
Definition: style.h:19
Style & bg(Background bg)
Set the background color for this style.
Definition: style.h:41
friend std::ostream & operator<<(std::ostream &os, const Style &val)
Output the style escape sequences to an output stream. Outputs all decorations first,...
Definition: style.h:61
Style & AddDecoration(Decoration decoration)
Add a text decoration to this style.
Definition: style.h:51
Style()
Default constructor. Initializes with reset colors and no decorations.
Definition: style.h:22
Style & fg(Foreground fg)
Set the foreground color for this style.
Definition: style.h:31
ANSI terminal color and decoration classes for styled output.
Color
Standard and bright ANSI terminal colors.
Definition: color.h:28
Definition: ascii.h:17