 |
Gorgon Game Engine
|
Go to the documentation of this file.
4 #include "../Geometry/Size.h"
5 #include "../Geometry/Point.h"
6 #include "../Graphics/Color.h"
9 namespace Gorgon {
namespace Utils {
21 Console(ConsoleBackend &backend) : backend(&backend), refcount(new int{1}) {
25 Console(
const Console &other) : backend(other.backend), refcount(other.refcount) {
69 return backend !=
nullptr;
73 explicit operator bool()
const {
return IsReady(); }
134 ConsoleBackend *backend =
nullptr;
135 int *refcount =
nullptr;
139 class ConsoleBackend {
141 virtual ~ConsoleBackend() { }
145 virtual bool IsStylesSupported()
const = 0;
155 virtual void Reset() = 0;
157 virtual void SetBold(
bool value) = 0;
159 virtual void SetUnderline(
bool value) = 0;
161 virtual void SetItalic(
bool value) = 0;
163 virtual void SetNegative(
bool value) = 0;
169 virtual void ClearScreen() = 0;
171 virtual void HideCaret() = 0;
173 virtual void ShowCaret() = 0;
175 virtual std::ostream &OutStream()
const = 0;
178 class StdOutBackend :
public ConsoleBackend {
182 virtual bool IsStylesSupported()
const override;
186 virtual void SetColor(Graphics::RGBA color)
override;
190 virtual void SetBackground(Graphics::RGBA color)
override;
192 virtual void Reset()
override;
194 virtual void SetBold(
bool value)
override;
196 virtual void SetUnderline(
bool value)
override;
198 virtual void SetItalic(
bool value)
override;
200 virtual void SetNegative(
bool value)
override;
206 virtual void ClearScreen()
override;
208 virtual void HideCaret()
override;
210 virtual void ShowCaret()
override;
212 virtual std::ostream &OutStream()
const override {
return std::cout; }
216 inline Console StdConsole() {
217 static Console stdconsole = {*
new StdOutBackend};
223 #define __mychk assert(refcount)
227 if(&other ==
this)
return *
this;
230 if(--(*refcount) <= 0) {
236 backend = other.backend;
237 refcount = other.refcount;
245 if(!refcount)
return;
247 if(--(*refcount) <= 0) {
254 __mychk;
return backend->ColorSupport();
258 __mychk;
return backend->IsStylesSupported();
262 __mychk; backend->SetColor(color);
266 __mychk; backend->SetColor(color);
270 __mychk; backend->SetBackground(color);
274 __mychk; backend->SetBackground(color);
278 __mychk; backend->Reset();
282 __mychk; backend->SetBold(bold);
286 __mychk; backend->SetUnderline(underline);
290 __mychk; backend->SetUnderline(italic);
294 __mychk; backend->SetNegative(negative);
298 __mychk;
return backend->GetSize();
310 __mychk; backend->GotoXY(location);
314 __mychk; backend->ClearScreen();
318 __mychk; backend->HideCaret();
322 __mychk; backend->ShowCaret();
327 __mychk;
return backend->OutStream();
Geometry::Size GetSize() const
Returns the size of the console window in cols/rows.
ColorSupportLevel
Level of support for color.
Definition: Console.h:35
void SetColor(Graphics::RGBA color)
Sets the color to the given value, avoid, black and white as console can have its background color re...
This class represents a color information.
Definition: Color.h:91
void SetUnderline(bool underline=true)
Enable/disable underline. Not all consoles support underline.
std::string GetFilename(std::string path)
Returns the filename portion of a file path.
Definition: Filesystem.h:183
int GetHeight() const
Returns the size of the console window in cols/rows.
Color
The colors that can be used for console coloring. This is a safe list.
Definition: Console.h:47
void Reset()
Resets terminal attributes.
bool IsReady() const
Returns if the console is usable.
Definition: Console.h:68
void GotoXY(int x, int y)
Changes the position of the caret to the given position.
Definition: Console.h:120
T_ Height
Height of this size object.
Definition: Size.h:261
void SetColor(Color color)
Sets the color to the given value, avoid, black and white as console can have its background color re...
@ Red
Definition: Console.h:51
@ None
Color is not supported.
Definition: Console.h:37
std::string GetDirectory(std::string filepath)
Returns the directory portion of a file path.
Definition: Filesystem.h:167
@ Safelist
Only colors in the safelist can be used.
Definition: Console.h:40
bool IsStylesSupported() const
Returns if color is supported in this terminal. Even if this is false, bold can be emulated.
basic_Size< int > Size
Definition: Size.h:385
void SetBold(bool bold=true)
Sets terminal font to bold or normal.
std::ostream & OutStream() const
@ White
Definition: Console.h:50
void ClearScreen()
Clears the console screen.
int GetWidth() const
Returns the size of the console window in cols/rows.
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
Console manipulation functions. Not thread safe. Current only std::cout is supported.
Definition: Console.h:14
basic_Point< int > Point
Definition: Point.h:598
@ Blue
Definition: Console.h:53
void SetBackground(Graphics::RGBA color)
Sets the background color to the given value. Use Default to set it to default color.
void SetNegative(bool negative=true)
Background/foreground is switched.
This class represents a 2D point.
Definition: Point.h:32
bool IsColorSupported() const
Returns if the color is supported by this console.
Definition: Console.h:63
void HideCaret()
Hides input cursor.
@ Cyan
Definition: Console.h:52
@ Yellow
Definition: Console.h:54
@ RGB
Graphics::RGBA can be used for color.
Definition: Console.h:43
std::string ExePath()
Returns the the full path of the application.
Definition: Linux.cpp:226
T_ Width
Width of this size object.
Definition: Size.h:258
std::vector< T_ >::const_iterator end(enum_type_id< T_ >)
Definition: Enum.h:288
@ Default
Definition: Console.h:48
@ Black
Definition: Console.h:49
Console(const Console &other)
Console objects can be copied. They are reference counted.
Definition: Console.h:25
void SetItalic(bool italic=true)
Enable/disable italic. Not all consoles support italic.
void GotoXY(Geometry::Point location)
Changes the position of the caret to the given position.
std::string Canonical(const std::string &path)
Canonicalizes a given relative path.
Definition: Linux.cpp:94
void SetBackground(Color color)
Sets the background color to the given value. Use Default to set it to default color.
Console(ConsoleBackend &backend)
Creates a new console with the specified backend.
Definition: Console.h:21
void ShowCaret()
Shows input cursor.
@ Green
Definition: Console.h:56
std::string demangle(const std::string &name)
Definition: Compiler_GCC.cpp:8
Console & operator=(const Console &other)
Console objects can be copied. They are reference counted.
ColorSupportLevel ColorSupport() const
Returns if color is supported in this terminal.
Console()=default
Empty console, nothing can be done with it.
@ Magenta
Definition: Console.h:55