10-23-06 12:19 AM
Hello NG,
regarding the code below
// not working
printf("wire %s[%10.10s] %scurrent=%li%s\tdelta=%li\n",
makeColor(green, black, bold), self->name,
makeColor(red, black, bold), self->currentVal,
makeColor(normal, black, none), self->deltaVal);
// working
printf("wire %s[%10.10s]", makeColor(green, black, bold), self->name);
printf("\t%scurrent=%li", makeColor(red, black, bold), self->currentVal);
printf("%s\tdelta=%li\n", makeColor(normal, black, none), self->deltaVal);
it's interesting to note that the later works while the first do not
meaning that the first changes the color to green and gets stuck at it
so that all messages are in green
can someone explain this behaviour?
it doesn't seem that printf need "\n" to "evaluate" the escape sequence
I tried to put it between makeColor calls without success
Regards, Daniel
definition of makeColor function
enum MODE {
none = 0, // all attributes off
bold = 1,
faint = 2,
italic = 3,
underlined = 4,
blink = 5,
rapidBlink = 6,
concealed = 8,
notBold = 22,
notBlink = 25,
notUnderlined = 24,
notInvert = 27,
};
enum COLOR {
black = 0,
red = 1,
green = 2,
yellow = 3,
blue = 4,
magenta = 5,
cyan = 6,
white = 7,
normal = 8,
};
const char * makeColor(enum COLOR foreground, enum COLOR background,
enum MODE mode) {
static char buffer[256]; // we have only one thread
snprintf(buffer, sizeof(buffer), "\033[%i;%i;%im", mode, foreground
+ 30, background + 40);
return buffer;
}
[ Post a follow-up to this message ]
|