Arkanjo 0.2
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
base.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <unordered_map>
4#include <functional>
5#include <string>
6
8
9enum class Format {
10 TEXT,
11 JSON,
12 AUTO
13};
14
15using StyleMap = std::unordered_map<std::string, Utils::COLOR>;
16using RowColorFn = std::function<Utils::COLOR(size_t)>;
17
19public:
20 virtual ~IFormatter() = default;
21 virtual std::string colorize(
22 const std::string& text,
23 Utils::COLOR color
24 ) const = 0;
25 virtual const StyleMap& style() const = 0;
26};
27
29public:
31 bool enable_color = true
32 )
33 : enabled(enable_color) {}
34
35 std::string colorize(
36 const std::string& text,
37 Utils::COLOR color
38 ) const override {
39 if (!enabled) return text;
40 return Utils::format_colored_message(text, color);
41 }
42
43 const StyleMap& style() const override {
44 return theme;
45 }
46
47 void set(const std::string& key, Utils::COLOR c) {
48 theme[key] = c;
49 }
50
51 void set_theme(const StyleMap& t) {
52 theme = t;
53 }
54
55private:
56 bool enabled;
57 StyleMap theme = {
58 {"file", Utils::COLOR::RED},
59 {"function", Utils::COLOR::BOLD},
60 {"number", Utils::COLOR::YELLOW},
61 {"bold", Utils::COLOR::BOLD},
62 {"warning", Utils::COLOR::MAGENTA},
63 {"row_even", Utils::COLOR::GRAY},
64 {"row_odd", Utils::COLOR::CYAN},
65 };
66};
std::unordered_map< std::string, Utils::COLOR > StyleMap
Definition base.hpp:15
Format
Definition base.hpp:9
std::function< Utils::COLOR(size_t)> RowColorFn
Definition base.hpp:16
void set_theme(const StyleMap &t)
Definition base.hpp:51
void set(const std::string &key, Utils::COLOR c)
Definition base.hpp:47
std::string colorize(const std::string &text, Utils::COLOR color) const override
Definition base.hpp:35
const StyleMap & style() const override
Definition base.hpp:43
ConsoleFormatter(bool enable_color=true)
Definition base.hpp:30
virtual ~IFormatter()=default
virtual const StyleMap & style() const =0
virtual std::string colorize(const std::string &text, Utils::COLOR color) const =0
std::string format_colored_message(const std::string &message, COLOR color)
Formats a message with ANSI color codes.
Definition utils.cpp:45
COLOR
Enumeration of available colors for formatted messages.
Definition utils.hpp:111
@ BOLD
Bold text.
Definition utils.hpp:123
@ MAGENTA
Magenta color.
Definition utils.hpp:117
@ GRAY
Gray color.
Definition utils.hpp:119
@ RED
Red color.
Definition utils.hpp:113
@ YELLOW
Yellow color.
Definition utils.hpp:115
@ CYAN
Cyan color.
Definition utils.hpp:118
Defines utility functions used across all files.