Skip to content

Releases: bgorlick/colorterm

Colorterm v0.0.1

13 Jun 11:38
37f6cb4
Compare
Choose a tag to compare

v0.0.1 (Alpha)

ColorTerm - The Fastest Feature-Rich C++ Terminal Color Cross-Platform Header Only Library for adding vibrant colors to terminal output.

Features

  • Cross-platform support for Windows, Linux, and macOS
  • Highly optimized color application macros
  • Over 50 predefined foreground and background colors and effects
  • Support for 8-bit and 24-bit colors and gradients
  • Simple and intuitive API
  • Logger class for colored logs with log levels (INFO, DEBUG, ERROR, etc.)
  • Custom color and theme management
  • Built-in output formatter supporting JSON, XML, YAML, CSV, HTML, and plain text
  • Compile-time constants for color definitions
  • Efficient and flexible color application macros
  • Customizable color functions and custom palette management

Files included in this release:

  • README.md: Instructions and documentation for using the library.
  • colorterm.hpp: The header-only library file.
  • LICENSE_1_0.txt: License file for the library.
  • benchmark.cpp: Benchmarking file to test the performance of the library.

Quick Testing

To compile it with clang++, run the following command:

clang++ -std=c++17 -O3 -rtlib=compiler-rt -stdlib=libc++ -o benchmark benchmark.cpp \
      -I/usr/local/include/c++/v1 \
      -L/usr/local/lib \
      -lc++ -lc++abi -lunwind -lgcc_s -lgcc -lm -lc -v -ferror-limit=50

To compile with g++, run the following command:

g++ -std=c++17 -O3 -o benchmark benchmark.cpp \
    -I/usr/local/include/c++/v1 \
    -L/usr/local/lib \
    -lstdc++ -lunwind -lgcc_s -lgcc -lm -lc -v -fmax-errors=50

Then run the compiled binary to see some of the color features: ./benchmark --verify-all

Usage

Basic Usage:

#include "colorterm.hpp"

int main() {
    std::cout << colorterm::red << "Red text" << colorterm::reset << std::endl;
    Logger::info("This is an info message");
    Logger::error("This is an error message");
    OutputFormatter::to_json(std::cout, data);
    ThemeManager::create("my_theme");
    ThemeManager::set("my_theme");
    ThemeManager::insert("bracket", "[]", "\033[38;5;34m");
    std::cout << colorterm::custom_color("bracket") << "{\n" << colorterm::reset << std::endl;
    colorterm::apply_styles(std::cout, "bold", "underline", "purple") << "Bold, underlined, and purple text" << colorterm::reset << std::endl;
    colorterm::apply_gradient(std::cout, "This is a sentence with gradient color", 255, 0, 0, 0, 0, 255) << colorterm::reset << std::endl;
    return 0;
}

#### Theme Manager API
ThemeManager::create("my_theme");
ThemeManager::set("my_theme");
ThemeManager::insert("bracket", "[]", "\033[38;5;34m");
std::cout << colorterm::apply_theme("text to apply theme to") << std::endl;
std::unordered_map<char, std::string> colormap = ThemeManager::inspect_theme();
const std::string* color = ThemeManager::inspect_colormap_color('[');
const std::string* key_color = ThemeManager::inspect_key_color("name");
const std::string* value_color = ThemeManager::inspect_value_color("Alice");
std::vector<std::string> themes = ThemeManager::list_themes();
ThemeManager::replace("[]", "\033[38;5;40m");
ThemeManager::erase("[]");
ThemeManager::save("my_theme", "path/to/file");
ThemeManager::load("my_theme", "path/to/file");
ThemeManager::set_default();
ThemeManager::enable_colormap();
ThemeManager::disable_colormap();
bool enabled = ThemeManager::is_color_enabled();
std::string all_mappings = ThemeManager::list_all_theme_maps();

**Full Changelog**: https://github.com/bgorlick/colorterm/commits/v0.0.1