Enhance highlighting of semi-large and large numbers

This commit is contained in:
Benny Baumann 2020-09-13 23:50:24 +02:00 committed by cgzones
parent c7568bc054
commit 40441dca8e
3 changed files with 53 additions and 28 deletions

6
CRT.c
View File

@ -98,6 +98,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
[PROCESS_MEGABYTES] = ColorPair(Cyan,Black), [PROCESS_MEGABYTES] = ColorPair(Cyan,Black),
[PROCESS_GIGABYTES] = ColorPair(Green,Black),
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black), [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black),
[PROCESS_TREE] = ColorPair(Cyan,Black), [PROCESS_TREE] = ColorPair(Cyan,Black),
[PROCESS_R_STATE] = ColorPair(Green,Black), [PROCESS_R_STATE] = ColorPair(Green,Black),
@ -167,6 +168,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_DIM, [PROCESS_SHADOW] = A_DIM,
[PROCESS_TAG] = A_BOLD, [PROCESS_TAG] = A_BOLD,
[PROCESS_MEGABYTES] = A_BOLD, [PROCESS_MEGABYTES] = A_BOLD,
[PROCESS_GIGABYTES] = A_BOLD,
[PROCESS_BASENAME] = A_BOLD, [PROCESS_BASENAME] = A_BOLD,
[PROCESS_TREE] = A_BOLD, [PROCESS_TREE] = A_BOLD,
[PROCESS_R_STATE] = A_BOLD, [PROCESS_R_STATE] = A_BOLD,
@ -236,6 +238,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White), [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White),
[PROCESS_TAG] = ColorPair(White,Blue), [PROCESS_TAG] = ColorPair(White,Blue),
[PROCESS_MEGABYTES] = ColorPair(Blue,White), [PROCESS_MEGABYTES] = ColorPair(Blue,White),
[PROCESS_GIGABYTES] = ColorPair(Green,White),
[PROCESS_BASENAME] = ColorPair(Blue,White), [PROCESS_BASENAME] = ColorPair(Blue,White),
[PROCESS_TREE] = ColorPair(Green,White), [PROCESS_TREE] = ColorPair(Green,White),
[PROCESS_R_STATE] = ColorPair(Green,White), [PROCESS_R_STATE] = ColorPair(Green,White),
@ -305,6 +308,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
[PROCESS_TAG] = ColorPair(White,Blue), [PROCESS_TAG] = ColorPair(White,Blue),
[PROCESS_MEGABYTES] = ColorPair(Blue,Black), [PROCESS_MEGABYTES] = ColorPair(Blue,Black),
[PROCESS_GIGABYTES] = ColorPair(Green,Black),
[PROCESS_BASENAME] = ColorPair(Green,Black), [PROCESS_BASENAME] = ColorPair(Green,Black),
[PROCESS_TREE] = ColorPair(Blue,Black), [PROCESS_TREE] = ColorPair(Blue,Black),
[PROCESS_R_STATE] = ColorPair(Green,Black), [PROCESS_R_STATE] = ColorPair(Green,Black),
@ -374,6 +378,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue), [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue),
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue), [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue),
[PROCESS_MEGABYTES] = ColorPair(Cyan,Blue), [PROCESS_MEGABYTES] = ColorPair(Cyan,Blue),
[PROCESS_GIGABYTES] = ColorPair(Green,Blue),
[PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Blue), [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Blue),
[PROCESS_TREE] = ColorPair(Cyan,Blue), [PROCESS_TREE] = ColorPair(Cyan,Blue),
[PROCESS_R_STATE] = ColorPair(Green,Blue), [PROCESS_R_STATE] = ColorPair(Green,Blue),
@ -443,6 +448,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack,
[PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
[PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black), [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black),
[PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow,Black),
[PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black), [PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black),
[PROCESS_TREE] = ColorPair(Cyan,Black), [PROCESS_TREE] = ColorPair(Cyan,Black),
[PROCESS_THREAD] = ColorPair(Green,Black), [PROCESS_THREAD] = ColorPair(Green,Black),

1
CRT.h
View File

@ -58,6 +58,7 @@ typedef enum ColorElements_ {
PROCESS_SHADOW, PROCESS_SHADOW,
PROCESS_TAG, PROCESS_TAG,
PROCESS_MEGABYTES, PROCESS_MEGABYTES,
PROCESS_GIGABYTES,
PROCESS_TREE, PROCESS_TREE,
PROCESS_R_STATE, PROCESS_R_STATE,
PROCESS_D_STATE, PROCESS_D_STATE,

View File

@ -61,46 +61,64 @@ void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
int largeNumberColor = CRT_colors[LARGE_NUMBER]; int largeNumberColor = CRT_colors[LARGE_NUMBER];
int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES]; int processMegabytesColor = CRT_colors[PROCESS_MEGABYTES];
int processGigabytesColor = CRT_colors[PROCESS_GIGABYTES];
int processColor = CRT_colors[PROCESS]; int processColor = CRT_colors[PROCESS];
if (!coloring) { if (!coloring) {
largeNumberColor = CRT_colors[PROCESS]; largeNumberColor = CRT_colors[PROCESS];
processMegabytesColor = CRT_colors[PROCESS]; processMegabytesColor = CRT_colors[PROCESS];
processGigabytesColor = CRT_colors[PROCESS];
} }
if(number >= (10 * ONE_DECIMAL_M)) { if (number < 1000) {
#ifdef __LP64__ //Plain number, no markings
if(number >= (100 * ONE_DECIMAL_G)) { len = snprintf(buffer, 10, "%5lu ", number);
len = snprintf(buffer, 10, "%4luT ", number / ONE_G); RichString_appendn(str, processColor, buffer, len);
RichString_appendn(str, largeNumberColor, buffer, len); } else if (number < 100000) {
return; //2 digit MB, 3 digit KB
} else if (number >= (1000 * ONE_DECIMAL_M)) {
len = snprintf(buffer, 10, "%4.1lfT ", (double)number / ONE_G);
RichString_appendn(str, largeNumberColor, buffer, len);
return;
}
#endif
if(number >= (100 * ONE_DECIMAL_M)) {
len = snprintf(buffer, 10, "%4luG ", number / ONE_M);
RichString_appendn(str, largeNumberColor, buffer, len);
return;
}
len = snprintf(buffer, 10, "%4.1lfG ", (double)number / ONE_M);
RichString_appendn(str, largeNumberColor, buffer, len);
return;
} else if (number >= 100000) {
len = snprintf(buffer, 10, "%4luM ", number / ONE_K);
RichString_appendn(str, processMegabytesColor, buffer, len);
return;
} else if (number >= 1000) {
len = snprintf(buffer, 10, "%2lu", number/1000); len = snprintf(buffer, 10, "%2lu", number/1000);
RichString_appendn(str, processMegabytesColor, buffer, len); RichString_appendn(str, processMegabytesColor, buffer, len);
number %= 1000; number %= 1000;
len = snprintf(buffer, 10, "%03lu ", number); len = snprintf(buffer, 10, "%03lu ", number);
RichString_appendn(str, processColor, buffer, len); RichString_appendn(str, processColor, buffer, len);
return; } else if (number < 1000 * ONE_K) {
//3 digit MB
number /= ONE_K;
len = snprintf(buffer, 10, "%4luM ", number);
RichString_appendn(str, processMegabytesColor, buffer, len);
} else if (number < 10000 * ONE_K) {
//1 digit GB, 3 digit MB
number /= ONE_K;
len = snprintf(buffer, 10, "%1lu", number/1000);
RichString_appendn(str, processGigabytesColor, buffer, len);
number %= 1000;
len = snprintf(buffer, 10, "%03luM ", number);
RichString_appendn(str, processMegabytesColor, buffer, len);
} else if (number < 100 * ONE_M) {
//2 digit GB, 1 digit MB
number /= 100 * ONE_K;
len = snprintf(buffer, 10, "%2lu", number/10);
RichString_appendn(str, processGigabytesColor, buffer, len);
number %= 10;
len = snprintf(buffer, 10, ".%1luG ", number);
RichString_appendn(str, processMegabytesColor, buffer, len);
} else if (number < 1000 * ONE_M) {
//3 digit GB
number /= ONE_M;
len = snprintf(buffer, 10, "%4luG ", number);
RichString_appendn(str, processGigabytesColor, buffer, len);
} else if (number < 10000 * ONE_M) {
//1 digit TB, 3 digit GB
number /= ONE_M;
len = snprintf(buffer, 10, "%1lu", number/1000);
RichString_appendn(str, largeNumberColor, buffer, len);
number %= 1000;
len = snprintf(buffer, 10, "%03luG ", number);
RichString_appendn(str, processGigabytesColor, buffer, len);
} else {
//2 digit TB and above
len = snprintf(buffer, 10, "%4.1lfT ", (double)number/ONE_G);
RichString_appendn(str, largeNumberColor, buffer, len);
} }
len = snprintf(buffer, 10, "%5lu ", number);
RichString_appendn(str, processColor, buffer, len);
} }
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring) { void Process_colorNumber(RichString* str, unsigned long long number, bool coloring) {