-
Notifications
You must be signed in to change notification settings - Fork 21
/
progress.c
44 lines (39 loc) · 1.11 KB
/
progress.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <string.h>
#include "progress.h"
/** \brief Print progress bar with prefix
*
* \param [in] iteration Current iteration
* \param [in] total Total number of iterations
* \param [in] prefix Prefix text
* \param [in] fill Char to use for filling the bar
* \return Noting
*
*/
void PROGRESS_Print(uint16_t iteration, uint16_t total, char *prefix, char fill)
{
uint8_t filledLength;
float percent;
char bar[PROGRESS_BAR_LENGTH + 1];
char bar2[PROGRESS_BAR_LENGTH + 1];
memset(bar, fill, PROGRESS_BAR_LENGTH);
bar[PROGRESS_BAR_LENGTH] = 0;
memset(bar2, ' ', PROGRESS_BAR_LENGTH);
bar2[PROGRESS_BAR_LENGTH] = 0;
percent = (float)iteration / total * 100;
filledLength = (uint8_t)(PROGRESS_BAR_LENGTH * iteration / total);
printf("\r%s [%.*s%.*s] %.1f%%", prefix, filledLength, bar, PROGRESS_BAR_LENGTH - filledLength, bar2, percent);
fflush(stdout);
// Print New Line on Complete
if (iteration >= total)
printf("\n");
}
/** \brief Do break in the output
*
* \return Nothing
*
*/
void PROGRESS_Break(void)
{
printf("\n");
}