I have a project in which I have to change the background of the terminal
I saw many examples but for windows and I hardly see them in GNU/linux it is in the system that I am at this moment.
Note: I always mention the function system()
; but according to me that only works for windows and its terminal.
Well your question may have many ways to do it, here are some (ideas/approaches):
1
based on what you say
system()
You would have to know which terminal your OS has, for example if you have LXTerminal, this allows you to change them as far as I know from its window:
Now, this is just assumptions because in principle it seems somewhat cumbersome to me always counting on the terminal/OS being designed to do something similar (I have great doubts as to whether it was thought to do something similar).
could use something like this:
Notice what is passed to
cmd
the command "fiticio"but if there is a command for this, what the above would do would be to open a new console ect. It would be necessary to investigate if the parameter could be passed to the active terminal through system() in a similar way to the one mentioned.
My conclusion on this approach at a glance seems to me that there are too many variables for it not to work.
This question deals with a topic that may help you.
two
Another approach could be, that through its program, it modifies the configuration files or replaces the ones used by the terminal for the use scheme ect.
.Xdefaults
.bashrc
It will depend on the terminal, this approach seems simpler to me, and even more so if you know what colors you want, "you only have" to modify and load them, I don't think that with the use of system() it will be very complicated, even so you would have to investigate, because maybe There is a much easier way.
info: https://bbs.archlinux.org/viewtopic.php?id=51818&p=9
3
I'll leave this one for last, because I don't know if based on your question this approach could be used, (although I think this is the one I would use if I wanted a cli to have a custom color etc.).
I don't know if you know Ncurses , with this library you can change the aspect in which your program is displayed, maybe it is what you are looking for.
Although Ncurses goes much further than changing colors, if I want to customize the program I would use this library.
info: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/color.html
P.S:
system() works for GNU/Linux but it is very likely that the commands not passed to it are not the same as the ones you saw for windows, also keep in mind that it is a different OS, also keep in mind that terminals in GNU/Linux there are many with which possibly the commands are also different "in the case of being able to do it as you saw it in windows".
Trying out of curiosity, perhaps this is the simplest way for what you are looking for:
Using the ANSI approach:
https://es.wikipedia.org/wiki/C%C3%B3digo_escape_ANSI
Maybe you don't need this but I'll leave it to you, it's to change the color of the text letters, it works in UNIX-like environments:
With the setterm command you can change the background color of the terminal
This script works from a virtual terminal, to see how it works, access: ctrl + alt + f1 (for example) , login and run the following example script.
It's easier, if you use the escape sequence \033 in any printf or in any cout, for example:
in C:
in C++:
On this page there is more information about the list of font colors, background, applying bold, etc., to the linux terminal at runtime, similar to the system(color ) of the C/C++ language in Windows:
https://robologs.net/2016/03/31/how-to-color-the-output-of-the-terminal-in-linux/
I tested it using codeblocks on ubuntu 14.04 and it works using codeblocks.
Here a nice example:
Although the change is by lines or lines, creativity can be used to cover the entire terminal ;) .
I hope it has been helpful.
Greetings to all.