From 89539c200bf93d53ee9b91b521c09bd4607e01d0 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 16 Feb 2022 23:22:36 +0000 Subject: added human formatting for hbar --- src/glyphs.sh | 3 +++ src/hbar.c | 37 +++++++++++++++++++++++++++++++++---- test/hbar.sh | 16 ++++++++++++---- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/glyphs.sh b/src/glyphs.sh index dc4c285..56b5625 100644 --- a/src/glyphs.sh +++ b/src/glyphs.sh @@ -4,5 +4,8 @@ export CHECKMARK="✔" export CROSSMARK="✘" +export HOURGLASS="⧖" +export LARGE_CIRCLE="◯" +export REFRESH="🗘" export TABCHAR="╰┈➤ " diff --git a/src/hbar.c b/src/hbar.c index e301fb4..17840d8 100644 --- a/src/hbar.c +++ b/src/hbar.c @@ -20,6 +20,21 @@ #define SAVE_POS "\033[s" #define LOAD_POS "\033[u" +static void human_format(int bytes, char *output) { + char *suffix[] = {"B", "KB", "MB", "GB", "TB"}; + char length = sizeof(suffix) / sizeof(suffix[0]); + + int i = 0; + double dblBytes = bytes; + + if (bytes > 1024) { + for (i = 0; (bytes / 1024) > 0 && i