|
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
|
|
|
|
|
OK, stupid follow-up question.
How / where I activate "ansi"?
|
|
|
|
|
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 "); cout << "\033[0m\n"; 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 "); perror("\033[1;31mTEST perror "); cout << "\033[0m\n"; 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
modified 21-Dec-19 15:38pm.
|
|
|
|
|
Taking 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 red
TEST 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
DoTest
Which 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.
|
|
|
|
|
Yet another "problem" got me stumped.
To verify "networking" I use system call such as
system("vim /etc/hosts");
It does the job, however, I cannot figure out how to close the file.
The standard "vim" way is "Esc :q!" , and it is unclear which character should be "send" via standard console and which ones after responses from vim.
Either manually (cin) or as a string starting with "Esc".
Cheers
|
|
|
|
|
What kind of verification does vim ?
I am asking such a question because, I believe, while it is not straightforward closing vim , there could be better alternatives to 'verify networking'.
|
|
|
|
|
I wondered about that too: if the point is just to verify that you can access a certain file across a network file path, then trying to open it with fstream::open() should do the job.
Whereas, emulating console input that is supposed to be passed into an external process would be kind of tricky, to say the least...
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I am just looking to verify "hosts" names.
And I realize that using vim is asking for complications, especially when I actually need to use / select "name" for further processing.
vim is bad idea.
|
|
|
|
|
If vim is not in insert or append mode then you can close it by sending ZZ.
|
|
|
|
|
OK, I can do search and replace "cout<<" with "cout<< setw(offset)<< "
to shift the output start column to console at offset.
BUT
anybody has an idea / hack how to PRESET "cout" ?
<pre> int offset = 10;
setw(offset);
cout << setw(offset ) << "Test " << endl;
cout << setw(offset ) << "Test " << endl;
cout << setw(offset ) << "Test " << endl;
offset += 10;
cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
cout << setw(offset ) << "Test " <<" space " << "Test " << endl;
|
|
|
|
|
No, The width feature affects the following item only. In the same way you cannot have a preset in printf.
|
|
|
|
|
Usually when doing that sort of thing its easier to swing to ANSI which is semi portable on Windows and Linux consoles and you can have colours. Still cant set it global pre calls.
An example
printf("\x1B[%d;%df\x1B[31;40mRed line at 10,20\n", 10, 20);
printf("\x1B[37;40m");
In vino veritas
|
|
|
|
|
Leon,
I am getting used to using cout, despite of its irrational behaviour.
In my main project I went overboard with debugging colouring scheme and it sort of works.
I just started the "client" part of the project and reusing a class from my main project where cout colouring and cout lines work just as expected.
In derived project - no coloring, cout lines have extra line feed and I am getting non printable characters to boot.
Just another bug to find.
BTW
I am finding out this setw does not always work....
|
|
|
|
|
Vaclav_ wrote: I am finding out this setw does not always work More likely, you are finding there are bugs in your code.
|
|
|
|
|
|
That is little out of my league, but when I have a break I'll give it a try.
|
|
|
|
|
how to use LoadString in c++
|
|
|
|
|
The Windows API LoadString() expects a buffer, not a C++ string. The easiest way to use it would be something like:
std::wstring GetStringW(HINSTANCE hinst, UINT id)
{
std::vector<wchar_t> buffer(256);
::LoadStringW(hinst, id, buffer.data(), static_cast<int>(buffer.size()));
return &buffer[0];
}
which would convert the buffer into a std::wstring.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
|
Hi
I have a bitmap file of a red bullet Originally I tried to display it using RichEdit Ole Interface I copied the code modified it somewhat from
the "Q220844: HOWTO: Insert a Bitmap Into RTF Document Using RichEdit Control" I was able to display it however it didn't fit quite right
So I decided to go with a native Win32 and display on Static control adjacent to the rich edit
Thing is where the OleCreateFromFile worked the LoadImage API fails GetLastError return a zero as well using File Explorer I can see the red bullet
Thnaks
|
|
|
|
|
You aren't trying to load a jpg, gif or png are you .. loadimage does not support those it is strictly BMP and PCX.
If you need those just use IPic and for that all you need is #include <olectl.h>
In vino veritas
|
|
|
|
|
Are you referring to OLeLoadPicturefile BTW As I mentioned to Richard when I used the code example in the following article Quote: Q220844: HOWTO: Insert a Bitmap Into RTF Document Using RichEdit Control"
Even though I had a 1 in the first param of the SetSel the Red bullet didn't align itself right next the left border of the dialog box
In file explorer the image looked fine.
Opening up the image in Paintbrush I see a white rectangular border around the red bullet maybe that was part of the problem
I loaded the image by doing a google search is if this is the problem is there a way from get this image (I am trying to get something like the visual studio Breakpoint)
Thanks
|
|
|
|