today i need to print colorful text in console, but the color should be "unusual". I've found the only way to colorize text with windowh.h
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colorNumber)
Main problem is the limited choice of colorNumber, there are only 16 colors, but it is not enough. What if i want to make text color #33F5C8? What if i want to make it transparent? How can i do it?
(nonstandard cpp tools allowed)
With ANSI you can use the following code to set a RGB based color:
\033[38;2;⟨r⟩;⟨g⟩;⟨b⟩m
To reset color after change:
\033[0m
Pay attention that the visual's console might not support it, although the CMD probably does. To check the colors, compile your program and run it using the CMD.
Related
I'm using gdb 10.2 in a gnome-terminal (on Ubuntu 20.04 running in WSL2), where gnome-terminal is configured to follow the system theme.
In tui mode, if the current line is indicated by a black bar. Function calls are formatted with black foreground text, rendering them unreadable:
Already tried
set style source off: The current line is now readable, but source color coding is now (obviously) disabled
set style function foreground white: No effect
Configure gnome terminal to not follow the system theme: The terminal switches to "dark mode": The background now becomes black, the bar turns white. The function names are readable, but the legibility of many of the differently colored things is reduced.
Possible duplicate question
At this point, disabling source highlighting is workable, but suboptimal. Tips are most welcome!
I am attempting to put the final touches on a maze program I have been writing. I have used Unicode to delimit the walls and paths however because of the (horizontal) line spacing I can't quite get it to look compact enough. I have attached two screenshots. I'm just escaping the newline "\n" in order to print each row. Can the distance between lines be adjusted or am I stuck with this "gappy" representation?
My output:
What I am trying to closely represent:
Assuming you aren't printing double newlines, this is outside the scope of standard C++, it does not provide facilities for controlling terminal in a standard way.
Solutions:
You could provide a launcher script, which opens a new terminal window with specific font and runs your app in it.
You could use some platform specific method to change background color (ANSI codes work in unixy terminals, or use Win32 API for Windows terminal, ncurses library on Unix-like environments) and print just spaces in different colors.
Use a GUI library/framework to get complete control on what is drawn (I'd use Qt for C++ GUI app).
TBH if you want pixel-accurate rendering use a proper rendering API, such as OpenGL.
From a text rendering point of view you don't say what you are rendering to. Assuming something like a terminal console or shell window then the layout beyond characters and newlines is nothing to do with your program; the visual representation is entirely determined by the shell you are rendering to.
Firstly, check that you are genuinely printing a line per maze scan line, and not interleaving with spurious newlines. Assuming that is ruled out, the problem is that the unicode glyph is not a full block. So you must somehow set the font or choose another glyph which is a full block.
Usually console windows are 80 characters wide by 22 or 24 characters high, and characters are 8 pixels wide by 19 pixels high. So it's very far from a square grid, and you might want to bias the maze to reflect that and provide a better visual appearance (eg make 2 pixel-wide vertical corridors much more common than 2-pievel wide horizontal corridors).
Do check the binary image library fonts, you might find them useful.
https://github.com/MalcolmMcLean/binaryimagelibrary
I am making a console program that deals with the simple command line (console) in C++. It works fine, the program has no errors at all. My problem that came for design was: how can I instantiate in C++ changing the font size and color that would be displayed in the program? Suppose like this:
"Hello. This is the List Commands. Please Choose Wisely."
How can I make the font colored green while the others white? Set up the size?
Thanks for answering.
If you're on Linux, I'd recommend ncurses, hands-down:
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
I'm making a random number generator, the program will create several random numbers and then choose from those random numbers and then displays that number in the window.
I was wondering if there was a way to make that specific piece of text bigger?
I don't want to change the size of all of the text in the window as I have writing in the window that i don't want to change the size of
Thanks for any help you can give
No, but you can make it bold, change the font color, or the background color for the specific text. If all you want is to make that specific piece of text stand out, I'd go with colorizing it.
As for how to do that... It's platform dependent. What platform are you on? Windows? Linux? What shell?
Take a look at the Windows Console API. That should have what you need.
Console text doesn't allow for the rich formatting you are referring to. You would have to move to a graphical output to render the size differences.
Generally, programs can't control the size of the text in the terminal. You may be able to change the color of a specific part of the text, though. Search for terminal escape sequences for information on how to do that on various terminals. Some terminals also handle bold, italics, and underlining.
No, but instead you can change colors of text and text's background. Will this be a good solution for your problem? There are a lot of specific examples available in the internet.
A possible console mode solution could involve FIGlet. You can tweak the output to write in many different fonts.
The output is larger, but no guarantee that it's suitable for your application.
open your console app, go to system menu of console window (left top corner, right click), font tab, choose what you wish. next time you open this (!) console app the font will be as you selected, other console windows are not affected
Right Click the top bar of the window
Click Properties
Click Font and select your font size
This isn't through the code but it will help for your pc.
I'm new to GUI programming in C and Linux, and I'm having a hard time with it. It seems like a fairly simple/straightforward thing, but I can't find any answers googling. I want to add a background color to a widget. XmNbackground seems to be what I want to use, but I don't understand what I set it to, like a simple color blue, how do I get "blue" to set XmNbackground color to that?
See here for an answer in the function Pixel convert_color_name_to_pixel, and also here.
Hope this helps.
You can use a resource file which includes "*background: blue" or use XSetArgVal to do the same thing in the code.
If you have the widget in a function, you can set the widget background color resource like this, assuming the widget name is w:
XtVaSetValues(w, XmNbackground, XmRstring, "#c4c4c4", 8, NULL);
Where #c4c4c3 is the hex color code for red (first two characters), green (middle two characters) and blue (last two characters).
You can also use any of the textual color names from file rgb.txt - where that file is located seems to be something of a moving target, but on the computer I'm using at the moment it's in /usr/share/X11