aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroy <[email protected]>2026-06-29 21:32:00 +0300
committerroy <[email protected]>2026-06-29 21:32:00 +0300
commit0fdb0405b6567aed4cd00637f79410ceeafd2e3b (patch)
tree816301b144f5fa95d52b44d343524ebf6710c026
parent9bde54a7c3922c2e325748b8e5591a00bf439980 (diff)
Added background color options. Added README.md.
-rw-r--r--LICENSE24
-rw-r--r--README.md29
-rw-r--r--terminal-game-utils.hpp22
3 files changed, 70 insertions, 5 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..efb9808
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,24 @@
+This is free and unencumbered software released into the public domain.
+
+Anyone is free to copy, modify, publish, use, compile, sell, or
+distribute this software, either in source code form or as a compiled
+binary, for any purpose, commercial or non-commercial, and by any
+means.
+
+In jurisdictions that recognize copyright laws, the author or authors
+of this software dedicate any and all copyright interest in the
+software to the public domain. We make this dedication for the benefit
+of the public at large and to the detriment of our heirs and
+successors. We intend this dedication to be an overt act of
+relinquishment in perpetuity of all present and future rights to this
+software under copyright law.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+For more information, please refer to <https://unlicense.org/>
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1b5a10e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,29 @@
+# Introduction
+
+This is a small C++ library with small methods to change the behaviour and colors of the terminal.
+
+# Usage
+
+Import normally with:
+
+
+```#include "terminal-game-utils.hpp"```
+```
+```
+
+And use tgu:: to refer to the methods/enum in the library.
+
+## API:
+
+Enum GameKey - Arrow keys, space, escape, A-Z.
+GetKeyPress() - Only works if raw mode is enabled. Retrieves the next key pressed, trying to parse the bytes to one of the options available in GameKey.
+Enable/DisableRawMode() - Enable/disable raw mode (take input by bytes, without waiting for a newline/enter).
+Enter/LeaveGameBuffer() - Enable a temporary buffer for drawing the game.
+TextGreen/Red/Blue - Change the text/foreground to one of 3 colors.
+TextRGB(int r, int g, int b) - Change the text/foreground to any RGB color.
+BGGreen/Red/Blue - Change the background to one of 3 colors.
+BGRGB(int r, int g, int b) - Change the background to any RGB color.
+TerminalColorReset - Resets foreground AND background to defaults.
+MoveCursor(int row, int col) - Moves cursor to a specific row and column.
+
+Feel free to use this anywhere at all.
diff --git a/terminal-game-utils.hpp b/terminal-game-utils.hpp
index 0e41074..328ff63 100644
--- a/terminal-game-utils.hpp
+++ b/terminal-game-utils.hpp
@@ -6,7 +6,7 @@
#include <termios.h>
#include <unistd.h>
-namespace TGU {
+namespace tgu {
inline struct termios orig_termios;
@@ -152,7 +152,7 @@ inline GameKey GetKeyPress() {
return KeyMap[keypress_string];
}
-// Terminal color printers:
+// Text printers:
inline void TextGreen() { std::cout << "\033[32m"; }
@@ -160,12 +160,24 @@ inline void TextRed() { std::cout << "\033[31m"; }
inline void TextBlue() { std::cout << "\033[34m"; }
-inline void TextReset() { std::cout << "\033[0m"; }
-
inline void TextRGB(int r, int g, int b) {
std::cout << std::format("\033[38;2;{};{};{}m", r, g, b);
};
+// Background printers:
+
+inline void BGGreen() { std::cout << "\033[42m"; }
+
+inline void BGRed() { std::cout << "\033[41m"; }
+
+inline void BGBlue() { std::cout << "\033[44m"; }
+
+inline void BGRGB(int r, int g, int b) {
+ std::cout << std::format("\033[48;2;{};{};{}m", r, g, b);
+}
+
+inline void TerminalColorReset() { std::cout << "\033[0m"; }
+
// Game buffer printers:
inline void EnterGameBuffer() { std::cout << "\033[?1049h"; }
@@ -175,4 +187,4 @@ inline void LeaveGameBuffer() { std::cout << "\033[?1049l"; }
inline void MoveCursor(int row, int col) {
std::cout << "\033[" << row << ";" << col << "H" << std::flush;
}
-}; // namespace TGU
+}; // namespace tgu