Add basic support for mini2440 board to barebox.
[barebox-mini2440.git] / lib / show_progress.c
blob333f49868a3cac55e095ee04de9eceb27c3c8c9b
1 /*
2 * show_progress.c - simple progress bar functions
4 * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this
7 * project.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <common.h>
24 #include <progress.h>
26 #define HASHES_PER_LINE 65
28 static int printed;
29 static int progress_max;
30 static int spin;
32 void show_progress(int now)
34 char spinchr[] = "\\|/-";
36 if (now < 0) {
37 printf("%c\b", spinchr[spin++ % (sizeof(spinchr) - 1)]);
38 return;
41 if (progress_max)
42 now = now * HASHES_PER_LINE / progress_max;
44 while (printed < now) {
45 if (!(printed % HASHES_PER_LINE) && printed)
46 printf("\n\t");
47 printf("#");
48 printed++;
52 void init_progression_bar(int max)
54 printed = 0;
55 progress_max = max;
56 spin = 0;
57 if (progress_max)
58 printf("\t[%65s]\r\t[", "");
59 else
60 printf("\t");