From cad6bf99af345ddc4708e667526655d49fffbadb Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Tue, 15 Sep 2020 13:01:46 -0400 Subject: [PATCH] Add padding to remove previous line's leftovers, and keep the printed line to around the same size --- programs/fileio.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index b27f314a..86ce997d 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1338,14 +1338,23 @@ FIO_compressZstdFrame(FIO_ctx_t* const fCtx, cShare ); } else { /* summarized notifications if == 2 */ if (fCtx->nbFilesTotal > 1) { - DISPLAYLEVEL(2, "\rCompressing %u/%u files. Current source: %s ", fCtx->currFileIdx+1, fCtx->nbFilesTotal, srcFileName); + size_t srcFileNameSize = strlen(srcFileName); + /* Ensure that the string we print is roughly the same size each time */ + if (srcFileNameSize > 20) { + const char* truncatedSrcFileName = srcFileName + srcFileNameSize - 17; + DISPLAYLEVEL(2, "\rCompressing %2u / %2u files. Current source: ...%s ", + fCtx->currFileIdx+1, fCtx->nbFilesTotal, truncatedSrcFileName); + } else { + DISPLAYLEVEL(2, "\rCompressing %2u / %2u files. Current source: %*s ", + fCtx->currFileIdx+1, fCtx->nbFilesTotal, (int)(20-srcFileNameSize), srcFileName); + } } else { DISPLAYLEVEL(2, "\r"); } - DISPLAYLEVEL(2, "Read : %u ", (unsigned)(zfp.consumed >> 20)); + DISPLAYLEVEL(2, "Read : %2u ", (unsigned)(zfp.consumed >> 20)); if (fileSize != UTIL_FILESIZE_UNKNOWN) - DISPLAYLEVEL(2, "/ %u ", (unsigned)(fileSize >> 20)); - DISPLAYLEVEL(2, "MB ==> %2.f%%", cShare); + DISPLAYLEVEL(2, "/ %2u ", (unsigned)(fileSize >> 20)); + DISPLAYLEVEL(2, "MB ==> %2.f%% ", cShare); DELAY_NEXT_UPDATE(); } @@ -1817,9 +1826,9 @@ int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx, } if (fCtx->nbFilesProcessed >= 1 && fCtx->nbFilesTotal > 1 && fCtx->totalBytesInput != 0) - DISPLAYLEVEL(2, "%d files compressed : %.2f%% (%6zu => %6zu bytes)\n", fCtx->nbFilesProcessed, + DISPLAYLEVEL(2, "%d files compressed : %.2f%% (%6zu => %6zu %-40s\n", fCtx->nbFilesProcessed, (double)fCtx->totalBytesOutput/((double)fCtx->totalBytesInput)*100, - fCtx->totalBytesInput, fCtx->totalBytesOutput); + fCtx->totalBytesInput, fCtx->totalBytesOutput, "bytes)"); FIO_freeCResources(ress); return error;