diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2010-06-14 22:31:04 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2010-06-28 10:43:55 +0200 |
commit | 257da5cac07854c89861de5925475b339e8ff71b (patch) | |
tree | 8da1f08d39f18465273354a00302104b7d32ed1b /lib | |
parent | 3039467bbd3eb1fa8c9ea2c3b63451f0082143e9 (diff) | |
download | barebox-257da5cac07854c89861de5925475b339e8ff71b.tar.gz barebox-257da5cac07854c89861de5925475b339e8ff71b.tar.xz |
add progression bar function
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/show_progress.c | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/lib/Makefile b/lib/Makefile index 4a33aaa3c0..5afbf132aa 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -30,5 +30,6 @@ obj-y += notifier.o obj-y += copy_file.o obj-y += random.o obj-y += lzo/ +obj-y += show_progress.o obj-$(CONFIG_LZO_DECOMPRESS) += decompress_unlzo.o obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE) += process_escape_sequence.o diff --git a/lib/show_progress.c b/lib/show_progress.c new file mode 100644 index 0000000000..333f49868a --- /dev/null +++ b/lib/show_progress.c @@ -0,0 +1,62 @@ +/* + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <common.h> +#include <progress.h> + +#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; + } + + if (progress_max) + now = now * HASHES_PER_LINE / progress_max; + + 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; + if (progress_max) + printf("\t[%65s]\r\t[", ""); + else + printf("\t"); +} + |