Sorry And C++
Sorry I haven’t posted on here in awhile, i’ve been really busy with the AI’s, here’s a program they wrote just now:
C++
#include <iostream>
#include <string>
#include <vector>
// A simple namespace to hold the style codes for organization
namespace Style {
const char* RESET = "\033[0m";
const char* BOLD = "\033[1m";
const char* DIM = "\033[2m";
const char* ITALIC = "\033[3m";
const char* UNDERLINE = "\033[4m";
const char* BLINK = "\033[5m";
const char* REVERSE = "\033[7m";
}
// Function to print the basic 16 colors (8 standard, 8 bright)
void print_basic_colors() {
std::cout << Style::BOLD << Style::UNDERLINE << "\n--- Basic 16 Colors ---\n" << Style::RESET;
std::vector<std::string> colors = {"Black", "Red", "Green", "Yellow", "Blue", "Magenta", "Cyan", "White"};
// Standard Text Colors (30-37)
std::cout << "\nStandard Text:\n";
for (int i = 0; i < 8; ++i) {
std::cout << "\033[3" << i << "m" << colors[i] << "\t" << Style::RESET;
}
std::cout << std::endl;
// Bright Text Colors (90-97)
std::cout << "\nBright Text:\n";
for (int i = 0; i < 8; ++i) {
std::cout << "\033[9" << i << "m" << colors[i] << "\t" << Style::RESET;
}
std::cout << std::endl;
// Standard Background Colors (40-47)
std::cout << "\nStandard Backgrounds:\n";
for (int i = 0; i < 8; ++i) {
std::cout << "\033[4" << i << "m " << colors[i] << " \t" << Style::RESET << " ";
}
std::cout << std::endl;
// Bright Background Colors (100-107)
std::cout << "\nBright Backgrounds:\n";
for (int i = 0; i < 8; ++i) {
std::cout << "\033[10" << i << "m " << colors[i] << " \t" << Style::RESET << " ";
}
std::cout << std::endl;
}
// Function to print the 256-color palette, extended to 1000 examples
void print_extended_palette(int start_index) {
int end_index = start_index + 1000;
std::cout << Style::BOLD << Style::UNDERLINE << "\n--- Color Choices (" << start_index << "-" << end_index - 1 << ") ---\n" << Style::RESET;
std::cout << "Text: \\033[38;5;{CODE}m | Background: \\033[48;5;{CODE}m\n\n";
for (int i = start_index; i < end_index; ++i) {
// Use the modulo operator (%) to wrap the color code within the 0-255 range
int color_code = i % 256;
// Set the foreground color
std::cout << "\033[38;5;" << color_code << "m";
// Print the color index, padded for alignment
if (i < 10) std::cout << " ";
else if (i < 100) std::cout << " ";
else if (i < 1000) std::cout << " ";
std::cout << i;
std::cout << Style::RESET;
// Add a newline every 20 colors to make a grid
if ((i + 1) % 20 == 0) {
std::cout << std::endl;
}
}
std::cout << std::endl;
}
// Function to demonstrate 24-bit "True Color"
void print_true_color_gradient() {
std::cout << Style::BOLD << Style::UNDERLINE << "\n--- 24-bit 'True Color' Gradient ---\n" << Style::RESET;
std::cout << "Text: \\033[38;2;R;G;Bm | Background: \\033[48;2;R;G;Bm\n\n";
// Red to Yellow Gradient
for (int g = 0; g <= 255; g += 5) {
std::cout << "\033[48;2;255;" << g << ";0m ";
}
std::cout << Style::RESET << " Red to Yellow\n";
// Green to Cyan Gradient
for (int b = 0; b <= 255; b += 5) {
std::cout << "\033[48;2;0;255;" << b << "m ";
}
std::cout << Style::RESET << " Green to Cyan\n";
// Blue to Magenta Gradient
for (int r = 0; r <= 255; r += 5) {
std::cout << "\033[48;2;" << r << ";0;255m ";
}
std::cout << Style::RESET << " Blue to Magenta\n";
// Grayscale Gradient
for (int i = 0; i <= 255; i += 5) {
std::cout << "\033[48;2;" << i << ";" << i << ";" << i << "m ";
}
std::cout << Style::RESET << " Grayscale\n";
}
int main() {
int current_start_index = 0;
while (true) {
// Clear the screen for a fresh display
// The \033[2J is the clear screen code, \033[1;1H moves the cursor to the top left
std::cout << "\033[2J\033[1;1H";
std::cout << "C++ ANSI Escape Code Demonstration for Ubuntu/Linux Terminals\n";
// Only show the basic colors and gradients on the first page
if (current_start_index == 0) {
print_basic_colors();
}
print_extended_palette(current_start_index);
if (current_start_index == 0) {
print_true_color_gradient();
}
std::cout << "\n" << Style::BOLD << "Press Enter to show the next 1,000 colors (or Ctrl+C to exit)..." << Style::RESET;
// Wait for the user to press Enter
std::cin.get();
// Increment the starting index for the next page
current_start_index += 1000;
}
std::cout << std::endl;
return 0;
}It prints colors to your terminal in C++, not everyone knows how to do this, which is why I am posting it. I told Google Gemini about my website and let’s see what it’s going to say about it hmm..
