-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansi_view.hpp
More file actions
40 lines (34 loc) · 1.38 KB
/
ansi_view.hpp
File metadata and controls
40 lines (34 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include "interfaces.hpp"
#include <string>
namespace FrogToad {
/**
* @brief ANSI terminal implementation of FrogToad::IView.
*
* Renders the board using ANSI escape sequences on a text console.
*/
class AnsiView : IView {
public:
AnsiView();
~AnsiView();
/**
* @brief Draw the current board state to the terminal.
* @param m Immutable board model to render.
*/
void draw(const BoardModel& m) override;
private:
// ANSI Escape Code Helpers
static const std::string resetStyles() { return "\x1b[0m"; }
static const std::string clearScreen() { return "\x1b[2J"; };
static const std::string hideCursor() { return "\x1b[?25l"; }
static const std::string showCursor() { return "\x1b[?25h"; }
static const std::string eraseAfter() { return "\x1b[0J"; }
static const std::string cursorHome() { return "\x1b[H"; }
static const std::string white() { return "\x1b[1m"; }
static const std::string grey() { return "\x1b[37m"; }
static const std::string red() { return "\x1b[38;5;196m"; }
static const std::string blue() { return "\x1b[38;5;33m"; }
static const std::string green() { return "\x1b[38;5;34m"; }
static const std::string bell() { return "\a"; }
};
}