HIPO  4.3.0
High Performance Output data format for experimental physics
text.h
Go to the documentation of this file.
1 
6 #ifndef INCLUDE_ASCII_TEXT_H_
7 #define INCLUDE_ASCII_TEXT_H_
8 #include "style.h"
9 
10 namespace ascii {
12 
19 class Text {
20 public:
22  Text() {}
23 
28  Text(std::string text) : text_(text) {}
29 
35  Text(std::string text, Style style) : text_(text), style_(style) {}
36 
43  style_ = style;
44  return *this;
45  }
46 
52  Text &text(std::string text) {
53  text_ = text;
54  return *this;
55  }
56 
61  std::string text() { return text_; }
62 
68  friend std::ostream &operator<<(std::ostream &os, const Text &val) {
69  os << val.style_ << val.text_ << Decoration::From(Decoration::RESET);
70  return os;
71  }
72 
73 private:
74  std::string text_;
75  Style style_;
76 };
77 } // namespace ascii
78 #endif // !INCLUDE_ASCII_TEXT_H_
static Decoration From(Attribute attr)
Create a Decoration from an Attribute.
Definition: color.h:132
Combines foreground, background, and text decorations into a terminal style.
Definition: style.h:19
Styled text element for terminal output with ANSI color support.
Definition: text.h:19
Text(std::string text)
Construct a Text with the given string and default style.
Definition: text.h:28
friend std::ostream & operator<<(std::ostream &os, const Text &val)
Output the styled text to an output stream. Outputs the style, followed by the text content,...
Definition: text.h:68
Text()
Default constructor. Creates an empty text with default style.
Definition: text.h:22
Text & style(Style style)
Set the style for this text.
Definition: text.h:42
std::string text()
Get the text content.
Definition: text.h:61
Text(std::string text, Style style)
Construct a Text with the given string and style.
Definition: text.h:35
Text & text(std::string text)
Set the text content.
Definition: text.h:52
Definition: ascii.h:17
Style class combining foreground, background, and text decorations.