Skip to content

Commit

Permalink
Merge branch 'fix-byte-fields' of xavierog/htop
Browse files Browse the repository at this point in the history
This will see a further code cleanup being prepared at
Explorer09/htop-1 branch print-bytes-improve
  • Loading branch information
Daniel Lange authored and Daniel Lange committed Aug 11, 2023
2 parents 278ebbb + 0f1a05e commit 03d5e47
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@ void Process_printBytes(RichString* str, unsigned long long number, bool colorin
number %= 1000;
len = xSnprintf(buffer, sizeof(buffer), "%03lluM ", number);
RichString_appendnAscii(str, processMegabytesColor, buffer, len);
} else if (number < 100000 * ONE_K) {
} else if (number < 100 * ONE_M) {
//2 digit GB, 1 digit MB
number /= 100 * ONE_K;
len = xSnprintf(buffer, sizeof(buffer), "%2llu", number / 10);
len = xSnprintf(buffer, sizeof(buffer), "%2llu", number / ONE_M);
RichString_appendnAscii(str, processGigabytesColor, buffer, len);
number %= 10;
number = (number % ONE_M) * 10 / ONE_M;
len = xSnprintf(buffer, sizeof(buffer), ".%1llu", number);
RichString_appendnAscii(str, processMegabytesColor, buffer, len);
RichString_appendAscii(str, processGigabytesColor, "G ");
Expand All @@ -133,12 +132,11 @@ void Process_printBytes(RichString* str, unsigned long long number, bool colorin
number %= 1000;
len = xSnprintf(buffer, sizeof(buffer), "%03lluG ", number);
RichString_appendnAscii(str, processGigabytesColor, buffer, len);
} else if (number < 100000 * ONE_M) {
} else if (number < 100ULL * ONE_G) {
//2 digit TB, 1 digit GB
number /= 100 * ONE_M;
len = xSnprintf(buffer, sizeof(buffer), "%2llu", number / 10);
len = xSnprintf(buffer, sizeof(buffer), "%2llu", number / ONE_G);
RichString_appendnAscii(str, largeNumberColor, buffer, len);
number %= 10;
number = (number % ONE_G) * 10 / ONE_G;
len = xSnprintf(buffer, sizeof(buffer), ".%1llu", number);
RichString_appendnAscii(str, processGigabytesColor, buffer, len);
RichString_appendAscii(str, largeNumberColor, "T ");
Expand Down

0 comments on commit 03d5e47

Please sign in to comment.