PhoenixMock  1.8.7
Tools to split/merge/print mock used in Phoenix
string_color.cpp File Reference
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "string_function.h"
#include "string_color.h"
+ Include dependency graph for string_color.cpp:

Go to the source code of this file.

Functions

void clearTerminal ()
 fonction qui permet d'éffacer le terminal More...
 
std::string colorString (const std::string &str, PTerminalStyle color)
 fonction qui permet de colorier du texte dans une string More...
 
short unsigned int getNbColTerminal ()
 fonction qui renvoie le nombre de colonnes du terminal More...
 
short unsigned int getNbRowTerminal ()
 fonction qui renvoie le nombre de lignes du terminal More...
 
void printAll (const std::string &strLeft, char ch, const std::string &strRight)
 fonction qui écrit un texte dans la console en l'alignant à droite (ne prend pas en compte la couleur du texte) More...
 
void printAllCerr (const std::string &strLeft, char ch, const std::string &strRight)
 fonction qui écrit un texte dans la console d'erreur en l'alignant à droite (ne prend pas en compte la couleur du texte) More...
 
void printAllCol (const std::string &strLeft, char ch, const std::string &strRight)
 fonction qui écrit un texte dans la console en l'alignant à droite (prend en compte la couleur du texte) More...
 
void printAllColCerr (const std::string &strLeft, char ch, const std::string &strRight)
 fonction qui écrit un texte dans la console d'erreur en l'alignant à droite (prend en compte la couleur du texte) More...
 
void printColor (const std::string &str, PTerminalStyle color)
 fonction qui affiche un texte coloré dans le terminal More...
 
void printColorCerr (const std::string &str, PTerminalStyle color)
 fonction qui affiche un texte coloré dans le terminal More...
 
void printDelire (const std::string &str)
 fonction qui utilise toutes les couleur du terminal pour afficher un message More...
 
std::string termBBlack ()
 affiche le fond du terminal en noir More...
 
std::string termBBlue ()
 affiche le fond du terminal en bleu More...
 
std::string termBCyan ()
 affiche le fond du terminal en cyan More...
 
std::string termBGreen ()
 affiche le fond du terminal en vert More...
 
std::string termBlack ()
 affiche le terminal noir More...
 
std::string termBlink ()
 affiche le terminal clignotant More...
 
std::string termBlue ()
 affiche le terminal blue More...
 
std::string termBPurple ()
 affiche le fond du terminal en violet More...
 
std::string termBRed ()
 affiche le fond du terminal en rouge More...
 
std::string termBright ()
 affiche le terminal brillant More...
 
std::string termBWhite ()
 affiche le fond du terminal en blanc More...
 
std::string termBYellow ()
 affiche le fond du terminal en jaune More...
 
std::string termCyan ()
 affiche le terminal cyan More...
 
std::string termDefault ()
 affiche le terminal par défaut More...
 
std::string termGreen ()
 affiche le terminal vert More...
 
std::string termNegative ()
 affiche le terminal négatif More...
 
std::string termPositive ()
 affiche le terminal positif More...
 
std::string termPurple ()
 affiche le terminal violet More...
 
std::string termRed ()
 affiche le terminal rouge More...
 
std::string termUnderlined ()
 affiche le terminal souligné More...
 
std::string termWhite ()
 affiche le terminal blanc More...
 
std::string termYellow ()
 affiche le terminal jaune More...
 
void textColor (const char *color)
 focntion qui permet de changer la couleur du texte dan le terminal More...
 
void textColor (PTerminalStyle color)
 focntion qui permet de changer la couleur du texte dan le terminal More...
 
