SOLVED CASE CLOSED cout in color and perror - revisited
-
SOLVED CASE CLOSED Thanks for all the help from the group. It is much appreciated. Ask Mrs Google for "Eclipse ANSI" . The question remains why it works without the 3rd part plug in when the app is crosscompiled. I hope it will not bother the group if I revisit this , now multiple issue. 1. The attached C++ code DOES NOT execute in expected sequence. Both perror output in red, which is expected , but out of expected sequence. 2. The setw works as expected. 3. The cout "escape sequence " DOES NOT change color and also outputs the sequence as "control characters". It works well in crosscomplied code. The code fails using tools implementing "standard" "hello word" on local machine. This SAME code works as expected running after the application is crosscompiled for "remote" machine. And has been working well for few months of development. As far as I can tell - implementing "control / escape " characters in cout does not require anything special - iostream should work .
cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; perror("TEST perror "); cout << setw(30) << "\\033\[1;31mbold red text\\033\[0m\\n"; perror("TEST perror "); while(1);
TEST perror : Success printed in red
TEST perror : Invalid argument printed in red
START test area 334
main
START test area 336
main
[1;31mbold red text[0m shifted , but no color change -
SOLVED CASE CLOSED Thanks for all the help from the group. It is much appreciated. Ask Mrs Google for "Eclipse ANSI" . The question remains why it works without the 3rd part plug in when the app is crosscompiled. I hope it will not bother the group if I revisit this , now multiple issue. 1. The attached C++ code DOES NOT execute in expected sequence. Both perror output in red, which is expected , but out of expected sequence. 2. The setw works as expected. 3. The cout "escape sequence " DOES NOT change color and also outputs the sequence as "control characters". It works well in crosscomplied code. The code fails using tools implementing "standard" "hello word" on local machine. This SAME code works as expected running after the application is crosscompiled for "remote" machine. And has been working well for few months of development. As far as I can tell - implementing "control / escape " characters in cout does not require anything special - iostream should work .
cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; perror("TEST perror "); cout << setw(30) << "\\033\[1;31mbold red text\\033\[0m\\n"; perror("TEST perror "); while(1);
TEST perror : Success printed in red
TEST perror : Invalid argument printed in red
START test area 334
main
START test area 336
main
[1;31mbold red text[0m shifted , but no color changeWith cout you can do it directly without the escape code
cout << ansi::foreground_red << "bold red text" << ansi::foreground_white << endl;
In vino veritas
-
With cout you can do it directly without the escape code
cout << ansi::foreground_red << "bold red text" << ansi::foreground_white << endl;
In vino veritas
-
SOLVED CASE CLOSED Thanks for all the help from the group. It is much appreciated. Ask Mrs Google for "Eclipse ANSI" . The question remains why it works without the 3rd part plug in when the app is crosscompiled. I hope it will not bother the group if I revisit this , now multiple issue. 1. The attached C++ code DOES NOT execute in expected sequence. Both perror output in red, which is expected , but out of expected sequence. 2. The setw works as expected. 3. The cout "escape sequence " DOES NOT change color and also outputs the sequence as "control characters". It works well in crosscomplied code. The code fails using tools implementing "standard" "hello word" on local machine. This SAME code works as expected running after the application is crosscompiled for "remote" machine. And has been working well for few months of development. As far as I can tell - implementing "control / escape " characters in cout does not require anything special - iostream should work .
cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; cout << " START test area " << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl; perror("TEST perror "); cout << setw(30) << "\\033\[1;31mbold red text\\033\[0m\\n"; perror("TEST perror "); while(1);
TEST perror : Success printed in red
TEST perror : Invalid argument printed in red
START test area 334
main
START test area 336
main
[1;31mbold red text[0m shifted , but no color changeI just tried your code after correcting it, and it worked fine printing "bold red text" in bold red. What is that
while(1);
statement supposed to be for? Also, why are your results shown in a different order to the actual instructions in your code sample? -
I just tried your code after correcting it, and it worked fine printing "bold red text" in bold red. What is that
while(1);
statement supposed to be for? Also, why are your results shown in a different order to the actual instructions in your code sample? -
I suppose asking to share your solution is out of the question. Since this is a TEST code , the while(1); purpose is to stop code flow.
It's nothing special, just print the start test line, then two samples of perror, the first with no error, and the second with error 5.
cout << "Function: " << __FUNCTION__ << endl;
cout << " START test area " << __LINE__ << endl;
errno = 0;
perror("\033[1;31mTEST perror "); // print the error details in red
cout << "\033[0m\n"; // restore to standard colours
errno = 5;
perror("\033[1;31mTEST perror ");
cout << "\033[0m\n";Quote:
Since this is a TEST code , the while(1); purpose is to stop code flow.
Not sure what that means as there is nothing to stop.
-
It's nothing special, just print the start test line, then two samples of perror, the first with no error, and the second with error 5.
cout << "Function: " << __FUNCTION__ << endl;
cout << " START test area " << __LINE__ << endl;
errno = 0;
perror("\033[1;31mTEST perror "); // print the error details in red
cout << "\033[0m\n"; // restore to standard colours
errno = 5;
perror("\033[1;31mTEST perror ");
cout << "\033[0m\n";Quote:
Since this is a TEST code , the while(1); purpose is to stop code flow.
Not sure what that means as there is nothing to stop.
Unfortunately that is not a solution. Edited perror always prints in red - using stderr / cerr . Maybe I should just switch from cout to cerr to output in red, Please observe that escape codes, which are still ignored, are printed instead of being reacted on. That is THE ISSUE, the usage of while is NOT related to the issue at all. I believe this is related either to complier or operating system. I am searching for a solution in that direction for now. Any other suggestions are welcome.
cout << "Function: " << \_\_FUNCTION\_\_ << endl; cout << " START test area " << \_\_LINE\_\_ << endl; errno = 0; perror("TEST perror "); // default print in red perror("\\033\[1;31mTEST perror "); // print the error details in red cout << "\\033\[0m\\n"; // restore to standard colours errno = 5; perror("\\033\[1;31mTEST perror "); cout << "\\033\[0m\\n"; printf("%c\[%dmHELLO!\\n", 0x1B, 32); const std::string red("\\033\[0;31m"); cout << red << "red text" << endl; system("Color 1A"); system("Color 1B"); std::cout << "\\t\\t\\t Hello World" << std::endl; cout << "Bluetooth client " << endl; cout << " START test area " << dec << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl;
Function: main
START test area 39
[0m
[0m
[32mHELLO!
[0;31mred text
TEST perror : Success
[1;31mTEST perror : Invalid argument
[1;31mTEST perror : Input/output error
sh: 1: Color: not found
sh: 1: Hello World
Bluetooth client
START test area 58
main
set color @line [31m 443
set color @line [31m 449
PROGREESS TRACE START -
Unfortunately that is not a solution. Edited perror always prints in red - using stderr / cerr . Maybe I should just switch from cout to cerr to output in red, Please observe that escape codes, which are still ignored, are printed instead of being reacted on. That is THE ISSUE, the usage of while is NOT related to the issue at all. I believe this is related either to complier or operating system. I am searching for a solution in that direction for now. Any other suggestions are welcome.
cout << "Function: " << \_\_FUNCTION\_\_ << endl; cout << " START test area " << \_\_LINE\_\_ << endl; errno = 0; perror("TEST perror "); // default print in red perror("\\033\[1;31mTEST perror "); // print the error details in red cout << "\\033\[0m\\n"; // restore to standard colours errno = 5; perror("\\033\[1;31mTEST perror "); cout << "\\033\[0m\\n"; printf("%c\[%dmHELLO!\\n", 0x1B, 32); const std::string red("\\033\[0;31m"); cout << red << "red text" << endl; system("Color 1A"); system("Color 1B"); std::cout << "\\t\\t\\t Hello World" << std::endl; cout << "Bluetooth client " << endl; cout << " START test area " << dec << \_\_LINE\_\_ << endl; cout << \_\_FUNCTION\_\_ << endl;
Function: main
START test area 39
[0m
[0m
[32mHELLO!
[0;31mred text
TEST perror : Success
[1;31mTEST perror : Invalid argument
[1;31mTEST perror : Input/output error
sh: 1: Color: not found
sh: 1: Hello World
Bluetooth client
START test area 58
main
set color @line [31m 443
set color @line [31m 449
PROGREESS TRACE STARTTaking your code above and running it produces the following output:
C:\Users\rjmac\Documents\Code\C++>Test
Function: DoTest
START test area 17
TEST perror : No error --> in normal black
TEST perror : No error --> in bold redTEST perror : Input/output error --> in bold red
HELLO! --> in green
red text --> everything from here in normal red
Hello World
Bluetooth client
START test area 36
DoTestWhich does not match with what you have produced. I can only conclude that there is something else going on in your system, or the actual code you run is different, that you are not telling us about.