Add color support for restart messages and comments displayed by sar.
Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
char sc_zero_int_stat[] = C_LIGHT_YELLOW;
char sc_int_stat[] = C_BOLD_YELLOW;
char sc_item_name[] = C_LIGHT_GREEN;
+char sc_sa_restart[] = C_LIGHT_RED;
+char sc_sa_comment[] = C_LIGHT_CYAN;
char sc_normal[] = C_NORMAL;
/* Type of persistent device names used in sar and iostat */
strcpy(sc_zero_int_stat, "");
strcpy(sc_int_stat, "");
strcpy(sc_item_name, "");
+ strcpy(sc_sa_comment, "");
+ strcpy(sc_sa_restart, "");
strcpy(sc_normal, "");
}
}
}
printf("%s", sc_normal);
}
+
+/*
+ ***************************************************************************
+ * Print a string using selected color.
+ *
+ * IN:
+ * @type Type of string to display.
+ * @format Output format.
+ * @string String to display.
+ ***************************************************************************
+*/
+void cprintf_s(int type, char *format, char *string)
+{
+ if (type == IS_RESTART) {
+ printf("%s", sc_sa_restart);
+ }
+ else {
+ /* IS_COMMENT */
+ printf("%s", sc_sa_comment);
+ }
+ printf(format, string);
+ printf("%s", sc_normal);
+}
***************************************************************************
*/
+#define C_LIGHT_RED "\e[31;22m"
#define C_BOLD_RED "\e[31;1m"
#define C_LIGHT_GREEN "\e[32;22m"
#define C_LIGHT_YELLOW "\e[33;22m"
#define C_BOLD_YELLOW "\e[33;1m"
#define C_BOLD_BLUE "\e[34;1m"
+#define C_LIGHT_CYAN "\e[36;22m"
#define C_NORMAL "\e[0m"
#define PERCENT_LIMIT_HIGH 75.0
#define PERCENT_LIMIT_LOW 50.0
-#define IS_INT 0
-#define IS_STR 1
+#define IS_INT 0
+#define IS_STR 1
+#define IS_RESTART 2
+#define IS_COMMENT 3
/*
***************************************************************************
cprintf_in(int, char *, char *, int);
extern void
cprintf_pc(int, int, int, ...);
+extern void
+ cprintf_s(int, char *, char *);
extern void
cprintf_ull(int, int, ...);
extern char *
int sar_print_special(int curr, int use_tm_start, int use_tm_end, int rtype,
int ifd, char *file, struct file_magic *file_magic)
{
- char cur_time[26];
+ char cur_time[26], restart[64];
int dp = 1;
unsigned int new_cpu_nr;
file_hdr.sa_vol_act_nr);
if (dp) {
- printf("\n%-11s LINUX RESTART\t(%d CPU)\n",
- cur_time, new_cpu_nr > 1 ? new_cpu_nr - 1 : 1);
+ printf("\n%-11s", cur_time);
+ sprintf(restart, " LINUX RESTART\t(%d CPU)\n",
+ new_cpu_nr > 1 ? new_cpu_nr - 1 : 1);
+ cprintf_s(IS_RESTART, "%s", restart);
return 1;
}
}
replace_nonprintable_char(ifd, file_comment);
if (dp && DISPLAY_COMMENT(flags)) {
- printf("%-11s COM %s\n", cur_time, file_comment);
+ printf("%-11s", cur_time);
+ cprintf_s(IS_COMMENT, " COM %s\n", file_comment);
return 1;
}
}
init_nls();
#endif
+ /* Init color strings */
+ init_colors();
+
tm_start.use = tm_end.use = FALSE;
/* Allocate and init activity bitmaps */