[Gambas-user] Standart output
Fabien Bodard
gambas.fr at ...626...
Sat Nov 12 12:08:09 CET 2011
this is the code that produce the progressbar
/* refactored from cb_trans_progress */
static void fill_progress(const int bar_percent, const int disp_percent,
const int proglen)
{
/* 8 = 1 space + 1 [ + 1 ] + 5 for percent */
const int hashlen = proglen - 8;
const int hash = bar_percent * hashlen / 100;
static int lasthash = 0, mouth = 0;
int i;
if(bar_percent == 0) {
lasthash = 0;
mouth = 0;
}
if(hashlen > 0) {
printf(" [");
for(i = hashlen; i > 0; --i) {
/* if special progress bar enabled */
if(config->chomp) {
if(i > hashlen - hash) {
printf("-");
} else if(i == hashlen - hash) {
if(lasthash == hash) {
if(mouth) {
printf("\033[1;33mC\033[m");
} else {
printf("\033[1;33mc\033[m");
}
} else {
lasthash = hash;
mouth = mouth == 1 ? 0 : 1;
if(mouth) {
printf("\033[1;33mC\033[m");
} else {
printf("\033[1;33mc\033[m");
}
}
} else if(i%3 == 0) {
printf("\033[0;37mo\033[m");
} else {
printf("\033[0;37m \033[m");
}
} /* else regular progress bar */
else if(i > hashlen - hash) {
printf("#");
} else {
printf("-");
}
}
printf("]");
}
/* print display percent after progress bar */
/* 5 = 1 space + 3 digits + 1 % */
if(proglen >= 5) {
printf(" %3d%%", disp_percent);
}
if(bar_percent == 100) {
printf("\n");
} else {
printf("\r");
}
fflush(stdout);
}
More information about the User
mailing list