address Andreas' comment about the using-declaration

This commit is contained in:
Laurent Rineau 2025-11-12 15:51:28 +01:00
parent 175b7b9241
commit 77bac5866b
1 changed files with 31 additions and 33 deletions

View File

@ -9,15 +9,13 @@
* ANSI colors.
*/
using CGAL::IO::Ansi_color;
void demonstrate_basic_colors() {
std::cout << "=== Basic Color Usage ===\n\n";
// Example 1: Single color
{
std::cout << "1. Single color (Red):\n";
CGAL::IO::Color_stream_guard guard(std::cout, Ansi_color::Red);
CGAL::IO::Color_stream_guard guard(std::cout, CGAL::IO::Ansi_color::Red);
std::cout << "This text is red\n";
std::cout << "All lines in this scope are red\n";
@ -29,17 +27,17 @@ void demonstrate_basic_colors() {
std::cout << "2. Different colors:\n";
{
CGAL::IO::Color_stream_guard green(std::cout, Ansi_color::Green);
CGAL::IO::Color_stream_guard green(std::cout, CGAL::IO::Ansi_color::Green);
std::cout << "Green text\n";
}
{
CGAL::IO::Color_stream_guard blue(std::cout, Ansi_color::Blue);
CGAL::IO::Color_stream_guard blue(std::cout, CGAL::IO::Ansi_color::Blue);
std::cout << "Blue text\n";
}
{
CGAL::IO::Color_stream_guard yellow(std::cout, Ansi_color::Yellow);
CGAL::IO::Color_stream_guard yellow(std::cout, CGAL::IO::Ansi_color::Yellow);
std::cout << "Yellow text\n";
}
}
@ -50,17 +48,17 @@ void demonstrate_basic_colors() {
std::cout << "3. Bright colors:\n";
{
CGAL::IO::Color_stream_guard bright_red(std::cout, Ansi_color::BrightRed);
CGAL::IO::Color_stream_guard bright_red(std::cout, CGAL::IO::Ansi_color::BrightRed);
std::cout << "Bright red text\n";
}
{
CGAL::IO::Color_stream_guard bright_green(std::cout, Ansi_color::BrightGreen);
CGAL::IO::Color_stream_guard bright_green(std::cout, CGAL::IO::Ansi_color::BrightGreen);
std::cout << "Bright green text\n";
}
{
CGAL::IO::Color_stream_guard bright_cyan(std::cout, Ansi_color::BrightCyan);
CGAL::IO::Color_stream_guard bright_cyan(std::cout, CGAL::IO::Ansi_color::BrightCyan);
std::cout << "Bright cyan text\n";
}
}
@ -74,7 +72,7 @@ void demonstrate_combined_colors() {
{
std::cout << "1. Bold colors:\n";
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Red});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Red});
std::cout << "This text is bold and red\n";
}
@ -84,7 +82,7 @@ void demonstrate_combined_colors() {
{
std::cout << "2. Underlined colors:\n";
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Underline, Ansi_color::Blue});
std::vector{CGAL::IO::Ansi_color::Underline, CGAL::IO::Ansi_color::Blue});
std::cout << "This text is underlined and blue\n";
}
@ -94,7 +92,7 @@ void demonstrate_combined_colors() {
{
std::cout << "3. Multiple attributes:\n";
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Underline, Ansi_color::Green});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Underline, CGAL::IO::Ansi_color::Green});
std::cout << "This text is bold, underlined, and green\n";
}
@ -106,7 +104,7 @@ void demonstrate_background_colors() {
{
std::cout << "1. Red background:\n";
CGAL::IO::Color_stream_guard guard(std::cout, Ansi_color::BgRed);
CGAL::IO::Color_stream_guard guard(std::cout, CGAL::IO::Ansi_color::BgRed);
std::cout << "Text with red background\n";
}
std::cout << "Back to normal\n\n";
@ -114,7 +112,7 @@ void demonstrate_background_colors() {
{
std::cout << "2. Foreground + background:\n";
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Yellow, Ansi_color::BgBlue});
std::vector{CGAL::IO::Ansi_color::Yellow, CGAL::IO::Ansi_color::BgBlue});
std::cout << "Yellow text on blue background\n";
}
std::cout << "Back to normal\n\n";
@ -122,7 +120,7 @@ void demonstrate_background_colors() {
{
std::cout << "3. Bold white on bright green background:\n";
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::White, Ansi_color::BgBrightGreen});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::White, CGAL::IO::Ansi_color::BgBrightGreen});
std::cout << "Bold white on bright green\n";
}
std::cout << "Back to normal\n\n";
@ -132,15 +130,15 @@ void demonstrate_nested_colors() {
std::cout << "=== Nested Color Scopes ===\n\n";
{
CGAL::IO::Color_stream_guard outer(std::cout, Ansi_color::Blue);
CGAL::IO::Color_stream_guard outer(std::cout, CGAL::IO::Ansi_color::Blue);
std::cout << "Outer scope: blue text\n";
{
CGAL::IO::Color_stream_guard inner(std::cout, Ansi_color::Red);
CGAL::IO::Color_stream_guard inner(std::cout, CGAL::IO::Ansi_color::Red);
std::cout << "Inner scope: red text\n";
{
CGAL::IO::Color_stream_guard innermost(std::cout, Ansi_color::Green);
CGAL::IO::Color_stream_guard innermost(std::cout, CGAL::IO::Ansi_color::Green);
std::cout << "Innermost scope: green text\n";
}
@ -158,24 +156,24 @@ void simulate_colored_debug_output() {
std::cout << "Algorithm: Starting computation\n";
{
CGAL::IO::Color_stream_guard info(std::cout, Ansi_color::Cyan);
CGAL::IO::Color_stream_guard info(std::cout, CGAL::IO::Ansi_color::Cyan);
std::cout << "INFO: Initializing data structures\n";
}
{
CGAL::IO::Color_stream_guard success(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Green});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Green});
std::cout << "SUCCESS: Data loaded successfully\n";
}
{
CGAL::IO::Color_stream_guard warning(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Yellow});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Yellow});
std::cout << "WARNING: Large dataset detected, may take longer\n";
}
{
CGAL::IO::Color_stream_guard processing(std::cout, Ansi_color::Blue);
CGAL::IO::Color_stream_guard processing(std::cout, CGAL::IO::Ansi_color::Blue);
std::cout << "Processing vertices...\n";
std::cout << "Processing edges...\n";
std::cout << "Processing faces...\n";
@ -183,7 +181,7 @@ void simulate_colored_debug_output() {
{
CGAL::IO::Color_stream_guard success(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Green});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Green});
std::cout << "SUCCESS: Computation completed\n";
}
@ -200,7 +198,7 @@ void demonstrate_multiple_streams() {
// Apply colors to both streams simultaneously
{
std::cout << "\nWith make_color_guards (Red):\n";
auto guards = CGAL::IO::make_color_guards(Ansi_color::Red, std::cout, std::cerr);
auto guards = CGAL::IO::make_color_guards(CGAL::IO::Ansi_color::Red, std::cout, std::cerr);
std::cout << "Red text on cout\n";
std::cerr << "Red text on cerr\n";
@ -214,7 +212,7 @@ void demonstrate_multiple_streams() {
{
std::cout << "\nBold green on multiple streams:\n";
auto guards = CGAL::IO::make_color_guards(
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Green},
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Green},
std::cout, std::clog);
std::cout << "cout: Bold green output\n";
@ -230,7 +228,7 @@ void test_color_detection() {
// Test automatic detection in streambuf
std::cout << "1. Testing automatic color detection in Basic_color_streambuf:\n";
{
CGAL::IO::Color_streambuf color_buf(*std::cout.rdbuf(), Ansi_color::Green);
CGAL::IO::Color_streambuf color_buf(*std::cout.rdbuf(), CGAL::IO::Ansi_color::Green);
std::cout << " Colors automatically detected as: " << (color_buf.colors_enabled() ? "ENABLED" : "DISABLED")
<< "\n";
@ -246,7 +244,7 @@ void test_color_detection() {
if(CGAL::IO::stream_supports_color(std::cout)) {
std::cout << " stdout supports colors: YES\n";
{
CGAL::IO::Color_stream_guard guard(std::cout, Ansi_color::Green);
CGAL::IO::Color_stream_guard guard(std::cout, CGAL::IO::Ansi_color::Green);
std::cout << " (This text should be green if color is truly supported)\n";
}
} else {
@ -261,7 +259,7 @@ void test_color_detection() {
if(CGAL::IO::stream_supports_color(std::cerr)) {
std::cout << " stderr supports colors: YES\n";
{
CGAL::IO::Color_stream_guard guard(std::cerr, Ansi_color::Yellow);
CGAL::IO::Color_stream_guard guard(std::cerr, CGAL::IO::Ansi_color::Yellow);
std::cerr << " (This text should be yellow if color is truly supported)\n";
}
} else {
@ -280,7 +278,7 @@ void test_color_detection() {
std::cout << "5. Automatic coloring example (no manual checking!):\n";
{
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Cyan});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Cyan});
std::cout << " This message is automatically colored only if terminal supports it!\n";
std::cout << " No need to check stream_supports_color() manually - it's automatic!\n";
}
@ -292,7 +290,7 @@ void test_color_detection() {
// Info message - colors applied automatically!
std::cout << " ";
{
CGAL::IO::Color_stream_guard guard(std::cout, Ansi_color::Cyan);
CGAL::IO::Color_stream_guard guard(std::cout, CGAL::IO::Ansi_color::Cyan);
std::cout << "INFO:";
}
std::cout << " Normal information message\n";
@ -301,7 +299,7 @@ void test_color_detection() {
std::cout << " ";
{
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Green});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Green});
std::cout << "SUCCESS:";
}
std::cout << " Operation completed successfully\n";
@ -310,7 +308,7 @@ void test_color_detection() {
std::cout << " ";
{
CGAL::IO::Color_stream_guard guard(std::cout,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Yellow});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Yellow});
std::cout << "WARNING:";
}
std::cout << " Potential issue detected\n";
@ -319,7 +317,7 @@ void test_color_detection() {
std::cerr << " ";
{
CGAL::IO::Color_stream_guard guard(std::cerr,
std::vector<Ansi_color>{Ansi_color::Bold, Ansi_color::Red});
std::vector{CGAL::IO::Ansi_color::Bold, CGAL::IO::Ansi_color::Red});
std::cerr << "ERROR:";
}
std::cerr << " Critical error occurred\n";