Cores no printf

UNDEATH

Power Member
Oi pessoal! Tou com uma duvida tou a fazer um trabalho em c no linux e gostava de saber como se faz para mudar as cores das letras na chamada de um printf? Obrigado
 
não é possivel com a biblioteca standard de C.
isso só usando outra biblioteca. a ncurses que é standard em *nix por exemplo.
"man curses" ou "man ncurses"
 
Cores sem ncurses.

Código:
#include <stdio.h>

#define RESET		0
#define BRIGHT 		1
#define DIM		2
#define UNDERLINE 	3
#define BLINK		4
#define REVERSE		7
#define HIDDEN		8

#define BLACK 		0
#define RED		1
#define GREEN		2
#define YELLOW		3
#define BLUE		4
#define MAGENTA		5
#define CYAN		6
#define	WHITE		7

void textcolor(int attr, int fg, int bg);
int main()
{	textcolor(BRIGHT, RED, BLACK);	
	printf("Cor...\n");
	textcolor(RESET, WHITE, BLACK);	
	return 0;
}

void textcolor(int attr, int fg, int bg)
{	char command[13];

	sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
	printf("%s", command);
}


o formato é
Código:
<ESC>[{attr};{fg};{bg}m

experimenta na shell escrever
Código:
echo "^[[0;31;40mA Cores"



/ing
 
Back
Topo