diff options
| author | _ov4 <ov4@ov4.org> | 2026-09-01 12:11:55 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-09-01 12:11:55 +0000 |
| commit | 20f554748ebbc80406f9a37800559089d3e80e2b (patch) | |
| tree | 1a39878a8aa4721970a02bc5691d6ea2e898cb25 | |
| parent | 66e23046f3e6766064ed570d6a6a1fa53a0b9d32 (diff) | |
color
| -rw-r--r-- | include/all.h | 1 | ||||
| -rw-r--r-- | include/util/color.h | 35 | ||||
| -rw-r--r-- | src/util/color.cc | 17 | ||||
| -rw-r--r-- | src/util/prompt.cc | 12 |
4 files changed, 59 insertions, 6 deletions
diff --git a/include/all.h b/include/all.h index 5141e37..67759cc 100644 --- a/include/all.h +++ b/include/all.h @@ -4,6 +4,7 @@ #include "util/io.h" #include "util/prompt.h" #include "util/string.h" +#include "util/color.h" #include "eval.h" #include "global.h" #include "ground.h" diff --git a/include/util/color.h b/include/util/color.h new file mode 100644 index 0000000..01711d6 --- /dev/null +++ b/include/util/color.h @@ -0,0 +1,35 @@ +#pragma once + +#include <string> + +namespace ov4 +{ + +std::string make_color(const std::string s, const std::string color); + +} + +namespace ov4::color +{ + +const std::string + black = "30", + red = "31", + green = "32", + yellow = "33", + blue = "34", + purple = "35", + cyan = "36", + white = "37"; + +const std::string + bright_black = "90", + bright_red = "91", + bright_green = "92", + bright_yellow = "93", + bright_blue = "94", + bright_purple = "95", + bright_cyan = "96", + bright_white = "97"; + +} diff --git a/src/util/color.cc b/src/util/color.cc new file mode 100644 index 0000000..87fd346 --- /dev/null +++ b/src/util/color.cc @@ -0,0 +1,17 @@ +#include "util/color.h" + +#include <string> + +#include "all.h" + +using namespace std; + +namespace ov4 +{ + +string make_color(const string s, const string color) +{ + return "\e[0;" + color + "m" + s + "\e[0m"; +} + +} diff --git a/src/util/prompt.cc b/src/util/prompt.cc index ac9137b..6ba1ea9 100644 --- a/src/util/prompt.cc +++ b/src/util/prompt.cc @@ -14,15 +14,15 @@ namespace ov4 char buffer[hostname_size]; gethostname(buffer, hostname_size); cout - << name + << make_color((string)name, ov4::color::bright_green) << " " - << getlogin() - << "@" - << buffer + << make_color(getlogin(), ov4::color::bright_blue) + << make_color("@", ov4::color::bright_blue) + << make_color(buffer, ov4::color::bright_blue) << ":" - << get_current_dir() + << make_color(get_current_dir(), ov4::color::bright_purple) << " " - << get_prompt() + << make_color(get_prompt(), ov4::color::bright_yellow) << " " << flush; } |
