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 45 46 47 48 49 50 51
|
// SPDX-License-Identifier: MIT
/*
* Copyright © 2025 Intel Corporation
*/
#include <assert.h>
#include "utils.h"
static const char * const bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
void n_spaces(const unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
putchar(' ');
}
void print_percentage_bar(double percent, int max_len)
{
int bar_len, i, len = max_len - 1;
const int w = PERCLIENT_ENGINE_WIDTH;
len -= printf("|%5.1f%% ", percent);
/* no space left for bars, do what we can */
if (len < 0)
len = 0;
bar_len = ceil(w * percent * len / 100.0);
if (bar_len > w * len)
bar_len = w * len;
for (i = bar_len; i >= w; i -= w)
printf("%s", bars[w]);
if (i)
printf("%s", bars[i]);
len -= (bar_len + (w - 1)) / w;
n_spaces(len);
putchar('|');
}
int print_engines_footer(int lines, int con_w, int con_h)
{
if (lines++ < con_h)
printf("\n");
return lines;
}
|