void textColorCerr (const char *color)
 focntion qui permet de changer la couleur du texte dan le terminal (sortie d'erreur) More...
 
void textColorCerr (PTerminalStyle color)
 focntion qui permet de changer la couleur du texte dan le terminal (sortie d'erreur) More...
 

Function Documentation

◆ clearTerminal()

void clearTerminal ( )

fonction qui permet d'éffacer le terminal

Definition at line 128 of file string_color.cpp.

128  {
129  printf("\033[H\033[2J");
130 }

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ colorString()

std::string colorString ( const std::string &  str,
PTerminalStyle  color 
)

fonction qui permet de colorier du texte dans une string

Parameters
str: méssage à afficher dans le terminal
color: couleur des caractères dans le terminal
Returns
string avec la couleur

Definition at line 181 of file string_color.cpp.

181  {
182  char buffer[100];
183  sprintf(buffer, "\033[%dm", color);
184  return string(buffer) + str + "\033[0m";
185 }

References createReleaseCurl::str.

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ getNbColTerminal()

short unsigned int getNbColTerminal ( )

fonction qui renvoie le nombre de colonnes du terminal

Returns
nombre de colonnes du terminal

Definition at line 206 of file string_color.cpp.

206  {
207  struct winsize w;
208  ioctl(0, TIOCGWINSZ, &w);
209  return w.ws_col;
210 }

Referenced by ProgressTime::initialisationProgressTime(), printAll(), printAllCerr(), printAllCol(), printAllColCerr(), and testStringColor().

+ Here is the caller graph for this function:

◆ getNbRowTerminal()

short unsigned int getNbRowTerminal ( )

fonction qui renvoie le nombre de lignes du terminal

Returns
nombre de lignes du terminal

Definition at line 215 of file string_color.cpp.

215  {
216  struct winsize w;
217  ioctl(0, TIOCGWINSZ, &w);
218  return w.ws_row;
219 }

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ printAll()

void printAll ( const std::string &  strLeft,
char  ch,
const std::string &  strRight 
)

fonction qui écrit un texte dans la console en l'alignant à droite (ne prend pas en compte la couleur du texte)

Parameters
strLeft: texte à écrire aligné à gauche
ch: caractère à afficher entre les deux
strRight: texte à écrire aligné à droite

Definition at line 247 of file string_color.cpp.

247  {
248  long unsigned int longueurConsole((long unsigned int)getNbColTerminal());
249  long unsigned int sizeLeft(strLeft.size()), sizeRight(strRight.size());
250  long unsigned int sizeStr(sizeLeft + sizeRight);
251  if(sizeStr > longueurConsole){
252  cout << strLeft << strRight << endl;
253  }else{
254  cout << strLeft;
255  long unsigned int nbChar(longueurConsole - sizeStr);
256  for(long unsigned int i(0); i < nbChar; ++i){
257  cout << ch;
258  }
259  cout << strRight << endl;
260  }
261 }

References getNbColTerminal().

Referenced by testStringColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ printAllCerr()

void printAllCerr ( const std::string &  strLeft,
char  ch,
const std::string &  strRight 
)

fonction qui écrit un texte dans la console d'erreur en l'alignant à droite (ne prend pas en compte la couleur du texte)

Parameters
strLeft: texte à écrire aligné à gauche
ch: caractère à afficher entre les deux
strRight: texte à écrire aligné à droite

Definition at line 268 of file string_color.cpp.

268  {
269  long unsigned int longueurConsole((long unsigned int)getNbColTerminal());
270  long unsigned int sizeLeft(strLeft.size()), sizeRight(strRight.size());
271  long unsigned int sizeStr(sizeLeft + sizeRight);
272  if(sizeStr > longueurConsole){
273  cerr << strLeft << strRight;
274  }else{
275  cerr << strLeft;
276  long unsigned int nbChar(longueurConsole - sizeStr);
277  for(long unsigned int i(0); i < nbChar; ++i){
278  cerr << ch;
279  }
280  cerr << strRight;
281  }
282 }

References getNbColTerminal().

Referenced by testStringColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ printAllCol()

void printAllCol ( const std::string &  strLeft,
char  ch,
const std::string &  strRight 
)

fonction qui écrit un texte dans la console en l'alignant à droite (prend en compte la couleur du texte)

Parameters
strLeft: texte à écrire aligné à gauche
ch: caractère à afficher entre les deux
strRight: texte à écrire aligné à droite

Definition at line 226 of file string_color.cpp.

226  {
227  long unsigned int longueurConsole((long unsigned int)getNbColTerminal());
228  long unsigned int sizeLeft(strLeft.size()), sizeRight(strRight.size());
229  long unsigned int sizeStr(sizeLeft - ((long unsigned int)countNbChar(strLeft ,'\033')*9)/2 + sizeRight - ((long unsigned int)countNbChar(strRight ,'\033')*9)/2);
230  if(sizeStr > longueurConsole){
231  cout << strLeft << strRight << endl;
232  }else{
233  cout << strLeft;
234  long unsigned int nbChar(longueurConsole - sizeStr);
235  for(long unsigned int i(0); i < nbChar; ++i){
236  cout << ch;
237  }
238  cout << strRight << endl;
239  }
240 }

References countNbChar(), and getNbColTerminal().

Referenced by testStringColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ printAllColCerr()

void printAllColCerr ( const std::string &  strLeft,
char  ch,
const std::string &  strRight 
)

fonction qui écrit un texte dans la console d'erreur en l'alignant à droite (prend en compte la couleur du texte)

Parameters
strLeft: texte à écrire aligné à gauche
ch: caractère à afficher entre les deux
strRight: texte à écrire aligné à droite

Definition at line 289 of file string_color.cpp.

289  {
290  long unsigned int longueurConsole((long unsigned int)getNbColTerminal());
291  long unsigned int sizeLeft(strLeft.size()), sizeRight(strRight.size());
292  long unsigned int sizeStr(sizeLeft - ((long unsigned int)countNbChar(strLeft ,'\033')*9)/2 + sizeRight - ((long unsigned int)countNbChar(strRight ,'\033')*9)/2);
293  if(sizeStr > longueurConsole){
294  cerr << strLeft << strRight;
295  }else{
296  cerr << strLeft;
297  long unsigned int nbChar(longueurConsole - sizeStr);
298  for(long unsigned int i(0); i < nbChar; ++i){
299  cerr << ch;
300  }
301  cerr << strRight;
302  }
303 }

References countNbChar(), and getNbColTerminal().

Referenced by testStringColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ printColor()

void printColor ( const std::string &  str,
PTerminalStyle  color 
)

fonction qui affiche un texte coloré dans le terminal

Parameters
str: méssage à afficher dans le terminal
color: couleur des caractères dans le terminal

Definition at line 191 of file string_color.cpp.

191  {
192  printf("\033[%dm%s\033[0m",color, str.c_str());
193 }

References createReleaseCurl::str.

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ printColorCerr()

void printColorCerr ( const std::string &  str,
PTerminalStyle  color 
)

fonction qui affiche un texte coloré dans le terminal

Parameters
str: méssage à afficher dans le terminal
color: couleur des caractères dans le terminal

Definition at line 199 of file string_color.cpp.

199  {
200  fprintf(stderr, "\033[%dm%s\033[0m",color, str.c_str());
201 }

References createReleaseCurl::str.

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ printDelire()

void printDelire ( const std::string &  str)

fonction qui utilise toutes les couleur du terminal pour afficher un message

Parameters
str: méssage à afficher dans le terminal

Definition at line 163 of file string_color.cpp.

163  {
164  int couleur = 0;
165  char buffer[255];
166  for(string::const_iterator it = str.begin(); it != str.end(); it++){
167  couleur++;
168  if(couleur > 7){couleur = 1;}
169  sprintf(buffer, "3%d", couleur);
170  textColor(buffer);
171  printf("%c", *it);
172  }
173  textColor("0");
174 }

References createReleaseCurl::str, and textColor().

Referenced by testStringColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ termBBlack()

std::string termBBlack ( )

affiche le fond du terminal en noir

Returns
string de modification du terminal

Definition at line 90 of file string_color.cpp.

90 {return "\033[40m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBBlue()

std::string termBBlue ( )

affiche le fond du terminal en bleu

Returns
string de modification du terminal

Definition at line 110 of file string_color.cpp.

110 {return "\033[44m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBCyan()

std::string termBCyan ( )

affiche le fond du terminal en cyan

Returns
string de modification du terminal

Definition at line 120 of file string_color.cpp.

120 {return "\033[46m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBGreen()

std::string termBGreen ( )

affiche le fond du terminal en vert

Returns
string de modification du terminal

Definition at line 100 of file string_color.cpp.

100 {return "\033[42m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBlack()

std::string termBlack ( )

affiche le terminal noir

Returns
string de modification du terminal

Definition at line 50 of file string_color.cpp.

50 {return "\033[30m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBlink()

std::string termBlink ( )

affiche le terminal clignotant

Returns
string de modification du terminal

Definition at line 35 of file string_color.cpp.

35 {return "\033[5m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBlue()

std::string termBlue ( )

affiche le terminal blue

Returns
string de modification du terminal

Definition at line 70 of file string_color.cpp.

70 {return "\033[34m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBPurple()

std::string termBPurple ( )

affiche le fond du terminal en violet

Returns
string de modification du terminal

Definition at line 115 of file string_color.cpp.

115 {return "\033[45m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBRed()

std::string termBRed ( )

affiche le fond du terminal en rouge

Returns
string de modification du terminal

Definition at line 95 of file string_color.cpp.

95 {return "\033[41m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBright()

std::string termBright ( )

affiche le terminal brillant

Returns
string de modification du terminal

Definition at line 25 of file string_color.cpp.

25 {return "\033[1m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBWhite()

std::string termBWhite ( )

affiche le fond du terminal en blanc

Returns
string de modification du terminal

Definition at line 125 of file string_color.cpp.

125 {return "\033[47m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termBYellow()

std::string termBYellow ( )

affiche le fond du terminal en jaune

Returns
string de modification du terminal

Definition at line 105 of file string_color.cpp.

105 {return "\033[43m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termCyan()

std::string termCyan ( )

affiche le terminal cyan

Returns
string de modification du terminal

Definition at line 80 of file string_color.cpp.

80 {return "\033[36m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termDefault()

std::string termDefault ( )

affiche le terminal par défaut

Returns
string de modification du terminal

Definition at line 20 of file string_color.cpp.

20 {return "\033[0m";}

Referenced by Option::checkArgument(), and testStringColor().

+ Here is the caller graph for this function:

◆ termGreen()

std::string termGreen ( )

affiche le terminal vert

Returns
string de modification du terminal

Definition at line 60 of file string_color.cpp.

60 {return "\033[32m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termNegative()

std::string termNegative ( )

affiche le terminal négatif

Returns
string de modification du terminal

Definition at line 40 of file string_color.cpp.

40 {return "\033[7m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termPositive()

std::string termPositive ( )

affiche le terminal positif

Returns
string de modification du terminal

Definition at line 45 of file string_color.cpp.

45 {return "\033[27m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termPurple()

std::string termPurple ( )

affiche le terminal violet

Returns
string de modification du terminal

Definition at line 75 of file string_color.cpp.

75 {return "\033[35m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termRed()

std::string termRed ( )

affiche le terminal rouge

Returns
string de modification du terminal

Definition at line 55 of file string_color.cpp.

55 {return "\033[31m";}

Referenced by Option::checkArgument(), and testStringColor().

+ Here is the caller graph for this function:

◆ termUnderlined()

std::string termUnderlined ( )

affiche le terminal souligné

Returns
string de modification du terminal

Definition at line 30 of file string_color.cpp.

30 {return "\033[4m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termWhite()

std::string termWhite ( )

affiche le terminal blanc

Returns
string de modification du terminal

Definition at line 85 of file string_color.cpp.

85 {return "\033[37m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ termYellow()

std::string termYellow ( )

affiche le terminal jaune

Returns
string de modification du terminal

Definition at line 65 of file string_color.cpp.

65 {return "\033[33m";}

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ textColor() [1/2]

void textColor ( const char *  color)

focntion qui permet de changer la couleur du texte dan le terminal

Parameters
color: couleur des caractères dans le terminal

Definition at line 135 of file string_color.cpp.

135  {
136  printf("\033[%sm",color);
137 }

Referenced by printDelire(), and testStringColor().

+ Here is the caller graph for this function:

◆ textColor() [2/2]

void textColor ( PTerminalStyle  color)

focntion qui permet de changer la couleur du texte dan le terminal

Parameters
color: couleur des caractères dans le terminal

Definition at line 149 of file string_color.cpp.

149  {
150  printf("\033[%dm",color);
151 }

◆ textColorCerr() [1/2]

void textColorCerr ( const char *  color)

focntion qui permet de changer la couleur du texte dan le terminal (sortie d'erreur)

Parameters
color: couleur des caractères dans le terminal (sortie d'erreur)

Definition at line 142 of file string_color.cpp.

142  {
143  fprintf(stderr, "\033[%sm", color);
144 }

Referenced by testStringColor().

+ Here is the caller graph for this function:

◆ textColorCerr() [2/2]

void textColorCerr ( PTerminalStyle  color)

focntion qui permet de changer la couleur du texte dan le terminal (sortie d'erreur)

Parameters
color: couleur des caractères dans le terminal (sortie d'erreur)

Definition at line 156 of file string_color.cpp.

156  {
157  fprintf(stderr, "\033[%dm", color);
158 }
getNbColTerminal
short unsigned int getNbColTerminal()
fonction qui renvoie le nombre de colonnes du terminal
Definition: string_color.cpp:206
textColor
void textColor(const char *color)
focntion qui permet de changer la couleur du texte dan le terminal
Definition: string_color.cpp:135
createReleaseCurl.str
str
Definition: createReleaseCurl.py:128
countNbChar
size_t countNbChar(const std::string &str, char ch)
Count number of chararacters ch in string.
Definition: string_function.cpp:145