importctl: draw a pretty progress bar while downloading
Everybody loves pretty terminal progress bar.
This commit is contained in:
@@ -380,6 +380,10 @@ executables += [
|
||||
'sources' : files('test-process-util.c'),
|
||||
'dependencies' : threads,
|
||||
},
|
||||
test_template + {
|
||||
'sources' : files('test-progress-bar.c'),
|
||||
'type' : 'manual',
|
||||
},
|
||||
test_template + {
|
||||
'sources' : files('test-qrcode-util.c'),
|
||||
'dependencies' : libdl,
|
||||
|
||||
@@ -92,6 +92,8 @@ TEST(dump_special_glyphs) {
|
||||
dump_glyph(SPECIAL_GLYPH_TREE_SPACE);
|
||||
dump_glyph(SPECIAL_GLYPH_TREE_TOP);
|
||||
dump_glyph(SPECIAL_GLYPH_VERTICAL_DOTTED);
|
||||
dump_glyph(SPECIAL_GLYPH_HORIZONTAL_DOTTED);
|
||||
dump_glyph(SPECIAL_GLYPH_HORIZONTAL_FAT);
|
||||
dump_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET);
|
||||
dump_glyph(SPECIAL_GLYPH_BLACK_CIRCLE);
|
||||
dump_glyph(SPECIAL_GLYPH_WHITE_CIRCLE);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "pretty-print.h"
|
||||
#include "random-util.h"
|
||||
#include "tests.h"
|
||||
|
||||
#define PROGRESS_PREFIX "test: "
|
||||
|
||||
TEST(progress_bar) {
|
||||
|
||||
draw_progress_bar(PROGRESS_PREFIX, 0);
|
||||
|
||||
bool paused = false;
|
||||
|
||||
for (double d = 0; d <= 100; d += 0.5) {
|
||||
usleep_safe(random_u64_range(20 * USEC_PER_MSEC));
|
||||
draw_progress_bar(PROGRESS_PREFIX, d);
|
||||
|
||||
if (!paused && d >= 50) {
|
||||
clear_progress_bar(PROGRESS_PREFIX);
|
||||
fputs("Sleeping for 1s...", stdout);
|
||||
fflush(stdout);
|
||||
usleep_safe(USEC_PER_SEC);
|
||||
paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
draw_progress_bar(PROGRESS_PREFIX, 100);
|
||||
usleep_safe(300 * MSEC_PER_SEC);
|
||||
clear_progress_bar(PROGRESS_PREFIX);
|
||||
fputs("Done.\n", stdout);
|
||||
}
|
||||
|
||||
DEFINE_TEST_MAIN(LOG_INFO);
|
||||
Reference in New Issue
Block a user