2010-06-14 20:31:04 +00:00
|
|
|
/*
|
|
|
|
* show_progress.c - simple progress bar functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2013-09-27 07:33:21 +00:00
|
|
|
#include <fs.h>
|
2010-06-14 20:31:04 +00:00
|
|
|
#include <progress.h>
|
2012-01-24 10:51:03 +00:00
|
|
|
#include <asm-generic/div64.h>
|
2010-06-14 20:31:04 +00:00
|
|
|
|
|
|
|
#define HASHES_PER_LINE 65
|
|
|
|
|
|
|
|
static int printed;
|
|
|
|
static int progress_max;
|
|
|
|
static int spin;
|
|
|
|
|
|
|
|
void show_progress(int now)
|
|
|
|
{
|
|
|
|
char spinchr[] = "\\|/-";
|
|
|
|
|
|
|
|
if (now < 0) {
|
|
|
|
printf("%c\b", spinchr[spin++ % (sizeof(spinchr) - 1)]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-27 07:33:21 +00:00
|
|
|
if (progress_max && progress_max != FILESIZE_MAX) {
|
2012-01-24 10:51:03 +00:00
|
|
|
uint64_t tmp = (int64_t)now * HASHES_PER_LINE;
|
|
|
|
do_div(tmp, progress_max);
|
|
|
|
now = tmp;
|
|
|
|
}
|
2010-06-14 20:31:04 +00:00
|
|
|
|
|
|
|
while (printed < now) {
|
|
|
|
if (!(printed % HASHES_PER_LINE) && printed)
|
|
|
|
printf("\n\t");
|
|
|
|
printf("#");
|
|
|
|
printed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_progression_bar(int max)
|
|
|
|
{
|
|
|
|
printed = 0;
|
|
|
|
progress_max = max;
|
|
|
|
spin = 0;
|
2013-09-27 07:33:21 +00:00
|
|
|
if (progress_max && progress_max != FILESIZE_MAX)
|
2016-04-11 13:44:13 +00:00
|
|
|
printf("\t[%*s]\r\t[", HASHES_PER_LINE, "");
|
2010-06-14 20:31:04 +00:00
|
|
|
else
|
|
|
|
printf("\t");
|
|
|
|
}
|