Skip to content

Instantly share code, notes, and snippets.

@Bktero
Last active March 3, 2021 09:10
Show Gist options
  • Save Bktero/fb0beea33f07799713e37b8e62f8245b to your computer and use it in GitHub Desktop.
Save Bktero/fb0beea33f07799713e37b8e62f8245b to your computer and use it in GitHub Desktop.
[C++] Colored text in console with library Rang
cmake_minimum_required(VERSION 3.17)
project(hello_rang)
set(CMAKE_CXX_STANDARD 11)
# Get library from Github
include(FetchContent)
FetchContent_Declare(rang GIT_REPOSITORY https://github.com/agauniyal/rang.git GIT_TAG v3.1.0)
FetchContent_MakeAvailable(rang)
# Create executable
add_executable(hello_rang main.cpp)
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${rang_SOURCE_DIR}/include)
#include "rang.hpp"
int main() {
std::cout << rang::style::italic << rang::bg::green << rang::fg::red << "hello, ";
std::cout << rang::style::underline << rang::bgB::green << rang::fgB::red << "colored world";
std::cout << rang::style::reset << rang::bg::reset << rang::fg::reset << '\n';
}
@Bktero
Copy link
Author

Bktero commented Feb 16, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment