How in C to change the color of fonts and background around the text of a console Linux program?
- oneIt all depends on your environment: OS, what (which library) is used for output, etc. Without this data, the question does not make sense. (but in any case I can give a hint: the answer is in the documentation for your library for console output. First look at it, and if there is something incomprehensible there is already here) - PinkTux
- 2I did it once. Here is (all in one color.h file) a set of macros and an example. - avp
|
1 answer
Here it is well described as: https://unix.stackexchange.com/questions/148/colorizing-your-terminal-and-shell-environment
Software analogies implemented in php.
private function getMsgFormat($msg, $color = FALSE , $printDate = TRUE ) { $colorTag = ($color ? (isset($this->fontColor[$color]) ? "\033[" . $this->fontColor[$color] . "m" : "" ) : ""); $lockTag = ($colorTag ? "\033[0m" : ""); $patern = "{color}".($printDate ? "[" . date("ym dh:i:s") . " ] \t " : "")."$msg{lock} \n "; return array( str_replace(array("{color}", "{lock}"), array($colorTag, $lockTag), $patern), str_replace(array("{color}", "{lock}"), "", $patern), ); } private function cmdColor() { $this->fontColor['black'] = '0;30'; $this->fontColor['blue'] = '0;34'; $this->fontColor['green'] = '0;32'; $this->fontColor['red'] = '0;31'; $this->fontColor['yellow'] = '1;33'; $this->fontColor['white'] = '1;37'; $this->backColor['black'] = '40'; $this->backColor['red'] = '41'; $this->backColor['green'] = '42'; $this->backColor['yellow'] = '43'; $this->backColor['blue'] = '44'; } - oneWhat does this have to do with
C? - PinkTux - If it is necessary to color the console output, then the principle of constructing the terminal output itself is important, and in this case it is the same everywhere. - Redr01d
|