From 36260b58146cb535c5c08a38ab924d9685164db0 Mon Sep 17 00:00:00 2001 From: xzeldon Date: Tue, 7 Jun 2022 22:16:47 +0300 Subject: [PATCH] CPU Temperature and Frequency meter for Linux platform --- CRT.c | 1665 ++++++++++++++++++++++++---------------------- CRT.h | 34 +- FreqMeter.c | 29 + FreqMeter.h | 8 + Makefile.am | 4 + Settings.c | 720 ++++++++++++++------ TempMeter.c | 29 + TempMeter.h | 8 + XUtils.h | 47 +- linux/Platform.c | 742 +++++++++++++-------- linux/Platform.h | 79 ++- 11 files changed, 1975 insertions(+), 1390 deletions(-) create mode 100644 FreqMeter.c create mode 100644 FreqMeter.h create mode 100644 TempMeter.c create mode 100644 TempMeter.h diff --git a/CRT.c b/CRT.c index 95f8cc13..643c24a0 100644 --- a/CRT.c +++ b/CRT.c @@ -27,75 +27,75 @@ in the source distribution for its full text. #endif #if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND) -# define PRINT_BACKTRACE -# define UNW_LOCAL_ONLY -# include -# if defined(HAVE_DLADDR) -# include -# endif +#define PRINT_BACKTRACE +#define UNW_LOCAL_ONLY +#include +#if defined(HAVE_DLADDR) +#include +#endif #elif defined(HAVE_EXECINFO_H) -# define PRINT_BACKTRACE -# include +#define PRINT_BACKTRACE +#include #endif +#define ColorIndex(i, j) ((7 - (i)) * 8 + (j)) -#define ColorIndex(i,j) ((7-(i))*8+(j)) +#define ColorPair(i, j) COLOR_PAIR(ColorIndex(i, j)) -#define ColorPair(i,j) COLOR_PAIR(ColorIndex(i,j)) - -#define Black COLOR_BLACK -#define Red COLOR_RED -#define Green COLOR_GREEN -#define Yellow COLOR_YELLOW -#define Blue COLOR_BLUE +#define Black COLOR_BLACK +#define Red COLOR_RED +#define Green COLOR_GREEN +#define Yellow COLOR_YELLOW +#define Blue COLOR_BLUE #define Magenta COLOR_MAGENTA -#define Cyan COLOR_CYAN -#define White COLOR_WHITE +#define Cyan COLOR_CYAN +#define White COLOR_WHITE -#define ColorPairGrayBlack ColorPair(Magenta,Magenta) -#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) +#define ColorPairGrayBlack ColorPair(Magenta, Magenta) +#define ColorIndexGrayBlack ColorIndex(Magenta, Magenta) -#define ColorPairWhiteDefault ColorPair(Red, Red) +#define ColorPairWhiteDefault ColorPair(Red, Red) #define ColorIndexWhiteDefault ColorIndex(Red, Red) -static const char* const CRT_treeStrAscii[LAST_TREE_STR] = { - [TREE_STR_VERT] = "|", - [TREE_STR_RTEE] = "`", - [TREE_STR_BEND] = "`", - [TREE_STR_TEND] = ",", - [TREE_STR_OPEN] = "+", - [TREE_STR_SHUT] = "-", - [TREE_STR_ASC] = "+", - [TREE_STR_DESC] = "-", +static const char *const CRT_treeStrAscii[LAST_TREE_STR] = { + [TREE_STR_VERT] = "|", + [TREE_STR_RTEE] = "`", + [TREE_STR_BEND] = "`", + [TREE_STR_TEND] = ",", + [TREE_STR_OPEN] = "+", + [TREE_STR_SHUT] = "-", + [TREE_STR_ASC] = "+", + [TREE_STR_DESC] = "-", }; #ifdef HAVE_LIBNCURSESW -static const char* const CRT_treeStrUtf8[LAST_TREE_STR] = { - [TREE_STR_VERT] = "\xe2\x94\x82", // │ - [TREE_STR_RTEE] = "\xe2\x94\x9c", // ├ - [TREE_STR_BEND] = "\xe2\x94\x94", // └ - [TREE_STR_TEND] = "\xe2\x94\x8c", // ┌ - [TREE_STR_OPEN] = "+", // +, TODO use 🮯 'BOX DRAWINGS LIGHT HORIZONTAL - // WITH VERTICAL STROKE' (U+1FBAF, "\xf0\x9f\xae\xaf") when - // Unicode 13 is common - [TREE_STR_SHUT] = "\xe2\x94\x80", // ─ - [TREE_STR_ASC] = "\xe2\x96\xb3", // △ - [TREE_STR_DESC] = "\xe2\x96\xbd", // ▽ +static const char *const CRT_treeStrUtf8[LAST_TREE_STR] = { + [TREE_STR_VERT] = "\xe2\x94\x82", // │ + [TREE_STR_RTEE] = "\xe2\x94\x9c", // ├ + [TREE_STR_BEND] = "\xe2\x94\x94", // └ + [TREE_STR_TEND] = "\xe2\x94\x8c", // ┌ + [TREE_STR_OPEN] = "+", // +, TODO use 🮯 'BOX DRAWINGS LIGHT HORIZONTAL + // WITH VERTICAL STROKE' (U+1FBAF, "\xf0\x9f\xae\xaf") when + // Unicode 13 is common + [TREE_STR_SHUT] = "\xe2\x94\x80", // ─ + [TREE_STR_ASC] = "\xe2\x96\xb3", // △ + [TREE_STR_DESC] = "\xe2\x96\xbd", // ▽ }; bool CRT_utf8 = false; #endif -const char* const* CRT_treeStr = CRT_treeStrAscii; +const char *const *CRT_treeStr = CRT_treeStrAscii; -static const Settings* CRT_crashSettings; -static const int* CRT_delay; +static const Settings *CRT_crashSettings; +static const int *CRT_delay; -const char* CRT_degreeSign; +const char *CRT_degreeSign; -static const char* initDegreeSign(void) { +static const char *initDegreeSign(void) +{ #ifdef HAVE_LIBNCURSESW if (CRT_utf8) return "\xc2\xb0"; @@ -110,650 +110,662 @@ static const char* initDegreeSign(void) { return ""; } -const int* CRT_colors; +const int *CRT_colors; static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { - [COLORSCHEME_DEFAULT] = { - [RESET_COLOR] = ColorPair(White, Black), - [DEFAULT_COLOR] = ColorPair(White, Black), - [FUNCTION_BAR] = ColorPair(Black, Cyan), - [FUNCTION_KEY] = ColorPair(White, Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), - [FAILED_SEARCH] = ColorPair(Red, Cyan), - [FAILED_READ] = A_BOLD | ColorPair(Red, Black), - [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), - [UPTIME] = A_BOLD | ColorPair(Cyan, Black), - [BATTERY] = A_BOLD | ColorPair(Cyan, Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), - [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, - [METER_TEXT] = ColorPair(Cyan, Black), - [METER_VALUE] = A_BOLD | ColorPair(Cyan, Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_IOREAD] = ColorPair(Green, Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), - [METER_VALUE_OK] = ColorPair(Green, Black), - [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), - [LED_COLOR] = ColorPair(Green, Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), - [PROCESS] = A_NORMAL, - [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), - [PROCESS_MEGABYTES] = ColorPair(Cyan, Black), - [PROCESS_GIGABYTES] = ColorPair(Green, Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black), - [PROCESS_TREE] = ColorPair(Cyan, Black), - [PROCESS_RUN_STATE] = ColorPair(Green, Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black, Green), - [PROCESS_TOMB] = ColorPair(Black, Red), - [PROCESS_THREAD] = ColorPair(Green, Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Black), - [PROCESS_COMM] = ColorPair(Magenta, Black), - [PROCESS_THREAD_COMM] = ColorPair(Blue, Black), - [BAR_BORDER] = A_BOLD, - [BAR_SHADOW] = A_BOLD | ColorPairGrayBlack, - [SWAP] = ColorPair(Red, Black), - [SWAP_CACHE] = ColorPair(Yellow, Black), - [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), - [GRAPH_2] = ColorPair(Cyan, Black), - [MEMORY_USED] = ColorPair(Green, Black), - [MEMORY_BUFFERS] = ColorPair(Blue, Black), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), - [MEMORY_CACHE] = ColorPair(Yellow, Black), - [MEMORY_SHARED] = ColorPair(Magenta, Black), - [HUGEPAGE_1] = ColorPair(Green, Black), - [HUGEPAGE_2] = ColorPair(Yellow, Black), - [HUGEPAGE_3] = ColorPair(Red, Black), - [HUGEPAGE_4] = ColorPair(Blue, Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan, Black), - [LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan, Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Black), - [LOAD] = A_BOLD, - [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), - [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, - [CLOCK] = A_BOLD, - [DATE] = A_BOLD, - [DATETIME] = A_BOLD, - [CHECK_BOX] = ColorPair(Cyan, Black), - [CHECK_MARK] = A_BOLD, - [CHECK_TEXT] = A_NORMAL, - [HOSTNAME] = A_BOLD, - [CPU_NICE] = ColorPair(Blue, Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), - [CPU_NORMAL] = ColorPair(Green, Black), - [CPU_SYSTEM] = ColorPair(Red, Black), - [CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack, - [CPU_IRQ] = ColorPair(Yellow, Black), - [CPU_SOFTIRQ] = ColorPair(Magenta, Black), - [CPU_STEAL] = ColorPair(Cyan, Black), - [CPU_GUEST] = ColorPair(Cyan, Black), - [PANEL_EDIT] = ColorPair(White, Blue), - [SCREENS_OTH_BORDER] = ColorPair(Blue, Blue), - [SCREENS_OTH_TEXT] = ColorPair(Black, Blue), - [SCREENS_CUR_BORDER] = ColorPair(Green, Green), - [SCREENS_CUR_TEXT] = ColorPair(Black, Green), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan, Black), - [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan, Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Black), - [ZFS_MFU] = ColorPair(Blue, Black), - [ZFS_MRU] = ColorPair(Yellow, Black), - [ZFS_ANON] = ColorPair(Magenta, Black), - [ZFS_HEADER] = ColorPair(Cyan, Black), - [ZFS_OTHER] = ColorPair(Magenta, Black), - [ZFS_COMPRESSED] = ColorPair(Blue, Black), - [ZFS_RATIO] = ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), - [DYNAMIC_GRAY] = ColorPairGrayBlack, - [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, - [DYNAMIC_RED] = ColorPair(Red, Black), - [DYNAMIC_GREEN] = ColorPair(Green, Black), - [DYNAMIC_BLUE] = ColorPair(Blue, Black), - [DYNAMIC_CYAN] = ColorPair(Cyan, Black), - [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), - [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), - [DYNAMIC_WHITE] = ColorPair(White, Black), - }, - [COLORSCHEME_MONOCHROME] = { - [RESET_COLOR] = A_NORMAL, - [DEFAULT_COLOR] = A_NORMAL, - [FUNCTION_BAR] = A_REVERSE, - [FUNCTION_KEY] = A_NORMAL, - [PANEL_HEADER_FOCUS] = A_REVERSE, - [PANEL_HEADER_UNFOCUS] = A_REVERSE, - [PANEL_SELECTION_FOCUS] = A_REVERSE, - [PANEL_SELECTION_FOLLOW] = A_REVERSE, - [PANEL_SELECTION_UNFOCUS] = A_BOLD, - [FAILED_SEARCH] = A_REVERSE | A_BOLD, - [FAILED_READ] = A_BOLD, - [PAUSED] = A_BOLD | A_REVERSE, - [UPTIME] = A_BOLD, - [BATTERY] = A_BOLD, - [LARGE_NUMBER] = A_BOLD, - [METER_SHADOW] = A_DIM, - [METER_TEXT] = A_NORMAL, - [METER_VALUE] = A_BOLD, - [METER_VALUE_ERROR] = A_BOLD, - [METER_VALUE_IOREAD] = A_NORMAL, - [METER_VALUE_IOWRITE] = A_NORMAL, - [METER_VALUE_NOTICE] = A_BOLD, - [METER_VALUE_OK] = A_NORMAL, - [METER_VALUE_WARN] = A_BOLD, - [LED_COLOR] = A_NORMAL, - [TASKS_RUNNING] = A_BOLD, - [PROCESS] = A_NORMAL, - [PROCESS_SHADOW] = A_DIM, - [PROCESS_TAG] = A_BOLD, - [PROCESS_MEGABYTES] = A_BOLD, - [PROCESS_GIGABYTES] = A_BOLD, - [PROCESS_BASENAME] = A_BOLD, - [PROCESS_TREE] = A_BOLD, - [PROCESS_RUN_STATE] = A_BOLD, - [PROCESS_D_STATE] = A_BOLD, - [PROCESS_HIGH_PRIORITY] = A_BOLD, - [PROCESS_LOW_PRIORITY] = A_DIM, - [PROCESS_NEW] = A_BOLD, - [PROCESS_TOMB] = A_DIM, - [PROCESS_THREAD] = A_BOLD, - [PROCESS_THREAD_BASENAME] = A_REVERSE, - [PROCESS_COMM] = A_BOLD, - [PROCESS_THREAD_COMM] = A_REVERSE, - [BAR_BORDER] = A_BOLD, - [BAR_SHADOW] = A_DIM, - [SWAP] = A_BOLD, - [SWAP_CACHE] = A_NORMAL, - [GRAPH_1] = A_BOLD, - [GRAPH_2] = A_NORMAL, - [MEMORY_USED] = A_BOLD, - [MEMORY_BUFFERS] = A_NORMAL, - [MEMORY_BUFFERS_TEXT] = A_NORMAL, - [MEMORY_CACHE] = A_NORMAL, - [MEMORY_SHARED] = A_NORMAL, - [HUGEPAGE_1] = A_BOLD, - [HUGEPAGE_2] = A_NORMAL, - [HUGEPAGE_3] = A_REVERSE | A_BOLD, - [HUGEPAGE_4] = A_REVERSE, - [LOAD_AVERAGE_FIFTEEN] = A_DIM, - [LOAD_AVERAGE_FIVE] = A_NORMAL, - [LOAD_AVERAGE_ONE] = A_BOLD, - [LOAD] = A_BOLD, - [HELP_BOLD] = A_BOLD, - [HELP_SHADOW] = A_DIM, - [CLOCK] = A_BOLD, - [DATE] = A_BOLD, - [DATETIME] = A_BOLD, - [CHECK_BOX] = A_BOLD, - [CHECK_MARK] = A_NORMAL, - [CHECK_TEXT] = A_NORMAL, - [HOSTNAME] = A_BOLD, - [CPU_NICE] = A_NORMAL, - [CPU_NICE_TEXT] = A_NORMAL, - [CPU_NORMAL] = A_BOLD, - [CPU_SYSTEM] = A_BOLD, - [CPU_IOWAIT] = A_NORMAL, - [CPU_IRQ] = A_BOLD, - [CPU_SOFTIRQ] = A_BOLD, - [CPU_STEAL] = A_DIM, - [CPU_GUEST] = A_DIM, - [PANEL_EDIT] = A_BOLD, - [SCREENS_OTH_BORDER] = A_DIM, - [SCREENS_OTH_TEXT] = A_DIM, - [SCREENS_CUR_BORDER] = A_REVERSE, - [SCREENS_CUR_TEXT] = A_REVERSE, - [PRESSURE_STALL_THREEHUNDRED] = A_DIM, - [PRESSURE_STALL_SIXTY] = A_NORMAL, - [PRESSURE_STALL_TEN] = A_BOLD, - [ZFS_MFU] = A_NORMAL, - [ZFS_MRU] = A_NORMAL, - [ZFS_ANON] = A_DIM, - [ZFS_HEADER] = A_BOLD, - [ZFS_OTHER] = A_DIM, - [ZFS_COMPRESSED] = A_BOLD, - [ZFS_RATIO] = A_BOLD, - [ZRAM] = A_NORMAL, - [DYNAMIC_GRAY] = A_DIM, - [DYNAMIC_DARKGRAY] = A_DIM, - [DYNAMIC_RED] = A_BOLD, - [DYNAMIC_GREEN] = A_NORMAL, - [DYNAMIC_BLUE] = A_NORMAL, - [DYNAMIC_CYAN] = A_BOLD, - [DYNAMIC_MAGENTA] = A_NORMAL, - [DYNAMIC_YELLOW] = A_NORMAL, - [DYNAMIC_WHITE] = A_BOLD, - }, - [COLORSCHEME_BLACKONWHITE] = { - [RESET_COLOR] = ColorPair(Black, White), - [DEFAULT_COLOR] = ColorPair(Black, White), - [FUNCTION_BAR] = ColorPair(Black, Cyan), - [FUNCTION_KEY] = ColorPair(Black, White), - [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, White), - [FAILED_SEARCH] = ColorPair(Red, Cyan), - [FAILED_READ] = ColorPair(Red, White), - [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), - [UPTIME] = ColorPair(Yellow, White), - [BATTERY] = ColorPair(Yellow, White), - [LARGE_NUMBER] = ColorPair(Red, White), - [METER_SHADOW] = ColorPair(Blue, White), - [METER_TEXT] = ColorPair(Blue, White), - [METER_VALUE] = ColorPair(Black, White), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White), - [METER_VALUE_IOREAD] = ColorPair(Green, White), - [METER_VALUE_IOWRITE] = ColorPair(Yellow, White), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), - [METER_VALUE_OK] = ColorPair(Green, White), - [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, White), - [LED_COLOR] = ColorPair(Green, White), - [TASKS_RUNNING] = ColorPair(Green, White), - [PROCESS] = ColorPair(Black, White), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, White), - [PROCESS_TAG] = ColorPair(White, Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue, White), - [PROCESS_GIGABYTES] = ColorPair(Green, White), - [PROCESS_BASENAME] = ColorPair(Blue, White), - [PROCESS_TREE] = ColorPair(Green, White), - [PROCESS_RUN_STATE] = ColorPair(Green, White), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red, White), - [PROCESS_LOW_PRIORITY] = ColorPair(Green, White), - [PROCESS_NEW] = ColorPair(White, Green), - [PROCESS_TOMB] = ColorPair(White, Red), - [PROCESS_THREAD] = ColorPair(Blue, White), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, White), - [PROCESS_COMM] = ColorPair(Magenta, White), - [PROCESS_THREAD_COMM] = ColorPair(Green, White), - [BAR_BORDER] = ColorPair(Blue, White), - [BAR_SHADOW] = ColorPair(Black, White), - [SWAP] = ColorPair(Red, White), - [SWAP_CACHE] = ColorPair(Yellow, White), - [GRAPH_1] = A_BOLD | ColorPair(Blue, White), - [GRAPH_2] = ColorPair(Blue, White), - [MEMORY_USED] = ColorPair(Green, White), - [MEMORY_BUFFERS] = ColorPair(Cyan, White), - [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White), - [MEMORY_CACHE] = ColorPair(Yellow, White), - [MEMORY_SHARED] = ColorPair(Magenta, White), - [HUGEPAGE_1] = ColorPair(Green, White), - [HUGEPAGE_2] = ColorPair(Yellow, White), - [HUGEPAGE_3] = ColorPair(Red, White), - [HUGEPAGE_4] = ColorPair(Blue, White), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, White), - [LOAD_AVERAGE_FIVE] = ColorPair(Black, White), - [LOAD_AVERAGE_ONE] = ColorPair(Black, White), - [LOAD] = ColorPair(Black, White), - [HELP_BOLD] = ColorPair(Blue, White), - [HELP_SHADOW] = A_BOLD | ColorPair(Black, White), - [CLOCK] = ColorPair(Black, White), - [DATE] = ColorPair(Black, White), - [DATETIME] = ColorPair(Black, White), - [CHECK_BOX] = ColorPair(Blue, White), - [CHECK_MARK] = ColorPair(Black, White), - [CHECK_TEXT] = ColorPair(Black, White), - [HOSTNAME] = ColorPair(Black, White), - [CPU_NICE] = ColorPair(Cyan, White), - [CPU_NICE_TEXT] = ColorPair(Cyan, White), - [CPU_NORMAL] = ColorPair(Green, White), - [CPU_SYSTEM] = ColorPair(Red, White), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), - [CPU_IRQ] = ColorPair(Blue, White), - [CPU_SOFTIRQ] = ColorPair(Blue, White), - [CPU_STEAL] = ColorPair(Cyan, White), - [CPU_GUEST] = ColorPair(Cyan, White), - [PANEL_EDIT] = ColorPair(White,Blue), - [SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black,White), - [SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black,White), - [SCREENS_CUR_BORDER] = ColorPair(Green,Green), - [SCREENS_CUR_TEXT] = ColorPair(Black,Green), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, White), - [PRESSURE_STALL_SIXTY] = ColorPair(Black, White), - [PRESSURE_STALL_TEN] = ColorPair(Black, White), - [ZFS_MFU] = ColorPair(Cyan, White), - [ZFS_MRU] = ColorPair(Yellow, White), - [ZFS_ANON] = ColorPair(Magenta, White), - [ZFS_HEADER] = ColorPair(Yellow, White), - [ZFS_OTHER] = ColorPair(Magenta, White), - [ZFS_COMPRESSED] = ColorPair(Cyan, White), - [ZFS_RATIO] = ColorPair(Magenta, White), - [ZRAM] = ColorPair(Yellow, White), - [DYNAMIC_GRAY] = ColorPair(Black, White), - [DYNAMIC_DARKGRAY] = A_BOLD | ColorPair(Black, White), - [DYNAMIC_RED] = ColorPair(Red, White), - [DYNAMIC_GREEN] = ColorPair(Green, White), - [DYNAMIC_BLUE] = ColorPair(Blue, White), - [DYNAMIC_CYAN] = ColorPair(Yellow, White), - [DYNAMIC_MAGENTA] = ColorPair(Magenta, White), - [DYNAMIC_YELLOW] = ColorPair(Yellow, White), - [DYNAMIC_WHITE] = A_BOLD | ColorPair(Black, White), - }, - [COLORSCHEME_LIGHTTERMINAL] = { - [RESET_COLOR] = ColorPair(Black, Black), - [DEFAULT_COLOR] = ColorPair(Black, Black), - [FUNCTION_BAR] = ColorPair(Black, Cyan), - [FUNCTION_KEY] = ColorPair(Black, Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, Black), - [FAILED_SEARCH] = ColorPair(Red, Cyan), - [FAILED_READ] = ColorPair(Red, Black), - [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), - [UPTIME] = ColorPair(Yellow, Black), - [BATTERY] = ColorPair(Yellow, Black), - [LARGE_NUMBER] = ColorPair(Red, Black), - [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, - [METER_TEXT] = ColorPair(Blue, Black), - [METER_VALUE] = ColorPair(Black, Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_IOREAD] = ColorPair(Green, Black), - [METER_VALUE_IOWRITE] = ColorPair(Yellow, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPairWhiteDefault, - [METER_VALUE_OK] = ColorPair(Green, Black), - [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), - [LED_COLOR] = ColorPair(Green, Black), - [TASKS_RUNNING] = ColorPair(Green, Black), - [PROCESS] = ColorPair(Black, Black), - [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = ColorPair(White, Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue, Black), - [PROCESS_GIGABYTES] = ColorPair(Green, Black), - [PROCESS_BASENAME] = ColorPair(Green, Black), - [PROCESS_TREE] = ColorPair(Blue, Black), - [PROCESS_RUN_STATE] = ColorPair(Green, Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black, Green), - [PROCESS_TOMB] = ColorPair(Black, Red), - [PROCESS_THREAD] = ColorPair(Blue, Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), - [PROCESS_COMM] = ColorPair(Magenta, Black), - [PROCESS_THREAD_COMM] = ColorPair(Yellow, Black), - [BAR_BORDER] = ColorPair(Blue, Black), - [BAR_SHADOW] = ColorPairGrayBlack, - [SWAP] = ColorPair(Red, Black), - [SWAP_CACHE] = ColorPair(Yellow, Black), - [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), - [GRAPH_2] = ColorPair(Cyan, Black), - [MEMORY_USED] = ColorPair(Green, Black), - [MEMORY_BUFFERS] = ColorPair(Cyan, Black), - [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black), - [MEMORY_CACHE] = ColorPair(Yellow, Black), - [MEMORY_SHARED] = ColorPair(Magenta, Black), - [HUGEPAGE_1] = ColorPair(Green, Black), - [HUGEPAGE_2] = ColorPair(Yellow, Black), - [HUGEPAGE_3] = ColorPair(Red, Black), - [HUGEPAGE_4] = ColorPair(Blue, Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Black, Black), - [LOAD_AVERAGE_ONE] = ColorPair(Black, Black), - [LOAD] = ColorPairWhiteDefault, - [HELP_BOLD] = ColorPair(Blue, Black), - [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, - [CLOCK] = ColorPairWhiteDefault, - [DATE] = ColorPairWhiteDefault, - [DATETIME] = ColorPairWhiteDefault, - [CHECK_BOX] = ColorPair(Blue, Black), - [CHECK_MARK] = ColorPair(Black, Black), - [CHECK_TEXT] = ColorPair(Black, Black), - [HOSTNAME] = ColorPairWhiteDefault, - [CPU_NICE] = ColorPair(Cyan, Black), - [CPU_NICE_TEXT] = ColorPair(Cyan, Black), - [CPU_NORMAL] = ColorPair(Green, Black), - [CPU_SYSTEM] = ColorPair(Red, Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), - [CPU_SOFTIRQ] = ColorPair(Blue, Black), - [CPU_STEAL] = ColorPair(Black, Black), - [CPU_GUEST] = ColorPair(Black, Black), - [PANEL_EDIT] = ColorPair(White,Blue), - [SCREENS_OTH_BORDER] = ColorPair(Blue,Black), - [SCREENS_OTH_TEXT] = ColorPair(Blue,Black), - [SCREENS_CUR_BORDER] = ColorPair(Green,Green), - [SCREENS_CUR_TEXT] = ColorPair(Black,Green), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Black, Black), - [PRESSURE_STALL_TEN] = ColorPair(Black, Black), - [ZFS_MFU] = ColorPair(Cyan, Black), - [ZFS_MRU] = ColorPair(Yellow, Black), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Black), - [ZFS_HEADER] = ColorPair(Black, Black), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Black), - [ZFS_COMPRESSED] = ColorPair(Cyan, Black), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), - [DYNAMIC_GRAY] = ColorPairGrayBlack, - [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, - [DYNAMIC_RED] = ColorPair(Red, Black), - [DYNAMIC_GREEN] = ColorPair(Green, Black), - [DYNAMIC_BLUE] = ColorPair(Blue, Black), - [DYNAMIC_CYAN] = ColorPair(Cyan, Black), - [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), - [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), - [DYNAMIC_WHITE] = ColorPairWhiteDefault, - }, - [COLORSCHEME_MIDNIGHT] = { - [RESET_COLOR] = ColorPair(White, Blue), - [DEFAULT_COLOR] = ColorPair(White, Blue), - [FUNCTION_BAR] = ColorPair(Black, Cyan), - [FUNCTION_KEY] = A_NORMAL, - [PANEL_HEADER_FOCUS] = ColorPair(Black, Cyan), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Cyan), - [PANEL_SELECTION_FOCUS] = ColorPair(Black, White), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), - [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow, Blue), - [FAILED_SEARCH] = ColorPair(Red, Cyan), - [FAILED_READ] = A_BOLD | ColorPair(Red, Blue), - [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), - [UPTIME] = A_BOLD | ColorPair(Yellow, Blue), - [BATTERY] = A_BOLD | ColorPair(Yellow, Blue), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Blue), - [METER_SHADOW] = ColorPair(Cyan, Blue), - [METER_TEXT] = ColorPair(Cyan, Blue), - [METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue), - [METER_VALUE_IOREAD] = ColorPair(Green, Blue), - [METER_VALUE_IOWRITE] = ColorPair(Black, Blue), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), - [METER_VALUE_OK] = ColorPair(Green, Blue), - [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), - [LED_COLOR] = ColorPair(Green, Blue), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Blue), - [PROCESS] = ColorPair(White, Blue), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, Blue), - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Blue), - [PROCESS_MEGABYTES] = ColorPair(Cyan, Blue), - [PROCESS_GIGABYTES] = ColorPair(Green, Blue), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue), - [PROCESS_TREE] = ColorPair(Cyan, Blue), - [PROCESS_RUN_STATE] = ColorPair(Green, Blue), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue), - [PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue), - [PROCESS_NEW] = ColorPair(Blue, Green), - [PROCESS_TOMB] = ColorPair(Blue, Red), - [PROCESS_THREAD] = ColorPair(Green, Blue), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Blue), - [PROCESS_COMM] = ColorPair(Magenta, Blue), - [PROCESS_THREAD_COMM] = ColorPair(Black, Blue), - [BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue), - [BAR_SHADOW] = ColorPair(Cyan, Blue), - [SWAP] = ColorPair(Red, Blue), - [SWAP_CACHE] = A_BOLD | ColorPair(Yellow, Blue), - [GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue), - [GRAPH_2] = ColorPair(Cyan, Blue), - [MEMORY_USED] = A_BOLD | ColorPair(Green, Blue), - [MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan, Blue), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue), - [MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue), - [MEMORY_SHARED] = A_BOLD | ColorPair(Magenta, Blue), - [HUGEPAGE_1] = A_BOLD | ColorPair(Green, Blue), - [HUGEPAGE_2] = A_BOLD | ColorPair(Yellow, Blue), - [HUGEPAGE_3] = A_BOLD | ColorPair(Red, Blue), - [HUGEPAGE_4] = A_BOLD | ColorPair(White, Blue), - [LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black, Blue), - [LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White, Blue), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Blue), - [LOAD] = A_BOLD | ColorPair(White, Blue), - [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Blue), - [HELP_SHADOW] = A_BOLD | ColorPair(Black, Blue), - [CLOCK] = ColorPair(White, Blue), - [DATE] = ColorPair(White, Blue), - [DATETIME] = ColorPair(White, Blue), - [CHECK_BOX] = ColorPair(Cyan, Blue), - [CHECK_MARK] = A_BOLD | ColorPair(White, Blue), - [CHECK_TEXT] = A_NORMAL | ColorPair(White, Blue), - [HOSTNAME] = ColorPair(White, Blue), - [CPU_NICE] = A_BOLD | ColorPair(Cyan, Blue), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan, Blue), - [CPU_NORMAL] = A_BOLD | ColorPair(Green, Blue), - [CPU_SYSTEM] = A_BOLD | ColorPair(Red, Blue), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Blue), - [CPU_IRQ] = A_BOLD | ColorPair(Black, Blue), - [CPU_SOFTIRQ] = ColorPair(Black, Blue), - [CPU_STEAL] = ColorPair(White, Blue), - [CPU_GUEST] = ColorPair(White, Blue), - [PANEL_EDIT] = ColorPair(White,Blue), - [SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow,Blue), - [SCREENS_OTH_TEXT] = ColorPair(Cyan,Blue), - [SCREENS_CUR_BORDER] = ColorPair(Cyan,Cyan), - [SCREENS_CUR_TEXT] = ColorPair(Black,Cyan), - [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black, Blue), - [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White, Blue), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Blue), - [ZFS_MFU] = A_BOLD | ColorPair(White, Blue), - [ZFS_MRU] = A_BOLD | ColorPair(Yellow, Blue), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Blue), - [ZFS_HEADER] = A_BOLD | ColorPair(Yellow, Blue), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Blue), - [ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue), - [ZRAM] = A_BOLD | ColorPair(Yellow, Blue), - [DYNAMIC_GRAY] = ColorPairGrayBlack, - [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, - [DYNAMIC_RED] = ColorPair(Red, Blue), - [DYNAMIC_GREEN] = ColorPair(Green, Blue), - [DYNAMIC_BLUE] = ColorPair(Black, Blue), - [DYNAMIC_CYAN] = ColorPair(Cyan, Blue), - [DYNAMIC_MAGENTA] = ColorPair(Magenta, Blue), - [DYNAMIC_YELLOW] = ColorPair(Yellow, Blue), - [DYNAMIC_WHITE] = ColorPair(White, Blue), - }, - [COLORSCHEME_BLACKNIGHT] = { - [RESET_COLOR] = ColorPair(Cyan, Black), - [DEFAULT_COLOR] = ColorPair(Cyan, Black), - [FUNCTION_BAR] = ColorPair(Black, Green), - [FUNCTION_KEY] = ColorPair(Cyan, Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), - [FAILED_SEARCH] = ColorPair(Red, Green), - [FAILED_READ] = A_BOLD | ColorPair(Red, Black), - [PAUSED] = A_BOLD | ColorPair(Yellow, Green), - [UPTIME] = ColorPair(Green, Black), - [BATTERY] = ColorPair(Green, Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), - [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, - [METER_TEXT] = ColorPair(Cyan, Black), - [METER_VALUE] = ColorPair(Green, Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), - [METER_VALUE_IOREAD] = ColorPair(Green, Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), - [METER_VALUE_OK] = ColorPair(Green, Black), - [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), - [LED_COLOR] = ColorPair(Green, Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), - [PROCESS] = ColorPair(Cyan, Black), - [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), - [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green, Black), - [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow, Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Green, Black), - [PROCESS_TREE] = ColorPair(Cyan, Black), - [PROCESS_THREAD] = ColorPair(Green, Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), - [PROCESS_COMM] = ColorPair(Magenta, Black), - [PROCESS_THREAD_COMM] = ColorPair(Yellow, Black), - [PROCESS_RUN_STATE] = ColorPair(Green, Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), - [PROCESS_NEW] = ColorPair(Black, Green), - [PROCESS_TOMB] = ColorPair(Black, Red), - [BAR_BORDER] = A_BOLD | ColorPair(Green, Black), - [BAR_SHADOW] = ColorPair(Cyan, Black), - [SWAP] = ColorPair(Red, Black), - [SWAP_CACHE] = ColorPair(Yellow, Black), - [GRAPH_1] = A_BOLD | ColorPair(Green, Black), - [GRAPH_2] = ColorPair(Green, Black), - [MEMORY_USED] = ColorPair(Green, Black), - [MEMORY_BUFFERS] = ColorPair(Blue, Black), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), - [MEMORY_CACHE] = ColorPair(Yellow, Black), - [MEMORY_SHARED] = ColorPair(Magenta, Black), - [HUGEPAGE_1] = ColorPair(Green, Black), - [HUGEPAGE_2] = ColorPair(Yellow, Black), - [HUGEPAGE_3] = ColorPair(Red, Black), - [HUGEPAGE_4] = ColorPair(Blue, Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Green, Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Green, Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green, Black), - [LOAD] = A_BOLD, - [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), - [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, - [CLOCK] = ColorPair(Green, Black), - [CHECK_BOX] = ColorPair(Green, Black), - [CHECK_MARK] = A_BOLD | ColorPair(Green, Black), - [CHECK_TEXT] = ColorPair(Cyan, Black), - [HOSTNAME] = ColorPair(Green, Black), - [CPU_NICE] = ColorPair(Blue, Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), - [CPU_NORMAL] = ColorPair(Green, Black), - [CPU_SYSTEM] = ColorPair(Red, Black), - [CPU_IOWAIT] = ColorPair(Yellow, Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), - [CPU_SOFTIRQ] = ColorPair(Blue, Black), - [CPU_STEAL] = ColorPair(Cyan, Black), - [CPU_GUEST] = ColorPair(Cyan, Black), - [PANEL_EDIT] = ColorPair(White,Cyan), - [SCREENS_OTH_BORDER] = ColorPair(White,Black), - [SCREENS_OTH_TEXT] = ColorPair(Cyan,Black), - [SCREENS_CUR_BORDER] = A_BOLD | ColorPair(White,Black), - [SCREENS_CUR_TEXT] = A_BOLD | ColorPair(Green,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green, Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Green, Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green, Black), - [ZFS_MFU] = ColorPair(Blue, Black), - [ZFS_MRU] = ColorPair(Yellow, Black), - [ZFS_ANON] = ColorPair(Magenta, Black), - [ZFS_HEADER] = ColorPair(Yellow, Black), - [ZFS_OTHER] = ColorPair(Magenta, Black), - [ZFS_COMPRESSED] = ColorPair(Blue, Black), - [ZFS_RATIO] = ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), - [DYNAMIC_GRAY] = ColorPairGrayBlack, - [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, - [DYNAMIC_RED] = ColorPair(Red, Black), - [DYNAMIC_GREEN] = ColorPair(Green, Black), - [DYNAMIC_BLUE] = ColorPair(Blue, Black), - [DYNAMIC_CYAN] = ColorPair(Cyan, Black), - [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), - [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), - [DYNAMIC_WHITE] = ColorPair(White, Black), - }, - [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. + [COLORSCHEME_DEFAULT] = { + [RESET_COLOR] = ColorPair(White, Black), + [DEFAULT_COLOR] = ColorPair(White, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(White, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [FAILED_READ] = A_BOLD | ColorPair(Red, Black), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Cyan, Black), + [TEMP] = A_BOLD | ColorPair(Cyan, Black), + [FREQ] = A_BOLD | ColorPair(Cyan, Black), + [BATTERY] = A_BOLD | ColorPair(Cyan, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), + [METER_VALUE_OK] = ColorPair(Green, Black), + [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), + [PROCESS] = A_NORMAL, + [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_RUN_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Black), + [PROCESS_COMM] = ColorPair(Magenta, Black), + [PROCESS_THREAD_COMM] = ColorPair(Blue, Black), + [BAR_BORDER] = A_BOLD, + [BAR_SHADOW] = A_BOLD | ColorPairGrayBlack, + [SWAP] = ColorPair(Red, Black), + [SWAP_CACHE] = ColorPair(Yellow, Black), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), + [GRAPH_2] = ColorPair(Cyan, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Blue, Black), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [MEMORY_SHARED] = ColorPair(Magenta, Black), + [HUGEPAGE_1] = ColorPair(Green, Black), + [HUGEPAGE_2] = ColorPair(Yellow, Black), + [HUGEPAGE_3] = ColorPair(Red, Black), + [HUGEPAGE_4] = ColorPair(Blue, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan, Black), + [LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan, Black), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Black), + [LOAD] = A_BOLD, + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), + [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, + [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, + [CHECK_BOX] = ColorPair(Cyan, Black), + [CHECK_MARK] = A_BOLD, + [CHECK_TEXT] = A_NORMAL, + [HOSTNAME] = A_BOLD, + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack, + [CPU_IRQ] = ColorPair(Yellow, Black), + [CPU_SOFTIRQ] = ColorPair(Magenta, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PANEL_EDIT] = ColorPair(White, Blue), + [SCREENS_OTH_BORDER] = ColorPair(Blue, Blue), + [SCREENS_OTH_TEXT] = ColorPair(Black, Blue), + [SCREENS_CUR_BORDER] = ColorPair(Green, Green), + [SCREENS_CUR_TEXT] = ColorPair(Black, Green), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan, Black), + [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Cyan, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), + [DYNAMIC_GRAY] = ColorPairGrayBlack, + [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, + [DYNAMIC_RED] = ColorPair(Red, Black), + [DYNAMIC_GREEN] = ColorPair(Green, Black), + [DYNAMIC_BLUE] = ColorPair(Blue, Black), + [DYNAMIC_CYAN] = ColorPair(Cyan, Black), + [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), + [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), + [DYNAMIC_WHITE] = ColorPair(White, Black), + }, + [COLORSCHEME_MONOCHROME] = { + [RESET_COLOR] = A_NORMAL, + [DEFAULT_COLOR] = A_NORMAL, + [FUNCTION_BAR] = A_REVERSE, + [FUNCTION_KEY] = A_NORMAL, + [PANEL_HEADER_FOCUS] = A_REVERSE, + [PANEL_HEADER_UNFOCUS] = A_REVERSE, + [PANEL_SELECTION_FOCUS] = A_REVERSE, + [PANEL_SELECTION_FOLLOW] = A_REVERSE, + [PANEL_SELECTION_UNFOCUS] = A_BOLD, + [FAILED_SEARCH] = A_REVERSE | A_BOLD, + [FAILED_READ] = A_BOLD, + [PAUSED] = A_BOLD | A_REVERSE, + [UPTIME] = A_BOLD, + [TEMP] = A_BOLD, + [FREQ] = A_BOLD, + [BATTERY] = A_BOLD, + [LARGE_NUMBER] = A_BOLD, + [METER_SHADOW] = A_DIM, + [METER_TEXT] = A_NORMAL, + [METER_VALUE] = A_BOLD, + [METER_VALUE_ERROR] = A_BOLD, + [METER_VALUE_IOREAD] = A_NORMAL, + [METER_VALUE_IOWRITE] = A_NORMAL, + [METER_VALUE_NOTICE] = A_BOLD, + [METER_VALUE_OK] = A_NORMAL, + [METER_VALUE_WARN] = A_BOLD, + [LED_COLOR] = A_NORMAL, + [TASKS_RUNNING] = A_BOLD, + [PROCESS] = A_NORMAL, + [PROCESS_SHADOW] = A_DIM, + [PROCESS_TAG] = A_BOLD, + [PROCESS_MEGABYTES] = A_BOLD, + [PROCESS_GIGABYTES] = A_BOLD, + [PROCESS_BASENAME] = A_BOLD, + [PROCESS_TREE] = A_BOLD, + [PROCESS_RUN_STATE] = A_BOLD, + [PROCESS_D_STATE] = A_BOLD, + [PROCESS_HIGH_PRIORITY] = A_BOLD, + [PROCESS_LOW_PRIORITY] = A_DIM, + [PROCESS_NEW] = A_BOLD, + [PROCESS_TOMB] = A_DIM, + [PROCESS_THREAD] = A_BOLD, + [PROCESS_THREAD_BASENAME] = A_REVERSE, + [PROCESS_COMM] = A_BOLD, + [PROCESS_THREAD_COMM] = A_REVERSE, + [BAR_BORDER] = A_BOLD, + [BAR_SHADOW] = A_DIM, + [SWAP] = A_BOLD, + [SWAP_CACHE] = A_NORMAL, + [GRAPH_1] = A_BOLD, + [GRAPH_2] = A_NORMAL, + [MEMORY_USED] = A_BOLD, + [MEMORY_BUFFERS] = A_NORMAL, + [MEMORY_BUFFERS_TEXT] = A_NORMAL, + [MEMORY_CACHE] = A_NORMAL, + [MEMORY_SHARED] = A_NORMAL, + [HUGEPAGE_1] = A_BOLD, + [HUGEPAGE_2] = A_NORMAL, + [HUGEPAGE_3] = A_REVERSE | A_BOLD, + [HUGEPAGE_4] = A_REVERSE, + [LOAD_AVERAGE_FIFTEEN] = A_DIM, + [LOAD_AVERAGE_FIVE] = A_NORMAL, + [LOAD_AVERAGE_ONE] = A_BOLD, + [LOAD] = A_BOLD, + [HELP_BOLD] = A_BOLD, + [HELP_SHADOW] = A_DIM, + [CLOCK] = A_BOLD, + [DATE] = A_BOLD, + [DATETIME] = A_BOLD, + [CHECK_BOX] = A_BOLD, + [CHECK_MARK] = A_NORMAL, + [CHECK_TEXT] = A_NORMAL, + [HOSTNAME] = A_BOLD, + [CPU_NICE] = A_NORMAL, + [CPU_NICE_TEXT] = A_NORMAL, + [CPU_NORMAL] = A_BOLD, + [CPU_SYSTEM] = A_BOLD, + [CPU_IOWAIT] = A_NORMAL, + [CPU_IRQ] = A_BOLD, + [CPU_SOFTIRQ] = A_BOLD, + [CPU_STEAL] = A_DIM, + [CPU_GUEST] = A_DIM, + [PANEL_EDIT] = A_BOLD, + [SCREENS_OTH_BORDER] = A_DIM, + [SCREENS_OTH_TEXT] = A_DIM, + [SCREENS_CUR_BORDER] = A_REVERSE, + [SCREENS_CUR_TEXT] = A_REVERSE, + [PRESSURE_STALL_THREEHUNDRED] = A_DIM, + [PRESSURE_STALL_SIXTY] = A_NORMAL, + [PRESSURE_STALL_TEN] = A_BOLD, + [ZFS_MFU] = A_NORMAL, + [ZFS_MRU] = A_NORMAL, + [ZFS_ANON] = A_DIM, + [ZFS_HEADER] = A_BOLD, + [ZFS_OTHER] = A_DIM, + [ZFS_COMPRESSED] = A_BOLD, + [ZFS_RATIO] = A_BOLD, + [ZRAM] = A_NORMAL, + [DYNAMIC_GRAY] = A_DIM, + [DYNAMIC_DARKGRAY] = A_DIM, + [DYNAMIC_RED] = A_BOLD, + [DYNAMIC_GREEN] = A_NORMAL, + [DYNAMIC_BLUE] = A_NORMAL, + [DYNAMIC_CYAN] = A_BOLD, + [DYNAMIC_MAGENTA] = A_NORMAL, + [DYNAMIC_YELLOW] = A_NORMAL, + [DYNAMIC_WHITE] = A_BOLD, + }, + [COLORSCHEME_BLACKONWHITE] = { + [RESET_COLOR] = ColorPair(Black, White), + [DEFAULT_COLOR] = ColorPair(Black, White), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Black, White), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [FAILED_READ] = ColorPair(Red, White), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, White), + [TEMP] = ColorPair(Yellow, White), + [FREQ] = ColorPair(Yellow, White), + [BATTERY] = ColorPair(Yellow, White), + [LARGE_NUMBER] = ColorPair(Red, White), + [METER_SHADOW] = ColorPair(Blue, White), + [METER_TEXT] = ColorPair(Blue, White), + [METER_VALUE] = ColorPair(Black, White), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White), + [METER_VALUE_IOREAD] = ColorPair(Green, White), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), + [METER_VALUE_OK] = ColorPair(Green, White), + [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, White), + [LED_COLOR] = ColorPair(Green, White), + [TASKS_RUNNING] = ColorPair(Green, White), + [PROCESS] = ColorPair(Black, White), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, White), + [PROCESS_TAG] = ColorPair(White, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, White), + [PROCESS_GIGABYTES] = ColorPair(Green, White), + [PROCESS_BASENAME] = ColorPair(Blue, White), + [PROCESS_TREE] = ColorPair(Green, White), + [PROCESS_RUN_STATE] = ColorPair(Green, White), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, White), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, White), + [PROCESS_NEW] = ColorPair(White, Green), + [PROCESS_TOMB] = ColorPair(White, Red), + [PROCESS_THREAD] = ColorPair(Blue, White), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, White), + [PROCESS_COMM] = ColorPair(Magenta, White), + [PROCESS_THREAD_COMM] = ColorPair(Green, White), + [BAR_BORDER] = ColorPair(Blue, White), + [BAR_SHADOW] = ColorPair(Black, White), + [SWAP] = ColorPair(Red, White), + [SWAP_CACHE] = ColorPair(Yellow, White), + [GRAPH_1] = A_BOLD | ColorPair(Blue, White), + [GRAPH_2] = ColorPair(Blue, White), + [MEMORY_USED] = ColorPair(Green, White), + [MEMORY_BUFFERS] = ColorPair(Cyan, White), + [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White), + [MEMORY_CACHE] = ColorPair(Yellow, White), + [MEMORY_SHARED] = ColorPair(Magenta, White), + [HUGEPAGE_1] = ColorPair(Green, White), + [HUGEPAGE_2] = ColorPair(Yellow, White), + [HUGEPAGE_3] = ColorPair(Red, White), + [HUGEPAGE_4] = ColorPair(Blue, White), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, White), + [LOAD_AVERAGE_FIVE] = ColorPair(Black, White), + [LOAD_AVERAGE_ONE] = ColorPair(Black, White), + [LOAD] = ColorPair(Black, White), + [HELP_BOLD] = ColorPair(Blue, White), + [HELP_SHADOW] = A_BOLD | ColorPair(Black, White), + [CLOCK] = ColorPair(Black, White), + [DATE] = ColorPair(Black, White), + [DATETIME] = ColorPair(Black, White), + [CHECK_BOX] = ColorPair(Blue, White), + [CHECK_MARK] = ColorPair(Black, White), + [CHECK_TEXT] = ColorPair(Black, White), + [HOSTNAME] = ColorPair(Black, White), + [CPU_NICE] = ColorPair(Cyan, White), + [CPU_NICE_TEXT] = ColorPair(Cyan, White), + [CPU_NORMAL] = ColorPair(Green, White), + [CPU_SYSTEM] = ColorPair(Red, White), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), + [CPU_IRQ] = ColorPair(Blue, White), + [CPU_SOFTIRQ] = ColorPair(Blue, White), + [CPU_STEAL] = ColorPair(Cyan, White), + [CPU_GUEST] = ColorPair(Cyan, White), + [PANEL_EDIT] = ColorPair(White, Blue), + [SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Black, White), + [SCREENS_OTH_TEXT] = A_BOLD | ColorPair(Black, White), + [SCREENS_CUR_BORDER] = ColorPair(Green, Green), + [SCREENS_CUR_TEXT] = ColorPair(Black, Green), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, White), + [PRESSURE_STALL_SIXTY] = ColorPair(Black, White), + [PRESSURE_STALL_TEN] = ColorPair(Black, White), + [ZFS_MFU] = ColorPair(Cyan, White), + [ZFS_MRU] = ColorPair(Yellow, White), + [ZFS_ANON] = ColorPair(Magenta, White), + [ZFS_HEADER] = ColorPair(Yellow, White), + [ZFS_OTHER] = ColorPair(Magenta, White), + [ZFS_COMPRESSED] = ColorPair(Cyan, White), + [ZFS_RATIO] = ColorPair(Magenta, White), + [ZRAM] = ColorPair(Yellow, White), + [DYNAMIC_GRAY] = ColorPair(Black, White), + [DYNAMIC_DARKGRAY] = A_BOLD | ColorPair(Black, White), + [DYNAMIC_RED] = ColorPair(Red, White), + [DYNAMIC_GREEN] = ColorPair(Green, White), + [DYNAMIC_BLUE] = ColorPair(Blue, White), + [DYNAMIC_CYAN] = ColorPair(Yellow, White), + [DYNAMIC_MAGENTA] = ColorPair(Magenta, White), + [DYNAMIC_YELLOW] = ColorPair(Yellow, White), + [DYNAMIC_WHITE] = A_BOLD | ColorPair(Black, White), + }, + [COLORSCHEME_LIGHTTERMINAL] = { + [RESET_COLOR] = ColorPair(Black, Black), + [DEFAULT_COLOR] = ColorPair(Black, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Black, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, Black), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [FAILED_READ] = ColorPair(Red, Black), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, Black), + [TEMP] = ColorPair(Yellow, Black), + [FREQ] = ColorPair(Yellow, Black), + [BATTERY] = ColorPair(Yellow, Black), + [LARGE_NUMBER] = ColorPair(Red, Black), + [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, + [METER_TEXT] = ColorPair(Blue, Black), + [METER_VALUE] = ColorPair(Black, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPairWhiteDefault, + [METER_VALUE_OK] = ColorPair(Green, Black), + [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = ColorPair(Green, Black), + [PROCESS] = ColorPair(Black, Black), + [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, + [PROCESS_TAG] = ColorPair(White, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Blue, Black), + [PROCESS_RUN_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), + [PROCESS_THREAD] = ColorPair(Blue, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [PROCESS_COMM] = ColorPair(Magenta, Black), + [PROCESS_THREAD_COMM] = ColorPair(Yellow, Black), + [BAR_BORDER] = ColorPair(Blue, Black), + [BAR_SHADOW] = ColorPairGrayBlack, + [SWAP] = ColorPair(Red, Black), + [SWAP_CACHE] = ColorPair(Yellow, Black), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), + [GRAPH_2] = ColorPair(Cyan, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Cyan, Black), + [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [MEMORY_SHARED] = ColorPair(Magenta, Black), + [HUGEPAGE_1] = ColorPair(Green, Black), + [HUGEPAGE_2] = ColorPair(Yellow, Black), + [HUGEPAGE_3] = ColorPair(Red, Black), + [HUGEPAGE_4] = ColorPair(Blue, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Black, Black), + [LOAD_AVERAGE_ONE] = ColorPair(Black, Black), + [LOAD] = ColorPairWhiteDefault, + [HELP_BOLD] = ColorPair(Blue, Black), + [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, + [CLOCK] = ColorPairWhiteDefault, + [DATE] = ColorPairWhiteDefault, + [DATETIME] = ColorPairWhiteDefault, + [CHECK_BOX] = ColorPair(Blue, Black), + [CHECK_MARK] = ColorPair(Black, Black), + [CHECK_TEXT] = ColorPair(Black, Black), + [HOSTNAME] = ColorPairWhiteDefault, + [CPU_NICE] = ColorPair(Cyan, Black), + [CPU_NICE_TEXT] = ColorPair(Cyan, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Black, Black), + [CPU_GUEST] = ColorPair(Black, Black), + [PANEL_EDIT] = ColorPair(White, Blue), + [SCREENS_OTH_BORDER] = ColorPair(Blue, Black), + [SCREENS_OTH_TEXT] = ColorPair(Blue, Black), + [SCREENS_CUR_BORDER] = ColorPair(Green, Green), + [SCREENS_CUR_TEXT] = ColorPair(Black, Green), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Black, Black), + [PRESSURE_STALL_TEN] = ColorPair(Black, Black), + [ZFS_MFU] = ColorPair(Cyan, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Black, Black), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Cyan, Black), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), + [DYNAMIC_GRAY] = ColorPairGrayBlack, + [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, + [DYNAMIC_RED] = ColorPair(Red, Black), + [DYNAMIC_GREEN] = ColorPair(Green, Black), + [DYNAMIC_BLUE] = ColorPair(Blue, Black), + [DYNAMIC_CYAN] = ColorPair(Cyan, Black), + [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), + [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), + [DYNAMIC_WHITE] = ColorPairWhiteDefault, + }, + [COLORSCHEME_MIDNIGHT] = { + [RESET_COLOR] = ColorPair(White, Blue), + [DEFAULT_COLOR] = ColorPair(White, Blue), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = A_NORMAL, + [PANEL_HEADER_FOCUS] = ColorPair(Black, Cyan), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, White), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow, Blue), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [FAILED_READ] = A_BOLD | ColorPair(Red, Blue), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Yellow, Blue), + [TEMP] = A_BOLD | ColorPair(Yellow, Blue), + [FREQ] = A_BOLD | ColorPair(Yellow, Blue), + [BATTERY] = A_BOLD | ColorPair(Yellow, Blue), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Blue), + [METER_SHADOW] = ColorPair(Cyan, Blue), + [METER_TEXT] = ColorPair(Cyan, Blue), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue), + [METER_VALUE_IOREAD] = ColorPair(Green, Blue), + [METER_VALUE_IOWRITE] = ColorPair(Black, Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), + [METER_VALUE_OK] = ColorPair(Green, Blue), + [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Blue), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Blue), + [PROCESS] = ColorPair(White, Blue), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, Blue), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Blue), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Blue), + [PROCESS_GIGABYTES] = ColorPair(Green, Blue), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue), + [PROCESS_TREE] = ColorPair(Cyan, Blue), + [PROCESS_RUN_STATE] = ColorPair(Green, Blue), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue), + [PROCESS_NEW] = ColorPair(Blue, Green), + [PROCESS_TOMB] = ColorPair(Blue, Red), + [PROCESS_THREAD] = ColorPair(Green, Blue), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Blue), + [PROCESS_COMM] = ColorPair(Magenta, Blue), + [PROCESS_THREAD_COMM] = ColorPair(Black, Blue), + [BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue), + [BAR_SHADOW] = ColorPair(Cyan, Blue), + [SWAP] = ColorPair(Red, Blue), + [SWAP_CACHE] = A_BOLD | ColorPair(Yellow, Blue), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue), + [GRAPH_2] = ColorPair(Cyan, Blue), + [MEMORY_USED] = A_BOLD | ColorPair(Green, Blue), + [MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan, Blue), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue), + [MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue), + [MEMORY_SHARED] = A_BOLD | ColorPair(Magenta, Blue), + [HUGEPAGE_1] = A_BOLD | ColorPair(Green, Blue), + [HUGEPAGE_2] = A_BOLD | ColorPair(Yellow, Blue), + [HUGEPAGE_3] = A_BOLD | ColorPair(Red, Blue), + [HUGEPAGE_4] = A_BOLD | ColorPair(White, Blue), + [LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black, Blue), + [LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White, Blue), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Blue), + [LOAD] = A_BOLD | ColorPair(White, Blue), + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Blue), + [HELP_SHADOW] = A_BOLD | ColorPair(Black, Blue), + [CLOCK] = ColorPair(White, Blue), + [DATE] = ColorPair(White, Blue), + [DATETIME] = ColorPair(White, Blue), + [CHECK_BOX] = ColorPair(Cyan, Blue), + [CHECK_MARK] = A_BOLD | ColorPair(White, Blue), + [CHECK_TEXT] = A_NORMAL | ColorPair(White, Blue), + [HOSTNAME] = ColorPair(White, Blue), + [CPU_NICE] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NORMAL] = A_BOLD | ColorPair(Green, Blue), + [CPU_SYSTEM] = A_BOLD | ColorPair(Red, Blue), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Blue), + [CPU_IRQ] = A_BOLD | ColorPair(Black, Blue), + [CPU_SOFTIRQ] = ColorPair(Black, Blue), + [CPU_STEAL] = ColorPair(White, Blue), + [CPU_GUEST] = ColorPair(White, Blue), + [PANEL_EDIT] = ColorPair(White, Blue), + [SCREENS_OTH_BORDER] = A_BOLD | ColorPair(Yellow, Blue), + [SCREENS_OTH_TEXT] = ColorPair(Cyan, Blue), + [SCREENS_CUR_BORDER] = ColorPair(Cyan, Cyan), + [SCREENS_CUR_TEXT] = ColorPair(Black, Cyan), + [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black, Blue), + [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White, Blue), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Blue), + [ZFS_MFU] = A_BOLD | ColorPair(White, Blue), + [ZFS_MRU] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_HEADER] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue), + [ZRAM] = A_BOLD | ColorPair(Yellow, Blue), + [DYNAMIC_GRAY] = ColorPairGrayBlack, + [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, + [DYNAMIC_RED] = ColorPair(Red, Blue), + [DYNAMIC_GREEN] = ColorPair(Green, Blue), + [DYNAMIC_BLUE] = ColorPair(Black, Blue), + [DYNAMIC_CYAN] = ColorPair(Cyan, Blue), + [DYNAMIC_MAGENTA] = ColorPair(Magenta, Blue), + [DYNAMIC_YELLOW] = ColorPair(Yellow, Blue), + [DYNAMIC_WHITE] = ColorPair(White, Blue), + }, + [COLORSCHEME_BLACKNIGHT] = { + [RESET_COLOR] = ColorPair(Cyan, Black), + [DEFAULT_COLOR] = ColorPair(Cyan, Black), + [FUNCTION_BAR] = ColorPair(Black, Green), + [FUNCTION_KEY] = ColorPair(Cyan, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Green), + [FAILED_READ] = A_BOLD | ColorPair(Red, Black), + [PAUSED] = A_BOLD | ColorPair(Yellow, Green), + [UPTIME] = ColorPair(Green, Black), + [TEMP] = ColorPair(Green, Black), + [FREQ] = ColorPair(Green, Black), + [BATTERY] = ColorPair(Green, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_SHADOW] = A_BOLD | ColorPairGrayBlack, + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = ColorPair(Green, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), + [METER_VALUE_OK] = ColorPair(Green, Black), + [METER_VALUE_WARN] = A_BOLD | ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), + [PROCESS] = ColorPair(Cyan, Black), + [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green, Black), + [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [PROCESS_COMM] = ColorPair(Magenta, Black), + [PROCESS_THREAD_COMM] = ColorPair(Yellow, Black), + [PROCESS_RUN_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_NEW] = ColorPair(Black, Green), + [PROCESS_TOMB] = ColorPair(Black, Red), + [BAR_BORDER] = A_BOLD | ColorPair(Green, Black), + [BAR_SHADOW] = ColorPair(Cyan, Black), + [SWAP] = ColorPair(Red, Black), + [SWAP_CACHE] = ColorPair(Yellow, Black), + [GRAPH_1] = A_BOLD | ColorPair(Green, Black), + [GRAPH_2] = ColorPair(Green, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Blue, Black), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [MEMORY_SHARED] = ColorPair(Magenta, Black), + [HUGEPAGE_1] = ColorPair(Green, Black), + [HUGEPAGE_2] = ColorPair(Yellow, Black), + [HUGEPAGE_3] = ColorPair(Red, Black), + [HUGEPAGE_4] = ColorPair(Blue, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Green, Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Green, Black), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green, Black), + [LOAD] = A_BOLD, + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), + [HELP_SHADOW] = A_BOLD | ColorPairGrayBlack, + [CLOCK] = ColorPair(Green, Black), + [CHECK_BOX] = ColorPair(Green, Black), + [CHECK_MARK] = A_BOLD | ColorPair(Green, Black), + [CHECK_TEXT] = ColorPair(Cyan, Black), + [HOSTNAME] = ColorPair(Green, Black), + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = ColorPair(Yellow, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PANEL_EDIT] = ColorPair(White, Cyan), + [SCREENS_OTH_BORDER] = ColorPair(White, Black), + [SCREENS_OTH_TEXT] = ColorPair(Cyan, Black), + [SCREENS_CUR_BORDER] = A_BOLD | ColorPair(White, Black), + [SCREENS_CUR_TEXT] = A_BOLD | ColorPair(Green, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Green, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Yellow, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), + [DYNAMIC_GRAY] = ColorPairGrayBlack, + [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, + [DYNAMIC_RED] = ColorPair(Red, Black), + [DYNAMIC_GREEN] = ColorPair(Green, Black), + [DYNAMIC_BLUE] = ColorPair(Blue, Black), + [DYNAMIC_CYAN] = ColorPair(Cyan, Black), + [DYNAMIC_MAGENTA] = ColorPair(Magenta, Black), + [DYNAMIC_YELLOW] = ColorPair(Yellow, Black), + [DYNAMIC_WHITE] = ColorPair(White, Black), + }, + [COLORSCHEME_BROKENGRAY] = {0} // dynamically generated. }; int CRT_scrollHAmount = 5; @@ -763,7 +775,8 @@ int CRT_scrollWheelVAmount = 10; ColorScheme CRT_colorScheme = COLORSCHEME_DEFAULT; ATTR_NORETURN -static void CRT_handleSIGTERM(ATTR_UNUSED int sgn) { +static void CRT_handleSIGTERM(ATTR_UNUSED int sgn) +{ CRT_done(); _exit(0); } @@ -773,7 +786,8 @@ static void CRT_handleSIGTERM(ATTR_UNUSED int sgn) { static int stderrRedirectNewFd = -1; static int stderrRedirectBackupFd = -1; -static int createStderrCacheFile(void) { +static int createStderrCacheFile(void) +{ #if defined(HAVE_MEMFD_CREATE) return memfd_create("htop.stderr-redirect", 0); #elif defined(O_TMPFILE) @@ -786,15 +800,17 @@ static int createStderrCacheFile(void) { if (r < 0) return r; - (void) unlink(tmpName); + (void)unlink(tmpName); return r; #endif /* HAVE_MEMFD_CREATE */ } -static void redirectStderr(void) { +static void redirectStderr(void) +{ stderrRedirectNewFd = createStderrCacheFile(); - if (stderrRedirectNewFd < 0) { + if (stderrRedirectNewFd < 0) + { /* ignore failure */ return; } @@ -803,7 +819,8 @@ static void redirectStderr(void) { dup2(stderrRedirectNewFd, STDERR_FILENO); } -static void dumpStderr(void) { +static void dumpStderr(void) +{ if (stderrRedirectNewFd < 0) return; @@ -815,26 +832,31 @@ static void dumpStderr(void) { bool header = false; char buffer[8192]; - for (;;) { + for (;;) + { errno = 0; ssize_t res = read(stderrRedirectNewFd, buffer, sizeof(buffer)); - if (res < 0) { + if (res < 0) + { if (errno == EINTR) continue; break; } - if (res == 0) { + if (res == 0) + { break; } - if (res > 0) { - if (!header) { + if (res > 0) + { + if (!header) + { fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n"); header = true; } - (void)! write(STDERR_FILENO, buffer, res); + (void)!write(STDERR_FILENO, buffer, res); } } @@ -845,7 +867,8 @@ static void dumpStderr(void) { stderrRedirectNewFd = -1; } -void CRT_debug_impl(const char* file, size_t lineno, const char* func, const char* fmt, ...) { +void CRT_debug_impl(const char *file, size_t lineno, const char *func, const char *fmt, ...) +{ va_list args; fprintf(stderr, "[%s:%zu (%s)]: ", file, lineno, func); @@ -857,28 +880,31 @@ void CRT_debug_impl(const char* file, size_t lineno, const char* func, const cha #else /* !NDEBUG */ -static void redirectStderr(void) { +static void redirectStderr(void) +{ } -static void dumpStderr(void) { +static void dumpStderr(void) +{ } #endif /* !NDEBUG */ static struct sigaction old_sig_handler[32]; -static void CRT_installSignalHandlers(void) { +static void CRT_installSignalHandlers(void) +{ struct sigaction act; - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); act.sa_flags = (int)SA_RESETHAND | SA_NODEFER; act.sa_handler = CRT_handleSIGSEGV; - sigaction (SIGSEGV, &act, &old_sig_handler[SIGSEGV]); - sigaction (SIGFPE, &act, &old_sig_handler[SIGFPE]); - sigaction (SIGILL, &act, &old_sig_handler[SIGILL]); - sigaction (SIGBUS, &act, &old_sig_handler[SIGBUS]); - sigaction (SIGPIPE, &act, &old_sig_handler[SIGPIPE]); - sigaction (SIGSYS, &act, &old_sig_handler[SIGSYS]); - sigaction (SIGABRT, &act, &old_sig_handler[SIGABRT]); + sigaction(SIGSEGV, &act, &old_sig_handler[SIGSEGV]); + sigaction(SIGFPE, &act, &old_sig_handler[SIGFPE]); + sigaction(SIGILL, &act, &old_sig_handler[SIGILL]); + sigaction(SIGBUS, &act, &old_sig_handler[SIGBUS]); + sigaction(SIGPIPE, &act, &old_sig_handler[SIGPIPE]); + sigaction(SIGSYS, &act, &old_sig_handler[SIGSYS]); + sigaction(SIGABRT, &act, &old_sig_handler[SIGABRT]); signal(SIGCHLD, SIG_DFL); signal(SIGINT, CRT_handleSIGTERM); @@ -886,35 +912,41 @@ static void CRT_installSignalHandlers(void) { signal(SIGQUIT, CRT_handleSIGTERM); } -void CRT_resetSignalHandlers(void) { - sigaction (SIGSEGV, &old_sig_handler[SIGSEGV], NULL); - sigaction (SIGFPE, &old_sig_handler[SIGFPE], NULL); - sigaction (SIGILL, &old_sig_handler[SIGILL], NULL); - sigaction (SIGBUS, &old_sig_handler[SIGBUS], NULL); - sigaction (SIGPIPE, &old_sig_handler[SIGPIPE], NULL); - sigaction (SIGSYS, &old_sig_handler[SIGSYS], NULL); - sigaction (SIGABRT, &old_sig_handler[SIGABRT], NULL); +void CRT_resetSignalHandlers(void) +{ + sigaction(SIGSEGV, &old_sig_handler[SIGSEGV], NULL); + sigaction(SIGFPE, &old_sig_handler[SIGFPE], NULL); + sigaction(SIGILL, &old_sig_handler[SIGILL], NULL); + sigaction(SIGBUS, &old_sig_handler[SIGBUS], NULL); + sigaction(SIGPIPE, &old_sig_handler[SIGPIPE], NULL); + sigaction(SIGSYS, &old_sig_handler[SIGSYS], NULL); + sigaction(SIGABRT, &old_sig_handler[SIGABRT], NULL); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); signal(SIGQUIT, SIG_DFL); } -void CRT_setMouse(bool enabled) { +void CRT_setMouse(bool enabled) +{ #ifdef HAVE_GETMOUSE - if (enabled) { + if (enabled) + { #if NCURSES_MOUSE_VERSION > 1 mousemask(BUTTON1_RELEASED | BUTTON4_PRESSED | BUTTON5_PRESSED, NULL); #else mousemask(BUTTON1_RELEASED, NULL); #endif - } else { + } + else + { mousemask(0, NULL); } #endif } -void CRT_init(const Settings* settings, bool allowUnicode) { +void CRT_init(const Settings *settings, bool allowUnicode) +{ redirectStderr(); initscr(); @@ -924,7 +956,8 @@ void CRT_init(const Settings* settings, bool allowUnicode) { CRT_colors = CRT_colorSchemes[settings->colorScheme]; CRT_colorScheme = settings->colorScheme; - for (int i = 0; i < LAST_COLORELEMENT; i++) { + for (int i = 0; i < LAST_COLORELEMENT; i++) + { unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i]; CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White, Black) : color; } @@ -938,21 +971,26 @@ void CRT_init(const Settings* settings, bool allowUnicode) { #endif curs_set(0); - if (has_colors()) { + if (has_colors()) + { start_color(); } - const char* termType = getenv("TERM"); - if (termType && String_eq(termType, "linux")) { + const char *termType = getenv("TERM"); + if (termType && String_eq(termType, "linux")) + { CRT_scrollHAmount = 20; - } else { + } + else + { CRT_scrollHAmount = 5; } - if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) { + if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) + { #ifdef HTOP_NETBSD -#define define_key(s_, k_) define_key((char*)s_, k_) -IGNORE_WCASTQUAL_BEGIN +#define define_key(s_, k_) define_key((char *)s_, k_) + IGNORE_WCASTQUAL_BEGIN #endif define_key("\033[H", KEY_HOME); define_key("\033[F", KEY_END); @@ -971,16 +1009,18 @@ IGNORE_WCASTQUAL_BEGIN define_key("\033[17;2~", KEY_F(18)); define_key("\033[Z", KEY_SHIFT_TAB); char sequence[3] = "\033a"; - for (char c = 'a'; c <= 'z'; c++) { + for (char c = 'a'; c <= 'z'; c++) + { sequence[1] = c; define_key(sequence, KEY_ALT('A' + (c - 'a'))); } #ifdef HTOP_NETBSD -IGNORE_WCASTQUAL_END + IGNORE_WCASTQUAL_END #undef define_key #endif } - if (termType && (String_startsWith(termType, "rxvt"))) { + if (termType && (String_startsWith(termType, "rxvt"))) + { define_key("\033[Z", KEY_SHIFT_TAB); } @@ -992,27 +1032,31 @@ IGNORE_WCASTQUAL_END CRT_setColors(CRT_colorScheme); #ifdef HAVE_LIBNCURSESW - if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) { + if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) + { CRT_utf8 = true; - } else { + } + else + { CRT_utf8 = false; } #else - (void) allowUnicode; + (void)allowUnicode; #endif CRT_treeStr = #ifdef HAVE_LIBNCURSESW - CRT_utf8 ? CRT_treeStrUtf8 : + CRT_utf8 ? CRT_treeStrUtf8 : #endif - CRT_treeStrAscii; + CRT_treeStrAscii; CRT_setMouse(settings->enableMouse); CRT_degreeSign = initDegreeSign(); } -void CRT_done() { +void CRT_done() +{ int resetColor = CRT_colors ? CRT_colors[RESET_COLOR] : CRT_colorSchemes[COLORSCHEME_DEFAULT][RESET_COLOR]; attron(resetColor); @@ -1026,14 +1070,16 @@ void CRT_done() { dumpStderr(); } -void CRT_fatalError(const char* note) { - const char* sysMsg = strerror(errno); +void CRT_fatalError(const char *note) +{ + const char *sysMsg = strerror(errno); CRT_done(); fprintf(stderr, "%s: %s\n", note, sysMsg); exit(2); } -int CRT_readKey() { +int CRT_readKey() +{ nocbreak(); cbreak(); nodelay(stdscr, FALSE); @@ -1042,25 +1088,31 @@ int CRT_readKey() { return ret; } -void CRT_disableDelay() { +void CRT_disableDelay() +{ nocbreak(); cbreak(); nodelay(stdscr, TRUE); } -void CRT_enableDelay() { +void CRT_enableDelay() +{ halfdelay(*CRT_delay); } -void CRT_setColors(int colorScheme) { +void CRT_setColors(int colorScheme) +{ CRT_colorScheme = colorScheme; - for (short int i = 0; i < 8; i++) { - for (short int j = 0; j < 8; j++) { - if (ColorIndex(i, j) != ColorIndexGrayBlack && ColorIndex(i, j) != ColorIndexWhiteDefault) { + for (short int i = 0; i < 8; i++) + { + for (short int j = 0; j < 8; j++) + { + if (ColorIndex(i, j) != ColorIndexGrayBlack && ColorIndex(i, j) != ColorIndexWhiteDefault) + { short int bg = (colorScheme != COLORSCHEME_BLACKNIGHT) - ? (j == 0 ? -1 : j) - : j; + ? (j == 0 ? -1 : j) + : j; init_pair(ColorIndex(i, j), i, bg); } } @@ -1076,7 +1128,8 @@ void CRT_setColors(int colorScheme) { } #ifdef PRINT_BACKTRACE -static void print_backtrace(void) { +static void print_backtrace(void) +{ #if defined(HAVE_LIBUNWIND_H) && defined(HAVE_LIBUNWIND) unw_context_t context; unw_getcontext(&context); @@ -1086,7 +1139,8 @@ static void print_backtrace(void) { unsigned int item = 0; - while (unw_step(&cursor) > 0) { + while (unw_step(&cursor) > 0) + { unw_word_t pc; unw_get_reg(&cursor, UNW_REG_IP, &pc); if (pc == 0) @@ -1099,26 +1153,27 @@ static void print_backtrace(void) { unw_proc_info_t pip; pip.unwind_info = NULL; - const char* fname = "?"; - const void* ptr = 0; - if (unw_get_proc_info(&cursor, &pip) == 0) { - ptr = (const void*)(pip.start_ip + offset); + const char *fname = "?"; + const void *ptr = 0; + if (unw_get_proc_info(&cursor, &pip) == 0) + { + ptr = (const void *)(pip.start_ip + offset); - #ifdef HAVE_DLADDR +#ifdef HAVE_DLADDR Dl_info dlinfo; if (dladdr(ptr, &dlinfo) && dlinfo.dli_fname && *dlinfo.dli_fname) fname = dlinfo.dli_fname; - #endif +#endif } - const char* frame = ""; + const char *frame = ""; if (unw_is_signal_frame(&cursor) > 0) frame = "{signal frame}"; fprintf(stderr, "%2u: %#14lx %s (%s+%#lx) [%p]%s%s\n", item++, pc, fname, symbolName, offset, ptr, frame ? " " : "", frame); } #elif defined(HAVE_EXECINFO_H) - void* backtraceArray[256]; + void *backtraceArray[256]; size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO); @@ -1128,87 +1183,82 @@ static void print_backtrace(void) { } #endif -void CRT_handleSIGSEGV(int signal) { +void CRT_handleSIGSEGV(int signal) +{ CRT_done(); fprintf(stderr, "\n\n" - "FATAL PROGRAM ERROR DETECTED\n" - "============================\n" - "Please check at https://htop.dev/issues whether this issue has already been reported.\n" - "If no similar issue has been reported before, please create a new issue with the following information:\n" - " - Your "PACKAGE" version: '"VERSION"'\n" - " - Your OS and kernel version (uname -a)\n" - " - Your distribution and release (lsb_release -a)\n" - " - Likely steps to reproduce (How did it happen?)\n" - ); + "FATAL PROGRAM ERROR DETECTED\n" + "============================\n" + "Please check at https://htop.dev/issues whether this issue has already been reported.\n" + "If no similar issue has been reported before, please create a new issue with the following information:\n" + " - Your " PACKAGE " version: '" VERSION "'\n" + " - Your OS and kernel version (uname -a)\n" + " - Your distribution and release (lsb_release -a)\n" + " - Likely steps to reproduce (How did it happen?)\n"); #ifdef PRINT_BACKTRACE fprintf(stderr, " - Backtrace of the issue (see below)\n"); #endif fprintf(stderr, - "\n" - ); + "\n"); - const char* signal_str = strsignal(signal); - if (!signal_str) { + const char *signal_str = strsignal(signal); + if (!signal_str) + { signal_str = "unknown reason"; } fprintf(stderr, - "Error information:\n" - "------------------\n" - "A signal %d (%s) was received.\n" - "\n", - signal, signal_str - ); + "Error information:\n" + "------------------\n" + "A signal %d (%s) was received.\n" + "\n", + signal, signal_str); fprintf(stderr, - "Setting information:\n" - "--------------------\n"); + "Setting information:\n" + "--------------------\n"); Settings_write(CRT_crashSettings, true); fprintf(stderr, "\n\n"); #ifdef PRINT_BACKTRACE fprintf(stderr, - "Backtrace information:\n" - "----------------------\n" - ); + "Backtrace information:\n" + "----------------------\n"); print_backtrace(); fprintf(stderr, - "\n" - "To make the above information more practical to work with, " - "please also provide a disassembly of your "PACKAGE" binary. " - "This can usually be done by running the following command:\n" - "\n" - ); + "\n" + "To make the above information more practical to work with, " + "please also provide a disassembly of your " PACKAGE " binary. " + "This can usually be done by running the following command:\n" + "\n"); #ifdef HTOP_DARWIN - fprintf(stderr, " otool -tvV `which "PACKAGE"` > ~/htop.otool\n"); + fprintf(stderr, " otool -tvV `which " PACKAGE "` > ~/htop.otool\n"); #else - fprintf(stderr, " objdump -d -S -w `which "PACKAGE"` > ~/htop.objdump\n"); + fprintf(stderr, " objdump -d -S -w `which " PACKAGE "` > ~/htop.objdump\n"); #endif fprintf(stderr, - "\n" - "Please include the generated file in your report.\n" - ); + "\n" + "Please include the generated file in your report.\n"); #endif fprintf(stderr, - "Running this program with debug symbols or inside a debugger may provide further insights.\n" - "\n" - "Thank you for helping to improve "PACKAGE"!\n" - "\n" - ); + "Running this program with debug symbols or inside a debugger may provide further insights.\n" + "\n" + "Thank you for helping to improve " PACKAGE "!\n" + "\n"); /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ - if (sigaction (signal, &old_sig_handler[signal], NULL) < 0) { + if (sigaction(signal, &old_sig_handler[signal], NULL) < 0) + { /* This avoids an infinite loop in case the handler could not be reset. */ fprintf(stderr, - "!!! Chained handler could not be restored. Forcing exit.\n" - ); + "!!! Chained handler could not be restored. Forcing exit.\n"); _exit(1); } @@ -1217,7 +1267,6 @@ void CRT_handleSIGSEGV(int signal) { // Always terminate, even if installed handler returns fprintf(stderr, - "!!! Chained handler did not exit. Forcing exit.\n" - ); + "!!! Chained handler did not exit. Forcing exit.\n"); _exit(1); } diff --git a/CRT.h b/CRT.h index 297e8964..1ad702c6 100644 --- a/CRT.h +++ b/CRT.h @@ -15,8 +15,8 @@ in the source distribution for its full text. #include "ProvideCurses.h" #include "Settings.h" - -typedef enum TreeStr_ { +typedef enum TreeStr_ +{ TREE_STR_VERT, TREE_STR_RTEE, TREE_STR_BEND, @@ -28,7 +28,8 @@ typedef enum TreeStr_ { LAST_TREE_STR } TreeStr; -typedef enum ColorScheme_ { +typedef enum ColorScheme_ +{ COLORSCHEME_DEFAULT, COLORSCHEME_MONOCHROME, COLORSCHEME_BLACKONWHITE, @@ -39,7 +40,8 @@ typedef enum ColorScheme_ { LAST_COLORSCHEME } ColorScheme; -typedef enum ColorElements_ { +typedef enum ColorElements_ +{ RESET_COLOR, DEFAULT_COLOR, FUNCTION_BAR, @@ -64,6 +66,8 @@ typedef enum ColorElements_ { METER_VALUE_WARN, LED_COLOR, UPTIME, + TEMP, + FREQ, BATTERY, TASKS_RUNNING, SWAP, @@ -148,24 +152,24 @@ typedef enum ColorElements_ { LAST_COLORELEMENT } ColorElements; -void CRT_fatalError(const char* note) ATTR_NORETURN; +void CRT_fatalError(const char *note) ATTR_NORETURN; #ifdef NDEBUG -# define CRT_debug(...) +#define CRT_debug(...) #else -void CRT_debug_impl(const char* file, size_t lineno, const char* func, const char* fmt, ...) ATTR_FORMAT(printf, 4, 5); -# define CRT_debug(...) CRT_debug_impl(__FILE__, __LINE__, __func__, __VA_ARGS__) +void CRT_debug_impl(const char *file, size_t lineno, const char *func, const char *fmt, ...) ATTR_FORMAT(printf, 4, 5); +#define CRT_debug(...) CRT_debug_impl(__FILE__, __LINE__, __func__, __VA_ARGS__) #endif void CRT_handleSIGSEGV(int signal) ATTR_NORETURN; -#define KEY_WHEELUP KEY_F(30) +#define KEY_WHEELUP KEY_F(30) #define KEY_WHEELDOWN KEY_F(31) -#define KEY_RECLICK KEY_F(32) +#define KEY_RECLICK KEY_F(32) #define KEY_SHIFT_TAB KEY_F(33) -#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A')) +#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A')) -extern const char* CRT_degreeSign; +extern const char *CRT_degreeSign; #ifdef HAVE_LIBNCURSESW @@ -173,9 +177,9 @@ extern bool CRT_utf8; #endif -extern const char* const* CRT_treeStr; +extern const char *const *CRT_treeStr; -extern const int* CRT_colors; +extern const int *CRT_colors; extern int CRT_cursorX; @@ -187,7 +191,7 @@ extern ColorScheme CRT_colorScheme; void CRT_setMouse(bool enabled); -void CRT_init(const Settings* settings, bool allowUnicode); +void CRT_init(const Settings *settings, bool allowUnicode); void CRT_done(void); diff --git a/FreqMeter.c b/FreqMeter.c new file mode 100644 index 00000000..ea262e69 --- /dev/null +++ b/FreqMeter.c @@ -0,0 +1,29 @@ +#include "FreqMeter.h" + +#include "CRT.h" +#include "Object.h" +#include "Platform.h" +#include "XUtils.h" + +static const int FreqMeter_attributes[] = { + FREQ}; + +static void FreqMeter_updateValues(Meter *this) +{ + float freq = Platform_getFreq(); + + xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1lf GHz", freq); +} + +const MeterClass FreqMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete}, + .updateValues = FreqMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 100.0, + .attributes = FreqMeter_attributes, + .name = "Freq", + .uiName = "Freq", + .caption = "CPU/Frequency: "}; diff --git a/FreqMeter.h b/FreqMeter.h new file mode 100644 index 00000000..2f58ffa7 --- /dev/null +++ b/FreqMeter.h @@ -0,0 +1,8 @@ +#ifndef HEADER_FreqMeter +#define HEADER_FreqMeter + +#include "Meter.h" + +extern const MeterClass FreqMeter_class; + +#endif diff --git a/Makefile.am b/Makefile.am index 8af1864a..ad075cc6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,6 +82,8 @@ myhtopsources = \ TasksMeter.c \ TraceScreen.c \ UptimeMeter.c \ + FreqMeter.c \ + TempMeter.c \ UsersTable.c \ Vector.c \ XUtils.c @@ -144,6 +146,8 @@ myhtopheaders = \ TasksMeter.h \ TraceScreen.h \ UptimeMeter.h \ + FreqMeter.h \ + TempMeter.h \ UsersTable.h \ Vector.h \ XUtils.h diff --git a/Settings.c b/Settings.c index 7d6fca47..4fda53cb 100644 --- a/Settings.c +++ b/Settings.c @@ -23,6 +23,8 @@ in the source distribution for its full text. #include "Platform.h" #include "XUtils.h" +#define FORCE_TEMP_METER +#define FORCE_FREQ_METER /* @@ -66,15 +68,19 @@ static void writeQuotedList(FILE* fd, char** list) { */ -void Settings_delete(Settings* this) { +void Settings_delete(Settings *this) +{ free(this->filename); - for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) { + for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) + { String_freeArray(this->hColumns[i].names); free(this->hColumns[i].modes); } free(this->hColumns); - if (this->screens) { - for (unsigned int i = 0; this->screens[i]; i++) { + if (this->screens) + { + for (unsigned int i = 0; this->screens[i]; i++) + { ScreenSettings_delete(this->screens[i]); } free(this->screens); @@ -82,40 +88,46 @@ void Settings_delete(Settings* this) { free(this); } -static void Settings_readMeters(Settings* this, const char* line, unsigned int column) { - char* trim = String_trim(line); - char** ids = String_split(trim, ' ', NULL); +static void Settings_readMeters(Settings *this, const char *line, unsigned int column) +{ + char *trim = String_trim(line); + char **ids = String_split(trim, ' ', NULL); free(trim); column = MINIMUM(column, HeaderLayout_getColumns(this->hLayout) - 1); this->hColumns[column].names = ids; } -static void Settings_readMeterModes(Settings* this, const char* line, unsigned int column) { - char* trim = String_trim(line); - char** ids = String_split(trim, ' ', NULL); +static void Settings_readMeterModes(Settings *this, const char *line, unsigned int column) +{ + char *trim = String_trim(line); + char **ids = String_split(trim, ' ', NULL); free(trim); int len = 0; - for (int i = 0; ids[i]; i++) { + for (int i = 0; ids[i]; i++) + { len++; } column = MINIMUM(column, HeaderLayout_getColumns(this->hLayout) - 1); this->hColumns[column].len = len; - int* modes = len ? xCalloc(len, sizeof(int)) : NULL; - for (int i = 0; i < len; i++) { + int *modes = len ? xCalloc(len, sizeof(int)) : NULL; + for (int i = 0; i < len; i++) + { modes[i] = atoi(ids[i]); } String_freeArray(ids); this->hColumns[column].modes = modes; } -static bool Settings_validateMeters(Settings* this) { +static bool Settings_validateMeters(Settings *this) +{ const size_t colCount = HeaderLayout_getColumns(this->hLayout); bool anyMeter = false; - for (size_t column = 0; column < colCount; column++) { - char** names = this->hColumns[column].names; - const int* modes = this->hColumns[column].modes; + for (size_t column = 0; column < colCount; column++) + { + char **names = this->hColumns[column].names; + const int *modes = this->hColumns[column].modes; const size_t len = this->hColumns[column].len; if (!len) @@ -138,15 +150,18 @@ static bool Settings_validateMeters(Settings* this) { return anyMeter; } -static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) { - int sizes[] = { 3, 3 }; +static void Settings_defaultMeters(Settings *this, unsigned int initialCpuCount) +{ + int sizes[] = {3, 5}; - if (initialCpuCount > 4 && initialCpuCount <= 128) { + if (initialCpuCount > 4 && initialCpuCount <= 128) + { sizes[1]++; } // Release any previously allocated memory - for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) { + for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) + { String_freeArray(this->hColumns[i].names); free(this->hColumns[i].modes); } @@ -154,39 +169,51 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) this->hLayout = HF_TWO_50_50; this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting)); - for (size_t i = 0; i < 2; i++) { - this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char*)); + for (size_t i = 0; i < 2; i++) + { + this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char *)); this->hColumns[i].modes = xCalloc(sizes[i], sizeof(int)); this->hColumns[i].len = sizes[i]; } int r = 0; - if (initialCpuCount > 128) { + if (initialCpuCount > 128) + { // Just show the average, ricers need to config for impressive screenshots this->hColumns[0].names[0] = xStrdup("CPU"); this->hColumns[0].modes[0] = BAR_METERMODE; - } else if (initialCpuCount > 32) { + } + else if (initialCpuCount > 32) + { this->hColumns[0].names[0] = xStrdup("LeftCPUs8"); this->hColumns[0].modes[0] = BAR_METERMODE; this->hColumns[1].names[r] = xStrdup("RightCPUs8"); this->hColumns[1].modes[r++] = BAR_METERMODE; - } else if (initialCpuCount > 16) { + } + else if (initialCpuCount > 16) + { this->hColumns[0].names[0] = xStrdup("LeftCPUs4"); this->hColumns[0].modes[0] = BAR_METERMODE; this->hColumns[1].names[r] = xStrdup("RightCPUs4"); this->hColumns[1].modes[r++] = BAR_METERMODE; - } else if (initialCpuCount > 8) { + } + else if (initialCpuCount > 8) + { this->hColumns[0].names[0] = xStrdup("LeftCPUs2"); this->hColumns[0].modes[0] = BAR_METERMODE; this->hColumns[1].names[r] = xStrdup("RightCPUs2"); this->hColumns[1].modes[r++] = BAR_METERMODE; - } else if (initialCpuCount > 4) { + } + else if (initialCpuCount > 4) + { this->hColumns[0].names[0] = xStrdup("LeftCPUs"); this->hColumns[0].modes[0] = BAR_METERMODE; this->hColumns[1].names[r] = xStrdup("RightCPUs"); this->hColumns[1].modes[r++] = BAR_METERMODE; - } else { + } + else + { this->hColumns[0].names[0] = xStrdup("AllCPUs"); this->hColumns[0].modes[0] = BAR_METERMODE; } @@ -200,31 +227,44 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount) this->hColumns[1].modes[r++] = TEXT_METERMODE; this->hColumns[1].names[r] = xStrdup("Uptime"); this->hColumns[1].modes[r++] = TEXT_METERMODE; + this->hColumns[1].names[r] = xStrdup("Temp"); + this->hColumns[1].modes[r++] = TEXT_METERMODE; + this->hColumns[1].names[r] = xStrdup("Freq"); + this->hColumns[1].modes[r++] = TEXT_METERMODE; } -static const char* toFieldName(Hashtable* columns, int id) { +static const char *toFieldName(Hashtable *columns, int id) +{ if (id < 0) return NULL; - if (id >= LAST_PROCESSFIELD) { - const DynamicColumn* column = DynamicColumn_lookup(columns, id); + if (id >= LAST_PROCESSFIELD) + { + const DynamicColumn *column = DynamicColumn_lookup(columns, id); return column->name; } return Process_fields[id].name; } -static int toFieldIndex(Hashtable* columns, const char* str) { - if (isdigit(str[0])) { +static int toFieldIndex(Hashtable *columns, const char *str) +{ + if (isdigit(str[0])) + { // This "+1" is for compatibility with the older enum format. int id = atoi(str) + 1; - if (toFieldName(columns, id)) { + if (toFieldName(columns, id)) + { return id; } - } else { + } + else + { // Dynamically-defined columns are always stored by-name. char dynamic[32] = {0}; - if (sscanf(str, "Dynamic(%30s)", dynamic)) { - char* end; - if ((end = strrchr(dynamic, ')')) != NULL) { + if (sscanf(str, "Dynamic(%30s)", dynamic)) + { + char *end; + if ((end = strrchr(dynamic, ')')) != NULL) + { bool success; unsigned int key; *end = '\0'; @@ -235,8 +275,9 @@ static int toFieldIndex(Hashtable* columns, const char* str) { } } // Fallback to iterative scan of table of fields by-name. - for (int p = 1; p < LAST_PROCESSFIELD; p++) { - const char* pName = toFieldName(columns, p); + for (int p = 1; p < LAST_PROCESSFIELD; p++) + { + const char *pName = toFieldName(columns, p); if (pName && strcmp(pName, str) == 0) return p; } @@ -244,18 +285,21 @@ static int toFieldIndex(Hashtable* columns, const char* str) { return -1; } -static void ScreenSettings_readFields(ScreenSettings* ss, Hashtable* columns, const char* line) { - char* trim = String_trim(line); - char** ids = String_split(trim, ' ', NULL); +static void ScreenSettings_readFields(ScreenSettings *ss, Hashtable *columns, const char *line) +{ + char *trim = String_trim(line); + char **ids = String_split(trim, ' ', NULL); free(trim); /* reset default fields */ memset(ss->fields, '\0', LAST_PROCESSFIELD * sizeof(ProcessField)); - for (size_t j = 0, i = 0; ids[i]; i++) { + for (size_t j = 0, i = 0; ids[i]; i++) + { if (j >= UINT_MAX / sizeof(ProcessField)) continue; - if (j >= LAST_PROCESSFIELD) { + if (j >= LAST_PROCESSFIELD) + { ss->fields = xRealloc(ss->fields, (j + 1) * sizeof(ProcessField)); memset(&ss->fields[j], 0, sizeof(ProcessField)); } @@ -269,72 +313,82 @@ static void ScreenSettings_readFields(ScreenSettings* ss, Hashtable* columns, co String_freeArray(ids); } -ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults) { +ScreenSettings *Settings_newScreen(Settings *this, const ScreenDefaults *defaults) +{ int sortKey = defaults->sortKey ? toFieldIndex(this->dynamicColumns, defaults->sortKey) : PID; int sortDesc = (sortKey >= 0 && sortKey < LAST_PROCESSFIELD) ? Process_fields[sortKey].defaultSortDesc : 1; - ScreenSettings* ss = xMalloc(sizeof(ScreenSettings)); - *ss = (ScreenSettings) { - .name = xStrdup(defaults->name), - .fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)), - .flags = 0, - .direction = sortDesc ? -1 : 1, - .treeDirection = 1, - .sortKey = sortKey, - .treeSortKey = PID, - .treeView = false, - .treeViewAlwaysByPID = false, - .allBranchesCollapsed = false, + ScreenSettings *ss = xMalloc(sizeof(ScreenSettings)); + *ss = (ScreenSettings){ + .name = xStrdup(defaults->name), + .fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)), + .flags = 0, + .direction = sortDesc ? -1 : 1, + .treeDirection = 1, + .sortKey = sortKey, + .treeSortKey = PID, + .treeView = false, + .treeViewAlwaysByPID = false, + .allBranchesCollapsed = false, }; ScreenSettings_readFields(ss, this->dynamicColumns, defaults->columns); this->screens[this->nScreens] = ss; this->nScreens++; - this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1)); + this->screens = xRealloc(this->screens, sizeof(ScreenSettings *) * (this->nScreens + 1)); this->screens[this->nScreens] = NULL; return ss; } -void ScreenSettings_delete(ScreenSettings* this) { +void ScreenSettings_delete(ScreenSettings *this) +{ free(this->name); free(this->fields); free(this); } -static ScreenSettings* Settings_defaultScreens(Settings* this) { +static ScreenSettings *Settings_defaultScreens(Settings *this) +{ if (this->nScreens) return this->screens[0]; - for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) { - const ScreenDefaults* defaults = &Platform_defaultScreens[i]; + for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++) + { + const ScreenDefaults *defaults = &Platform_defaultScreens[i]; Settings_newScreen(this, defaults); } return this->screens[0]; } -static bool Settings_read(Settings* this, const char* fileName, unsigned int initialCpuCount) { - FILE* fd = fopen(fileName, "r"); +static bool Settings_read(Settings *this, const char *fileName, unsigned int initialCpuCount) +{ + FILE *fd = fopen(fileName, "r"); if (!fd) return false; - ScreenSettings* screen = NULL; + ScreenSettings *screen = NULL; bool didReadMeters = false; bool didReadAny = false; - for (;;) { - char* line = String_readLine(fd); - if (!line) { + for (;;) + { + char *line = String_readLine(fd); + if (!line) + { break; } didReadAny = true; size_t nOptions; - char** option = String_split(line, '=', &nOptions); - free (line); - if (nOptions < 2) { + char **option = String_split(line, '=', &nOptions); + free(line); + if (nOptions < 2) + { String_freeArray(option); continue; } - if (String_eq(option[0], "config_reader_min_version")) { + if (String_eq(option[0], "config_reader_min_version")) + { this->config_version = atoi(option[1]); - if (this->config_version > CONFIG_READER_MIN_VERSION) { + if (this->config_version > CONFIG_READER_MIN_VERSION) + { // the version of the config file on disk is newer than what we can read fprintf(stderr, "WARNING: %s specifies configuration format\n", fileName); fprintf(stderr, " version v%d, but this %s binary only supports up to version v%d.\n", this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION); @@ -343,236 +397,433 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini fclose(fd); return false; } - } else if (String_eq(option[0], "fields") && this->config_version <= 2) { + } + else if (String_eq(option[0], "fields") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); ScreenSettings_readFields(screen, this->dynamicColumns, option[1]); - } else if (String_eq(option[0], "sort_key") && this->config_version <= 2) { + } + else if (String_eq(option[0], "sort_key") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility // This "+1" is for compatibility with the older enum format. screen = Settings_defaultScreens(this); screen->sortKey = atoi(option[1]) + 1; - } else if (String_eq(option[0], "tree_sort_key") && this->config_version <= 2) { + } + else if (String_eq(option[0], "tree_sort_key") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility // This "+1" is for compatibility with the older enum format. screen = Settings_defaultScreens(this); screen->treeSortKey = atoi(option[1]) + 1; - } else if (String_eq(option[0], "sort_direction") && this->config_version <= 2) { + } + else if (String_eq(option[0], "sort_direction") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); screen->direction = atoi(option[1]); - } else if (String_eq(option[0], "tree_sort_direction") && this->config_version <= 2) { + } + else if (String_eq(option[0], "tree_sort_direction") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); screen->treeDirection = atoi(option[1]); - } else if (String_eq(option[0], "tree_view") && this->config_version <= 2) { + } + else if (String_eq(option[0], "tree_view") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); screen->treeView = atoi(option[1]); - } else if (String_eq(option[0], "tree_view_always_by_pid") && this->config_version <= 2) { + } + else if (String_eq(option[0], "tree_view_always_by_pid") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); screen->treeViewAlwaysByPID = atoi(option[1]); - } else if (String_eq(option[0], "all_branches_collapsed") && this->config_version <= 2) { + } + else if (String_eq(option[0], "all_branches_collapsed") && this->config_version <= 2) + { // old (no screen) naming also supported for backwards compatibility screen = Settings_defaultScreens(this); screen->allBranchesCollapsed = atoi(option[1]); - } else if (String_eq(option[0], "hide_kernel_threads")) { + } + else if (String_eq(option[0], "hide_kernel_threads")) + { this->hideKernelThreads = atoi(option[1]); - } else if (String_eq(option[0], "hide_userland_threads")) { + } + else if (String_eq(option[0], "hide_userland_threads")) + { this->hideUserlandThreads = atoi(option[1]); - } else if (String_eq(option[0], "shadow_other_users")) { + } + else if (String_eq(option[0], "shadow_other_users")) + { this->shadowOtherUsers = atoi(option[1]); - } else if (String_eq(option[0], "show_thread_names")) { + } + else if (String_eq(option[0], "show_thread_names")) + { this->showThreadNames = atoi(option[1]); - } else if (String_eq(option[0], "show_program_path")) { + } + else if (String_eq(option[0], "show_program_path")) + { this->showProgramPath = atoi(option[1]); - } else if (String_eq(option[0], "highlight_base_name")) { + } + else if (String_eq(option[0], "highlight_base_name")) + { this->highlightBaseName = atoi(option[1]); - } else if (String_eq(option[0], "highlight_deleted_exe")) { + } + else if (String_eq(option[0], "highlight_deleted_exe")) + { this->highlightDeletedExe = atoi(option[1]); - } else if (String_eq(option[0], "highlight_megabytes")) { + } + else if (String_eq(option[0], "highlight_megabytes")) + { this->highlightMegabytes = atoi(option[1]); - } else if (String_eq(option[0], "highlight_threads")) { + } + else if (String_eq(option[0], "highlight_threads")) + { this->highlightThreads = atoi(option[1]); - } else if (String_eq(option[0], "highlight_changes")) { + } + else if (String_eq(option[0], "highlight_changes")) + { this->highlightChanges = atoi(option[1]); - } else if (String_eq(option[0], "highlight_changes_delay_secs")) { + } + else if (String_eq(option[0], "highlight_changes_delay_secs")) + { this->highlightDelaySecs = CLAMP(atoi(option[1]), 1, 24 * 60 * 60); - } else if (String_eq(option[0], "find_comm_in_cmdline")) { + } + else if (String_eq(option[0], "find_comm_in_cmdline")) + { this->findCommInCmdline = atoi(option[1]); - } else if (String_eq(option[0], "strip_exe_from_cmdline")) { + } + else if (String_eq(option[0], "strip_exe_from_cmdline")) + { this->stripExeFromCmdline = atoi(option[1]); - } else if (String_eq(option[0], "show_merged_command")) { + } + else if (String_eq(option[0], "show_merged_command")) + { this->showMergedCommand = atoi(option[1]); - } else if (String_eq(option[0], "header_margin")) { + } + else if (String_eq(option[0], "header_margin")) + { this->headerMargin = atoi(option[1]); - } else if (String_eq(option[0], "screen_tabs")) { + } + else if (String_eq(option[0], "screen_tabs")) + { this->screenTabs = atoi(option[1]); - } else if (String_eq(option[0], "expand_system_time")) { + } + else if (String_eq(option[0], "expand_system_time")) + { // Compatibility option. this->detailedCPUTime = atoi(option[1]); - } else if (String_eq(option[0], "detailed_cpu_time")) { + } + else if (String_eq(option[0], "detailed_cpu_time")) + { this->detailedCPUTime = atoi(option[1]); - } else if (String_eq(option[0], "cpu_count_from_one")) { + } + else if (String_eq(option[0], "cpu_count_from_one")) + { this->countCPUsFromOne = atoi(option[1]); - } else if (String_eq(option[0], "cpu_count_from_zero")) { + } + else if (String_eq(option[0], "cpu_count_from_zero")) + { // old (inverted) naming also supported for backwards compatibility this->countCPUsFromOne = !atoi(option[1]); - } else if (String_eq(option[0], "show_cpu_usage")) { + } + else if (String_eq(option[0], "show_cpu_usage")) + { this->showCPUUsage = atoi(option[1]); - } else if (String_eq(option[0], "show_cpu_frequency")) { + } + else if (String_eq(option[0], "show_cpu_frequency")) + { this->showCPUFrequency = atoi(option[1]); - #ifdef BUILD_WITH_CPU_TEMP - } else if (String_eq(option[0], "show_cpu_temperature")) { +#ifdef BUILD_WITH_CPU_TEMP + } + else if (String_eq(option[0], "show_cpu_temperature")) + { this->showCPUTemperature = atoi(option[1]); - } else if (String_eq(option[0], "degree_fahrenheit")) { + } + else if (String_eq(option[0], "degree_fahrenheit")) + { this->degreeFahrenheit = atoi(option[1]); - #endif - } else if (String_eq(option[0], "update_process_names")) { +#endif + } + else if (String_eq(option[0], "update_process_names")) + { this->updateProcessNames = atoi(option[1]); - } else if (String_eq(option[0], "account_guest_in_cpu_meter")) { + } + else if (String_eq(option[0], "account_guest_in_cpu_meter")) + { this->accountGuestInCPUMeter = atoi(option[1]); - } else if (String_eq(option[0], "delay")) { + } + else if (String_eq(option[0], "delay")) + { this->delay = CLAMP(atoi(option[1]), 1, 255); - } else if (String_eq(option[0], "color_scheme")) { + } + else if (String_eq(option[0], "color_scheme")) + { this->colorScheme = atoi(option[1]); - if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) { + if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) + { this->colorScheme = 0; } - #ifdef HAVE_GETMOUSE - } else if (String_eq(option[0], "enable_mouse")) { +#ifdef HAVE_GETMOUSE + } + else if (String_eq(option[0], "enable_mouse")) + { this->enableMouse = atoi(option[1]); - #endif - } else if (String_eq(option[0], "header_layout")) { - this->hLayout = isdigit((unsigned char)option[1][0]) ? ((HeaderLayout) atoi(option[1])) : HeaderLayout_fromName(option[1]); +#endif + } + else if (String_eq(option[0], "header_layout")) + { + this->hLayout = isdigit((unsigned char)option[1][0]) ? ((HeaderLayout)atoi(option[1])) : HeaderLayout_fromName(option[1]); if (this->hLayout < 0 || this->hLayout >= LAST_HEADER_LAYOUT) this->hLayout = HF_TWO_50_50; free(this->hColumns); this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting)); - } else if (String_eq(option[0], "left_meters")) { + } + else if (String_eq(option[0], "left_meters")) + { Settings_readMeters(this, option[1], 0); didReadMeters = true; - } else if (String_eq(option[0], "right_meters")) { + } + else if (String_eq(option[0], "right_meters")) + { Settings_readMeters(this, option[1], 1); didReadMeters = true; - } else if (String_eq(option[0], "left_meter_modes")) { + } + else if (String_eq(option[0], "left_meter_modes")) + { Settings_readMeterModes(this, option[1], 0); didReadMeters = true; - } else if (String_eq(option[0], "right_meter_modes")) { + } + else if (String_eq(option[0], "right_meter_modes")) + { Settings_readMeterModes(this, option[1], 1); didReadMeters = true; - } else if (String_startsWith(option[0], "column_meters_")) { + } + else if (String_startsWith(option[0], "column_meters_")) + { Settings_readMeters(this, option[1], atoi(option[0] + strlen("column_meters_"))); didReadMeters = true; - } else if (String_startsWith(option[0], "column_meter_modes_")) { + } + else if (String_startsWith(option[0], "column_meter_modes_")) + { Settings_readMeterModes(this, option[1], atoi(option[0] + strlen("column_meter_modes_"))); didReadMeters = true; - } else if (String_eq(option[0], "hide_function_bar")) { + } + else if (String_eq(option[0], "hide_function_bar")) + { this->hideFunctionBar = atoi(option[1]); - #ifdef HAVE_LIBHWLOC - } else if (String_eq(option[0], "topology_affinity")) { +#ifdef HAVE_LIBHWLOC + } + else if (String_eq(option[0], "topology_affinity")) + { this->topologyAffinity = !!atoi(option[1]); - #endif - } else if (strncmp(option[0], "screen:", 7) == 0) { - screen = Settings_newScreen(this, &(const ScreenDefaults){ .name = option[0] + 7, .columns = option[1] }); - } else if (String_eq(option[0], ".sort_key")) { +#endif + } + else if (strncmp(option[0], "screen:", 7) == 0) + { + screen = Settings_newScreen(this, &(const ScreenDefaults){.name = option[0] + 7, .columns = option[1]}); + } + else if (String_eq(option[0], ".sort_key")) + { if (screen) screen->sortKey = toFieldIndex(this->dynamicColumns, option[1]); - } else if (String_eq(option[0], ".tree_sort_key")) { + } + else if (String_eq(option[0], ".tree_sort_key")) + { if (screen) screen->treeSortKey = toFieldIndex(this->dynamicColumns, option[1]); - } else if (String_eq(option[0], ".sort_direction")) { + } + else if (String_eq(option[0], ".sort_direction")) + { if (screen) screen->direction = atoi(option[1]); - } else if (String_eq(option[0], ".tree_sort_direction")) { + } + else if (String_eq(option[0], ".tree_sort_direction")) + { if (screen) screen->treeDirection = atoi(option[1]); - } else if (String_eq(option[0], ".tree_view")) { + } + else if (String_eq(option[0], ".tree_view")) + { if (screen) screen->treeView = atoi(option[1]); - } else if (String_eq(option[0], ".tree_view_always_by_pid")) { + } + else if (String_eq(option[0], ".tree_view_always_by_pid")) + { if (screen) screen->treeViewAlwaysByPID = atoi(option[1]); - } else if (String_eq(option[0], ".all_branches_collapsed")) { + } + else if (String_eq(option[0], ".all_branches_collapsed")) + { if (screen) screen->allBranchesCollapsed = atoi(option[1]); } String_freeArray(option); } fclose(fd); - if (!didReadMeters || !Settings_validateMeters(this)) - Settings_defaultMeters(this, initialCpuCount); - if (!this->nScreens) - Settings_defaultScreens(this); - return didReadAny; + + if (didReadMeters) + { + if (didReadMeters) + { +#if defined FORCE_TEMP_METER || defined FORCE_FREQ_METER + int ftidx = this->hColumns[1].len; + size_t realloc_len = ftidx; +#ifdef FORCE_TEMP_METER + uint8_t t_det = 0; +#endif +#ifdef FORCE_FREQ_METER + uint8_t f_det = 0; +#endif + char **cnames = this->hColumns[1].names; + for (int i = 0; i < ftidx; ++i) + { +#ifdef FORCE_TEMP_METER + if (strcmp("Temp", cnames[i]) == 0) + { + t_det = 1; + break; + } +#endif +#ifdef FORCE_FREQ_METER + if (strcmp("Freq", cnames[i]) == 0) + { + f_det = 1; + break; + } +#endif + } +#ifdef FORCE_TEMP_METER + if (!t_det) + { + ++realloc_len; + } +#endif +#ifdef FORCE_FREQ_METER + if (!f_det) + { + ++realloc_len; + } +#endif + this->hColumns[1].names = xReallocArray(this->hColumns[1].names, realloc_len + 1, sizeof(char *)); + this->hColumns[1].modes = xReallocArray(this->hColumns[1].modes, realloc_len, sizeof(int)); + +#ifdef FORCE_TEMP_METER + if (!t_det) + { + this->hColumns[1].names[ftidx] = xStrdup("Temp"); + this->hColumns[1].modes[ftidx++] = TEXT_METERMODE; + } +#endif +#ifdef FORCE_FREQ_METER + if (!f_det) + { + this->hColumns[1].names[ftidx] = xStrdup("Freq"); + this->hColumns[1].modes[ftidx++] = TEXT_METERMODE; + } +#endif + + this->hColumns[1].len = ftidx; +#endif + } + else + { + Settings_defaultMeters(this, initialCpuCount); + } + + if (!this->nScreens) + Settings_defaultScreens(this); + + return didReadAny; + } } -static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns, bool byName, char separator) { - const char* sep = ""; - for (unsigned int i = 0; fields[i]; i++) { - if (fields[i] < LAST_PROCESSFIELD && byName) { - const char* pName = toFieldName(columns, fields[i]); +static void writeFields(FILE *fd, const ProcessField *fields, Hashtable *columns, bool byName, char separator) +{ + const char *sep = ""; + for (unsigned int i = 0; fields[i]; i++) + { + if (fields[i] < LAST_PROCESSFIELD && byName) + { + const char *pName = toFieldName(columns, fields[i]); fprintf(fd, "%s%s", sep, pName); - } else if (fields[i] >= LAST_PROCESSFIELD && byName) { - const char* pName = toFieldName(columns, fields[i]); + } + else if (fields[i] >= LAST_PROCESSFIELD && byName) + { + const char *pName = toFieldName(columns, fields[i]); fprintf(fd, " Dynamic(%s)", pName); - } else { + } + else + { // This "-1" is for compatibility with the older enum format. - fprintf(fd, "%s%d", sep, (int) fields[i] - 1); + fprintf(fd, "%s%d", sep, (int)fields[i] - 1); } sep = " "; } fputc(separator, fd); } -static void writeList(FILE* fd, char** list, int len, char separator) { - const char* sep = ""; - for (int i = 0; i < len; i++) { +static void writeList(FILE *fd, char **list, int len, char separator) +{ + const char *sep = ""; + for (int i = 0; i < len; i++) + { fprintf(fd, "%s%s", sep, list[i]); sep = " "; } fputc(separator, fd); } -static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) { +static void writeMeters(const Settings *this, FILE *fd, char separator, unsigned int column) +{ writeList(fd, this->hColumns[column].names, this->hColumns[column].len, separator); } -static void writeMeterModes(const Settings* this, FILE* fd, char separator, unsigned int column) { - const char* sep = ""; - for (size_t i = 0; i < this->hColumns[column].len; i++) { +static void writeMeterModes(const Settings *this, FILE *fd, char separator, unsigned int column) +{ + const char *sep = ""; + for (size_t i = 0; i < this->hColumns[column].len; i++) + { fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]); sep = " "; } fputc(separator, fd); } -int Settings_write(const Settings* this, bool onCrash) { - FILE* fd; +int Settings_write(const Settings *this, bool onCrash) +{ + FILE *fd; char separator; - if (onCrash) { + if (onCrash) + { fd = stderr; separator = ';'; - } else { + } + else + { fd = fopen(this->filename, "w"); if (fd == NULL) return -errno; separator = '\n'; } - #define printSettingInteger(setting_, value_) \ - fprintf(fd, setting_ "=%d%c", (int) (value_), separator) - #define printSettingString(setting_, value_) \ - fprintf(fd, setting_ "=%s%c", value_, separator) +#define printSettingInteger(setting_, value_) \ + fprintf(fd, setting_ "=%d%c", (int)(value_), separator) +#define printSettingString(setting_, value_) \ + fprintf(fd, setting_ "=%s%c", value_, separator) - if (!onCrash) { + if (!onCrash) + { fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n"); fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n"); } printSettingString("htop_version", VERSION); printSettingInteger("config_reader_min_version", CONFIG_READER_MIN_VERSION); - fprintf(fd, "fields="); writeFields(fd, this->screens[0]->fields, this->dynamicColumns, false, separator); + fprintf(fd, "fields="); + writeFields(fd, this->screens[0]->fields, this->dynamicColumns, false, separator); printSettingInteger("hide_kernel_threads", this->hideKernelThreads); printSettingInteger("hide_userland_threads", this->hideUserlandThreads); printSettingInteger("shadow_other_users", this->shadowOtherUsers); @@ -593,24 +844,25 @@ int Settings_write(const Settings* this, bool onCrash) { printSettingInteger("cpu_count_from_one", this->countCPUsFromOne); printSettingInteger("show_cpu_usage", this->showCPUUsage); printSettingInteger("show_cpu_frequency", this->showCPUFrequency); - #ifdef BUILD_WITH_CPU_TEMP +#ifdef BUILD_WITH_CPU_TEMP printSettingInteger("show_cpu_temperature", this->showCPUTemperature); printSettingInteger("degree_fahrenheit", this->degreeFahrenheit); - #endif +#endif printSettingInteger("update_process_names", this->updateProcessNames); printSettingInteger("account_guest_in_cpu_meter", this->accountGuestInCPUMeter); printSettingInteger("color_scheme", this->colorScheme); - #ifdef HAVE_GETMOUSE +#ifdef HAVE_GETMOUSE printSettingInteger("enable_mouse", this->enableMouse); - #endif - printSettingInteger("delay", (int) this->delay); - printSettingInteger("hide_function_bar", (int) this->hideFunctionBar); - #ifdef HAVE_LIBHWLOC +#endif + printSettingInteger("delay", (int)this->delay); + printSettingInteger("hide_function_bar", (int)this->hideFunctionBar); +#ifdef HAVE_LIBHWLOC printSettingInteger("topology_affinity", this->topologyAffinity); - #endif +#endif printSettingString("header_layout", HeaderLayout_getName(this->hLayout)); - for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) { + for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) + { fprintf(fd, "column_meters_%u=", i); writeMeters(this, fd, separator, i); fprintf(fd, "column_meter_modes_%u=", i); @@ -627,8 +879,9 @@ int Settings_write(const Settings* this, bool onCrash) { printSettingInteger("tree_view_always_by_pid", this->screens[0]->treeViewAlwaysByPID); printSettingInteger("all_branches_collapsed", this->screens[0]->allBranchesCollapsed); - for (unsigned int i = 0; i < this->nScreens; i++) { - ScreenSettings* ss = this->screens[i]; + for (unsigned int i = 0; i < this->nScreens; i++) + { + ScreenSettings *ss = this->screens[i]; fprintf(fd, "screen:%s=", ss->name); writeFields(fd, ss->fields, this->dynamicColumns, true, separator); printSettingString(".sort_key", toFieldName(this->dynamicColumns, ss->sortKey)); @@ -640,8 +893,8 @@ int Settings_write(const Settings* this, bool onCrash) { printSettingInteger(".all_branches_collapsed", ss->allBranchesCollapsed); } - #undef printSettingString - #undef printSettingInteger +#undef printSettingString +#undef printSettingInteger if (onCrash) return 0; @@ -657,8 +910,9 @@ int Settings_write(const Settings* this, bool onCrash) { return r; } -Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) { - Settings* this = xCalloc(1, sizeof(Settings)); +Settings *Settings_new(unsigned int initialCpuCount, Hashtable *dynamicColumns) +{ + Settings *this = xCalloc(1, sizeof(Settings)); this->dynamicColumns = dynamicColumns; this->hLayout = HF_TWO_50_50; @@ -675,10 +929,10 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) this->countCPUsFromOne = false; this->showCPUUsage = true; this->showCPUFrequency = false; - #ifdef BUILD_WITH_CPU_TEMP +#ifdef BUILD_WITH_CPU_TEMP this->showCPUTemperature = false; this->degreeFahrenheit = false; - #endif +#endif this->updateProcessNames = false; this->showProgramPath = true; this->highlightThreads = true; @@ -689,42 +943,49 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) this->showMergedCommand = false; this->hideFunctionBar = 0; this->headerMargin = true; - #ifdef HAVE_LIBHWLOC +#ifdef HAVE_LIBHWLOC this->topologyAffinity = false; - #endif +#endif - this->screens = xCalloc(Platform_numberOfDefaultScreens * sizeof(ScreenSettings*), 1); + this->screens = xCalloc(Platform_numberOfDefaultScreens * sizeof(ScreenSettings *), 1); this->nScreens = 0; - char* legacyDotfile = NULL; - const char* rcfile = getenv("HTOPRC"); - if (rcfile) { + char *legacyDotfile = NULL; + const char *rcfile = getenv("HTOPRC"); + if (rcfile) + { this->filename = xStrdup(rcfile); - } else { - const char* home = getenv("HOME"); + } + else + { + const char *home = getenv("HOME"); if (!home) home = ""; - const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); - char* configDir = NULL; - char* htopDir = NULL; - if (xdgConfigHome) { + const char *xdgConfigHome = getenv("XDG_CONFIG_HOME"); + char *configDir = NULL; + char *htopDir = NULL; + if (xdgConfigHome) + { this->filename = String_cat(xdgConfigHome, "/htop/htoprc"); configDir = xStrdup(xdgConfigHome); htopDir = String_cat(xdgConfigHome, "/htop"); - } else { + } + else + { this->filename = String_cat(home, "/.config/htop/htoprc"); configDir = String_cat(home, "/.config"); htopDir = String_cat(home, "/.config/htop"); } legacyDotfile = String_cat(home, "/.htoprc"); - (void) mkdir(configDir, 0700); - (void) mkdir(htopDir, 0700); + (void)mkdir(configDir, 0700); + (void)mkdir(htopDir, 0700); free(htopDir); free(configDir); struct stat st; int err = lstat(legacyDotfile, &st); - if (err || S_ISLNK(st.st_mode)) { + if (err || S_ISLNK(st.st_mode)) + { free(legacyDotfile); legacyDotfile = NULL; } @@ -736,25 +997,31 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) this->changed = false; this->delay = DEFAULT_DELAY; bool ok = false; - if (legacyDotfile) { + if (legacyDotfile) + { ok = Settings_read(this, legacyDotfile, initialCpuCount); - if (ok) { + if (ok) + { // Transition to new location and delete old configuration file - if (Settings_write(this, false) == 0) { + if (Settings_write(this, false) == 0) + { unlink(legacyDotfile); } } free(legacyDotfile); } - if (!ok) { + if (!ok) + { ok = Settings_read(this, this->filename, initialCpuCount); } - if (!ok) { + if (!ok) + { this->screenTabs = true; this->changed = true; ok = Settings_read(this, SYSCONFDIR "/htoprc", initialCpuCount); } - if (!ok) { + if (!ok) + { Settings_defaultMeters(this, initialCpuCount); Settings_defaultScreens(this); } @@ -767,17 +1034,22 @@ Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicColumns) return this; } -void ScreenSettings_invertSortOrder(ScreenSettings* this) { - int* attr = (this->treeView) ? &(this->treeDirection) : &(this->direction); +void ScreenSettings_invertSortOrder(ScreenSettings *this) +{ + int *attr = (this->treeView) ? &(this->treeDirection) : &(this->direction); *attr = (*attr == 1) ? -1 : 1; } -void ScreenSettings_setSortKey(ScreenSettings* this, ProcessField sortKey) { - if (this->treeViewAlwaysByPID || !this->treeView) { +void ScreenSettings_setSortKey(ScreenSettings *this, ProcessField sortKey) +{ + if (this->treeViewAlwaysByPID || !this->treeView) + { this->sortKey = sortKey; this->direction = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1; this->treeView = false; - } else { + } + else + { this->treeSortKey = sortKey; this->treeDirection = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1; } @@ -785,24 +1057,32 @@ void ScreenSettings_setSortKey(ScreenSettings* this, ProcessField sortKey) { static bool readonly = false; -void Settings_enableReadonly(void) { +void Settings_enableReadonly(void) +{ readonly = true; } -bool Settings_isReadonly(void) { +bool Settings_isReadonly(void) +{ return readonly; } -void Settings_setHeaderLayout(Settings* this, HeaderLayout hLayout) { +void Settings_setHeaderLayout(Settings *this, HeaderLayout hLayout) +{ unsigned int oldColumns = HeaderLayout_getColumns(this->hLayout); unsigned int newColumns = HeaderLayout_getColumns(hLayout); - if (newColumns > oldColumns) { + if (newColumns > oldColumns) + { this->hColumns = xReallocArray(this->hColumns, newColumns, sizeof(MeterColumnSetting)); memset(this->hColumns + oldColumns, 0, (newColumns - oldColumns) * sizeof(MeterColumnSetting)); - } else if (newColumns < oldColumns) { - for (unsigned int i = newColumns; i < oldColumns; i++) { - if (this->hColumns[i].names) { + } + else if (newColumns < oldColumns) + { + for (unsigned int i = newColumns; i < oldColumns; i++) + { + if (this->hColumns[i].names) + { for (size_t j = 0; j < this->hColumns[i].len; j++) free(this->hColumns[i].names[j]); free(this->hColumns[i].names); diff --git a/TempMeter.c b/TempMeter.c new file mode 100644 index 00000000..9a169f7d --- /dev/null +++ b/TempMeter.c @@ -0,0 +1,29 @@ +#include "TempMeter.h" + +#include "CRT.h" +#include "Object.h" +#include "Platform.h" +#include "XUtils.h" + +static const int TempMeter_attributes[] = { + TEMP}; + +static void TempMeter_updateValues(Meter *this) +{ + float temp_c = Platform_getTemp(); + + xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1lf °C", temp_c); +} + +const MeterClass TempMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete}, + .updateValues = TempMeter_updateValues, + .defaultMode = TEXT_METERMODE, + .maxItems = 1, + .total = 100.0, + .attributes = TempMeter_attributes, + .name = "Temp", + .uiName = "Temp", + .caption = "CPU/Temperature: "}; diff --git a/TempMeter.h b/TempMeter.h new file mode 100644 index 00000000..69f1b4c5 --- /dev/null +++ b/TempMeter.h @@ -0,0 +1,8 @@ +#ifndef HEADER_TempMeter +#define HEADER_TempMeter + +#include "Meter.h" + +extern const MeterClass TempMeter_class; + +#endif diff --git a/XUtils.h b/XUtils.h index 2522a71f..a89b2ad5 100644 --- a/XUtils.h +++ b/XUtils.h @@ -17,60 +17,61 @@ in the source distribution for its full text. #include "Compat.h" #include "Macros.h" - void fail(void) ATTR_NORETURN; -void* xMalloc(size_t size) ATTR_ALLOC_SIZE1(1) ATTR_MALLOC; +void *xMalloc(size_t size) ATTR_ALLOC_SIZE1(1) ATTR_MALLOC; -void* xMallocArray(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC; +void *xMallocArray(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC; -void* xCalloc(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC; +void *xCalloc(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC; -void* xRealloc(void* ptr, size_t size) ATTR_ALLOC_SIZE1(2); +void *xRealloc(void *ptr, size_t size) ATTR_ALLOC_SIZE1(2); -void* xReallocArray(void* ptr, size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(2, 3); +void *xReallocArray(void *ptr, size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(2, 3); -void* xReallocArrayZero(void* ptr, size_t prevmemb, size_t newmemb, size_t size) ATTR_ALLOC_SIZE2(3, 4); +void *xReallocArrayZero(void *ptr, size_t prevmemb, size_t newmemb, size_t size) ATTR_ALLOC_SIZE2(3, 4); /* * String_startsWith gives better performance if strlen(match) can be computed * at compile time (e.g. when they are immutable string literals). :) */ -static inline bool String_startsWith(const char* s, const char* match) { +static inline bool String_startsWith(const char *s, const char *match) +{ return strncmp(s, match, strlen(match)) == 0; } -bool String_contains_i(const char* s1, const char* s2, bool multi); +bool String_contains_i(const char *s1, const char *s2, bool multi); -static inline bool String_eq(const char* s1, const char* s2) { +static inline bool String_eq(const char *s1, const char *s2) +{ return strcmp(s1, s2) == 0; } -char* String_cat(const char* s1, const char* s2) ATTR_MALLOC; +char *String_cat(const char *s1, const char *s2) ATTR_MALLOC; -char* String_trim(const char* in) ATTR_MALLOC; +char *String_trim(const char *in) ATTR_MALLOC; -char** String_split(const char* s, char sep, size_t* n); +char **String_split(const char *s, char sep, size_t *n); -void String_freeArray(char** s); +void String_freeArray(char **s); -char* String_readLine(FILE* fd) ATTR_MALLOC; +char *String_readLine(FILE *fd) ATTR_MALLOC; /* Always null-terminates dest. Caller must pass a strictly positive size. */ -size_t String_safeStrncpy(char* restrict dest, const char* restrict src, size_t size); +size_t String_safeStrncpy(char *restrict dest, const char *restrict src, size_t size); ATTR_FORMAT(printf, 2, 3) -int xAsprintf(char** strp, const char* fmt, ...); +int xAsprintf(char **strp, const char *fmt, ...); ATTR_FORMAT(printf, 3, 4) -int xSnprintf(char* buf, size_t len, const char* fmt, ...); +int xSnprintf(char *buf, size_t len, const char *fmt, ...); -char* xStrdup(const char* str) ATTR_NONNULL ATTR_MALLOC; -void free_and_xStrdup(char** ptr, const char* str); +char *xStrdup(const char *str) ATTR_NONNULL ATTR_MALLOC; +void free_and_xStrdup(char **ptr, const char *str); -char* xStrndup(const char* str, size_t len) ATTR_NONNULL ATTR_MALLOC; +char *xStrndup(const char *str, size_t len) ATTR_NONNULL ATTR_MALLOC; -ssize_t xReadfile(const char* pathname, void* buffer, size_t count); -ssize_t xReadfileat(openat_arg_t dirfd, const char* pathname, void* buffer, size_t count); +ssize_t xReadfile(const char *pathname, void *buffer, size_t count); +ssize_t xReadfileat(openat_arg_t dirfd, const char *pathname, void *buffer, size_t count); #endif diff --git a/linux/Platform.c b/linux/Platform.c index 38b66e83..837a1462 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -49,6 +49,8 @@ in the source distribution for its full text. #include "SysArchMeter.h" #include "TasksMeter.h" #include "UptimeMeter.h" +#include "FreqMeter.h" +#include "TempMeter.h" #include "XUtils.h" #include "linux/IOPriority.h" #include "linux/IOPriorityPanel.h" @@ -71,12 +73,12 @@ in the source distribution for its full text. #endif #ifndef O_PATH -#define O_PATH 010000000 // declare for ancient glibc versions +#define O_PATH 010000000 // declare for ancient glibc versions #endif - #ifdef HAVE_LIBCAP -enum CapMode { +enum CapMode +{ CAP_MODE_OFF, CAP_MODE_BASIC, CAP_MODE_STRICT @@ -86,60 +88,62 @@ enum CapMode { bool Running_containerized = false; const ScreenDefaults Platform_defaultScreens[] = { - { - .name = "Main", - .columns = "PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command", - .sortKey = "PERCENT_CPU", - }, - { - .name = "I/O", - .columns = "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command", - .sortKey = "IO_RATE", - }, + { + .name = "Main", + .columns = "PID USER PRIORITY NICE M_VIRT M_RESIDENT M_SHARE STATE PERCENT_CPU PERCENT_MEM TIME Command", + .sortKey = "PERCENT_CPU", + }, + { + .name = "I/O", + .columns = "PID USER IO_PRIORITY IO_RATE IO_READ_RATE IO_WRITE_RATE PERCENT_SWAP_DELAY PERCENT_IO_DELAY Command", + .sortKey = "IO_RATE", + }, }; const unsigned int Platform_numberOfDefaultScreens = ARRAYSIZE(Platform_defaultScreens); const SignalItem Platform_signals[] = { - { .name = " 0 Cancel", .number = 0 }, - { .name = " 1 SIGHUP", .number = 1 }, - { .name = " 2 SIGINT", .number = 2 }, - { .name = " 3 SIGQUIT", .number = 3 }, - { .name = " 4 SIGILL", .number = 4 }, - { .name = " 5 SIGTRAP", .number = 5 }, - { .name = " 6 SIGABRT", .number = 6 }, - { .name = " 6 SIGIOT", .number = 6 }, - { .name = " 7 SIGBUS", .number = 7 }, - { .name = " 8 SIGFPE", .number = 8 }, - { .name = " 9 SIGKILL", .number = 9 }, - { .name = "10 SIGUSR1", .number = 10 }, - { .name = "11 SIGSEGV", .number = 11 }, - { .name = "12 SIGUSR2", .number = 12 }, - { .name = "13 SIGPIPE", .number = 13 }, - { .name = "14 SIGALRM", .number = 14 }, - { .name = "15 SIGTERM", .number = 15 }, - { .name = "16 SIGSTKFLT", .number = 16 }, - { .name = "17 SIGCHLD", .number = 17 }, - { .name = "18 SIGCONT", .number = 18 }, - { .name = "19 SIGSTOP", .number = 19 }, - { .name = "20 SIGTSTP", .number = 20 }, - { .name = "21 SIGTTIN", .number = 21 }, - { .name = "22 SIGTTOU", .number = 22 }, - { .name = "23 SIGURG", .number = 23 }, - { .name = "24 SIGXCPU", .number = 24 }, - { .name = "25 SIGXFSZ", .number = 25 }, - { .name = "26 SIGVTALRM", .number = 26 }, - { .name = "27 SIGPROF", .number = 27 }, - { .name = "28 SIGWINCH", .number = 28 }, - { .name = "29 SIGIO", .number = 29 }, - { .name = "29 SIGPOLL", .number = 29 }, - { .name = "30 SIGPWR", .number = 30 }, - { .name = "31 SIGSYS", .number = 31 }, + {.name = " 0 Cancel", .number = 0}, + {.name = " 1 SIGHUP", .number = 1}, + {.name = " 2 SIGINT", .number = 2}, + {.name = " 3 SIGQUIT", .number = 3}, + {.name = " 4 SIGILL", .number = 4}, + {.name = " 5 SIGTRAP", .number = 5}, + {.name = " 6 SIGABRT", .number = 6}, + {.name = " 6 SIGIOT", .number = 6}, + {.name = " 7 SIGBUS", .number = 7}, + {.name = " 8 SIGFPE", .number = 8}, + {.name = " 9 SIGKILL", .number = 9}, + {.name = "10 SIGUSR1", .number = 10}, + {.name = "11 SIGSEGV", .number = 11}, + {.name = "12 SIGUSR2", .number = 12}, + {.name = "13 SIGPIPE", .number = 13}, + {.name = "14 SIGALRM", .number = 14}, + {.name = "15 SIGTERM", .number = 15}, + {.name = "16 SIGSTKFLT", .number = 16}, + {.name = "17 SIGCHLD", .number = 17}, + {.name = "18 SIGCONT", .number = 18}, + {.name = "19 SIGSTOP", .number = 19}, + {.name = "20 SIGTSTP", .number = 20}, + {.name = "21 SIGTTIN", .number = 21}, + {.name = "22 SIGTTOU", .number = 22}, + {.name = "23 SIGURG", .number = 23}, + {.name = "24 SIGXCPU", .number = 24}, + {.name = "25 SIGXFSZ", .number = 25}, + {.name = "26 SIGVTALRM", .number = 26}, + {.name = "27 SIGPROF", .number = 27}, + {.name = "28 SIGWINCH", .number = 28}, + {.name = "29 SIGIO", .number = 29}, + {.name = "29 SIGPOLL", .number = 29}, + {.name = "30 SIGPWR", .number = 30}, + {.name = "31 SIGSYS", .number = 31}, }; const unsigned int Platform_numberOfSignals = ARRAYSIZE(Platform_signals); -static enum { BAT_PROC, BAT_SYS, BAT_ERR } Platform_Battery_method = BAT_PROC; +static enum { BAT_PROC, + BAT_SYS, + BAT_ERR } Platform_Battery_method = BAT_PROC; static time_t Platform_Battery_cacheTime; static double Platform_Battery_cachePercent = NAN; static ACPresence Platform_Battery_cacheIsOnAC; @@ -148,41 +152,47 @@ static ACPresence Platform_Battery_cacheIsOnAC; static enum CapMode Platform_capabilitiesMode = CAP_MODE_BASIC; #endif -static Htop_Reaction Platform_actionSetIOPriority(State* st) { +static Htop_Reaction Platform_actionSetIOPriority(State *st) +{ if (Settings_isReadonly()) return HTOP_OK; - const LinuxProcess* p = (const LinuxProcess*) Panel_getSelected((Panel*)st->mainPanel); + const LinuxProcess *p = (const LinuxProcess *)Panel_getSelected((Panel *)st->mainPanel); if (!p) return HTOP_OK; IOPriority ioprio1 = p->ioPriority; - Panel* ioprioPanel = IOPriorityPanel_new(ioprio1); - const void* set = Action_pickFromVector(st, ioprioPanel, 20, true); - if (set) { + Panel *ioprioPanel = IOPriorityPanel_new(ioprio1); + const void *set = Action_pickFromVector(st, ioprioPanel, 20, true); + if (set) + { IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess(st->mainPanel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL); - if (!ok) { + bool ok = MainPanel_foreachProcess(st->mainPanel, LinuxProcess_setIOPriority, (Arg){.i = ioprio2}, NULL); + if (!ok) + { beep(); } } - Panel_delete((Object*)ioprioPanel); + Panel_delete((Object *)ioprioPanel); return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } -static bool Platform_changeAutogroupPriority(MainPanel* panel, int delta) { - if (LinuxProcess_isAutogroupEnabled() == false) { +static bool Platform_changeAutogroupPriority(MainPanel *panel, int delta) +{ + if (LinuxProcess_isAutogroupEnabled() == false) + { beep(); return false; } bool anyTagged; - bool ok = MainPanel_foreachProcess(panel, LinuxProcess_changeAutogroupPriorityBy, (Arg) { .i = delta }, &anyTagged); + bool ok = MainPanel_foreachProcess(panel, LinuxProcess_changeAutogroupPriorityBy, (Arg){.i = delta}, &anyTagged); if (!ok) beep(); return anyTagged; } -static Htop_Reaction Platform_actionHigherAutogroupPriority(State* st) { +static Htop_Reaction Platform_actionHigherAutogroupPriority(State *st) +{ if (Settings_isReadonly()) return HTOP_OK; @@ -190,7 +200,8 @@ static Htop_Reaction Platform_actionHigherAutogroupPriority(State* st) { return changed ? HTOP_REFRESH : HTOP_OK; } -static Htop_Reaction Platform_actionLowerAutogroupPriority(State* st) { +static Htop_Reaction Platform_actionLowerAutogroupPriority(State *st) +{ if (Settings_isReadonly()) return HTOP_OK; @@ -198,7 +209,8 @@ static Htop_Reaction Platform_actionLowerAutogroupPriority(State* st) { return changed ? HTOP_REFRESH : HTOP_OK; } -void Platform_setBindings(Htop_Action* keys) { +void Platform_setBindings(Htop_Action *keys) +{ keys['i'] = Platform_actionSetIOPriority; keys['{'] = Platform_actionLowerAutogroupPriority; keys['}'] = Platform_actionHigherAutogroupPriority; @@ -206,65 +218,122 @@ void Platform_setBindings(Htop_Action* keys) { keys[KEY_F(20)] = Platform_actionHigherAutogroupPriority; // Shift-F8 } -const MeterClass* const Platform_meterTypes[] = { - &CPUMeter_class, - &ClockMeter_class, - &DateMeter_class, - &DateTimeMeter_class, - &LoadAverageMeter_class, - &LoadMeter_class, - &MemoryMeter_class, - &SwapMeter_class, - &MemorySwapMeter_class, - &SysArchMeter_class, - &HugePageMeter_class, - &TasksMeter_class, - &UptimeMeter_class, - &BatteryMeter_class, - &HostnameMeter_class, - &AllCPUsMeter_class, - &AllCPUs2Meter_class, - &AllCPUs4Meter_class, - &AllCPUs8Meter_class, - &LeftCPUsMeter_class, - &RightCPUsMeter_class, - &LeftCPUs2Meter_class, - &RightCPUs2Meter_class, - &LeftCPUs4Meter_class, - &RightCPUs4Meter_class, - &LeftCPUs8Meter_class, - &RightCPUs8Meter_class, - &BlankMeter_class, - &PressureStallCPUSomeMeter_class, - &PressureStallIOSomeMeter_class, - &PressureStallIOFullMeter_class, - &PressureStallMemorySomeMeter_class, - &PressureStallMemoryFullMeter_class, - &ZfsArcMeter_class, - &ZfsCompressedArcMeter_class, - &ZramMeter_class, - &DiskIOMeter_class, - &NetworkIOMeter_class, - &SELinuxMeter_class, - &SystemdMeter_class, - NULL -}; +const MeterClass *const Platform_meterTypes[] = { + &CPUMeter_class, + &ClockMeter_class, + &DateMeter_class, + &DateTimeMeter_class, + &LoadAverageMeter_class, + &LoadMeter_class, + &MemoryMeter_class, + &SwapMeter_class, + &MemorySwapMeter_class, + &SysArchMeter_class, + &HugePageMeter_class, + &TasksMeter_class, + &UptimeMeter_class, + &FreqMeter_class, + &TempMeter_class, + &BatteryMeter_class, + &HostnameMeter_class, + &AllCPUsMeter_class, + &AllCPUs2Meter_class, + &AllCPUs4Meter_class, + &AllCPUs8Meter_class, + &LeftCPUsMeter_class, + &RightCPUsMeter_class, + &LeftCPUs2Meter_class, + &RightCPUs2Meter_class, + &LeftCPUs4Meter_class, + &RightCPUs4Meter_class, + &LeftCPUs8Meter_class, + &RightCPUs8Meter_class, + &BlankMeter_class, + &PressureStallCPUSomeMeter_class, + &PressureStallIOSomeMeter_class, + &PressureStallIOFullMeter_class, + &PressureStallMemorySomeMeter_class, + &PressureStallMemoryFullMeter_class, + &ZfsArcMeter_class, + &ZfsCompressedArcMeter_class, + &ZramMeter_class, + &DiskIOMeter_class, + &NetworkIOMeter_class, + &SELinuxMeter_class, + &SystemdMeter_class, + NULL}; -int Platform_getUptime() { +int Platform_getUptime() +{ double uptime = 0; - FILE* fd = fopen(PROCDIR "/uptime", "r"); - if (fd) { + FILE *fd = fopen(PROCDIR "/uptime", "r"); + if (fd) + { int n = fscanf(fd, "%64lf", &uptime); fclose(fd); - if (n <= 0) { + if (n <= 0) + { return 0; } } return floor(uptime); } -void Platform_getLoadAverage(double* one, double* five, double* fifteen) { - FILE* fd = fopen(PROCDIR "/loadavg", "r"); +float Platform_getTemp() +{ + float ftemp = 0; + + FILE *fd = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); + if (!fd) + { + return ftemp; + } + + int itemp = 0; + fscanf(fd, "%d", &itemp); + ftemp = itemp; + + if (ftemp >= 1000) + { + ftemp /= 1000; + } + + fclose(fd); + + return ftemp; +} + +float Platform_getFreq() +{ + float freq = 0; + + FILE *fd = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r"); + if (!fd) + { + return freq; + } + + int ifreq = 0; + fscanf(fd, "%d", &ifreq); + freq = ifreq; + + fclose(fd); + + if (freq < 10) + { + freq *= 1000000; + } + else + { + freq /= 1000000; + } + + return freq; +} + +void Platform_getLoadAverage(double *one, double *five, double *fifteen) +{ + FILE *fd = fopen(PROCDIR "/loadavg", "r"); if (!fd) goto err; @@ -285,53 +354,63 @@ err: *fifteen = NAN; } -int Platform_getMaxPid() { - FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); +int Platform_getMaxPid() +{ + FILE *file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); if (!file) return -1; int maxPid = 4194303; int match = fscanf(file, "%32d", &maxPid); - (void) match; + (void)match; fclose(file); return maxPid; } -double Platform_setCPUValues(Meter* this, unsigned int cpu) { - const LinuxProcessList* pl = (const LinuxProcessList*) this->pl; - const CPUData* cpuData = &(pl->cpuData[cpu]); - double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod); +double Platform_setCPUValues(Meter *this, unsigned int cpu) +{ + const LinuxProcessList *pl = (const LinuxProcessList *)this->pl; + const CPUData *cpuData = &(pl->cpuData[cpu]); + double total = (double)(cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod); double percent; - double* v = this->values; + double *v = this->values; - if (!cpuData->online) { + if (!cpuData->online) + { this->curItems = 0; return NAN; } v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0; v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0; - if (this->pl->settings->detailedCPUTime) { - v[CPU_METER_KERNEL] = cpuData->systemPeriod / total * 100.0; - v[CPU_METER_IRQ] = cpuData->irqPeriod / total * 100.0; + if (this->pl->settings->detailedCPUTime) + { + v[CPU_METER_KERNEL] = cpuData->systemPeriod / total * 100.0; + v[CPU_METER_IRQ] = cpuData->irqPeriod / total * 100.0; v[CPU_METER_SOFTIRQ] = cpuData->softIrqPeriod / total * 100.0; - v[CPU_METER_STEAL] = cpuData->stealPeriod / total * 100.0; - v[CPU_METER_GUEST] = cpuData->guestPeriod / total * 100.0; - v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; + v[CPU_METER_STEAL] = cpuData->stealPeriod / total * 100.0; + v[CPU_METER_GUEST] = cpuData->guestPeriod / total * 100.0; + v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; this->curItems = 8; - if (this->pl->settings->accountGuestInCPUMeter) { + if (this->pl->settings->accountGuestInCPUMeter) + { percent = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6]; - } else { + } + else + { percent = v[0] + v[1] + v[2] + v[3] + v[4]; } - } else { + } + else + { v[2] = cpuData->systemAllPeriod / total * 100.0; v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; this->curItems = 4; percent = v[0] + v[1] + v[2] + v[3]; } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) { + if (isnan(percent)) + { percent = 0.0; } @@ -346,18 +425,20 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { return percent; } -void Platform_setMemoryValues(Meter* this) { - const ProcessList* pl = this->pl; - const LinuxProcessList* lpl = (const LinuxProcessList*) pl; +void Platform_setMemoryValues(Meter *this) +{ + const ProcessList *pl = this->pl; + const LinuxProcessList *lpl = (const LinuxProcessList *)pl; - this->total = pl->totalMem; + this->total = pl->totalMem; this->values[0] = pl->usedMem; this->values[1] = pl->buffersMem; this->values[2] = pl->sharedMem; this->values[3] = pl->cachedMem; this->values[4] = pl->availableMem; - if (lpl->zfs.enabled != 0 && !Running_containerized) { + if (lpl->zfs.enabled != 0 && !Running_containerized) + { // ZFS does not shrink below the value of zfs_arc_min. unsigned long long int shrinkableSize = 0; if (lpl->zfs.size > lpl->zfs.min) @@ -368,46 +449,52 @@ void Platform_setMemoryValues(Meter* this) { } } -void Platform_setSwapValues(Meter* this) { - const ProcessList* pl = this->pl; +void Platform_setSwapValues(Meter *this) +{ + const ProcessList *pl = this->pl; this->total = pl->totalSwap; this->values[0] = pl->usedSwap; this->values[1] = pl->cachedSwap; } -void Platform_setZramValues(Meter* this) { - const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; +void Platform_setZramValues(Meter *this) +{ + const LinuxProcessList *lpl = (const LinuxProcessList *)this->pl; this->total = lpl->zram.totalZram; this->values[0] = lpl->zram.usedZramComp; this->values[1] = lpl->zram.usedZramOrig; } -void Platform_setZfsArcValues(Meter* this) { - const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; +void Platform_setZfsArcValues(Meter *this) +{ + const LinuxProcessList *lpl = (const LinuxProcessList *)this->pl; ZfsArcMeter_readStats(this, &(lpl->zfs)); } -void Platform_setZfsCompressedArcValues(Meter* this) { - const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; +void Platform_setZfsCompressedArcValues(Meter *this) +{ + const LinuxProcessList *lpl = (const LinuxProcessList *)this->pl; ZfsCompressedArcMeter_readStats(this, &(lpl->zfs)); } -char* Platform_getProcessEnv(pid_t pid) { +char *Platform_getProcessEnv(pid_t pid) +{ char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); - FILE* fd = fopen(procname, "r"); + FILE *fd = fopen(procname, "r"); if (!fd) return NULL; - char* env = NULL; + char *env = NULL; size_t capacity = 0; size_t size = 0; ssize_t bytes = 0; - do { + do + { size += bytes; capacity += 4096; env = xRealloc(env, capacity); @@ -415,7 +502,8 @@ char* Platform_getProcessEnv(pid_t pid) { fclose(fd); - if (bytes < 0) { + if (bytes < 0) + { free(env); return NULL; } @@ -436,16 +524,17 @@ char* Platform_getProcessEnv(pid_t pid) { * Based on implementation of lslocks from util-linux: * https://sources.debian.org/src/util-linux/2.36-3/misc-utils/lslocks.c/#L162 */ -char* Platform_getInodeFilename(pid_t pid, ino_t inode) { +char *Platform_getInodeFilename(pid_t pid, ino_t inode) +{ struct stat sb; - const struct dirent* de; - DIR* dirp; + const struct dirent *de; + DIR *dirp; ssize_t len; int fd; char path[PATH_MAX]; char sym[PATH_MAX]; - char* ret = NULL; + char *ret = NULL; memset(path, 0, sizeof(path)); memset(sym, 0, sizeof(sym)); @@ -457,15 +546,16 @@ char* Platform_getInodeFilename(pid_t pid, ino_t inode) { if (!(dirp = opendir(path))) return NULL; - if ((fd = dirfd(dirp)) < 0 ) + if ((fd = dirfd(dirp)) < 0) goto out; - while ((de = readdir(dirp))) { + while ((de = readdir(dirp))) + { if (String_eq(de->d_name, ".") || String_eq(de->d_name, "..")) continue; /* care only for numerical descriptors */ - if (!strtoull(de->d_name, (char **) NULL, 10)) + if (!strtoull(de->d_name, (char **)NULL, 10)) continue; if (!Compat_fstatat(fd, path, de->d_name, &sb, 0) && inode != sb.st_ino) @@ -485,18 +575,21 @@ out: return ret; } -FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { - FileLocks_ProcessData* pdata = xCalloc(1, sizeof(FileLocks_ProcessData)); +FileLocks_ProcessData *Platform_getProcessLocks(pid_t pid) +{ + FileLocks_ProcessData *pdata = xCalloc(1, sizeof(FileLocks_ProcessData)); - FILE* f = fopen(PROCDIR "/locks", "r"); - if (!f) { + FILE *f = fopen(PROCDIR "/locks", "r"); + if (!f) + { pdata->error = true; return pdata; } char buffer[1024]; - FileLocks_LockData** data_ref = &pdata->locks; - while(fgets(buffer, sizeof(buffer), f)) { + FileLocks_LockData **data_ref = &pdata->locks; + while (fgets(buffer, sizeof(buffer), f)) + { if (!strchr(buffer, '\n')) continue; @@ -510,17 +603,17 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { char lock_start[25]; char lock_end[25]; - if (10 != sscanf(buffer, "%d: %15s %15s %15s %d %x:%x:%"PRIu64" %24s %24s", - &lock_id, lock_type, lock_excl, lock_rw, &lock_pid, - &lock_dev[0], &lock_dev[1], &lock_inode, - lock_start, lock_end)) + if (10 != sscanf(buffer, "%d: %15s %15s %15s %d %x:%x:%" PRIu64 " %24s %24s", + &lock_id, lock_type, lock_excl, lock_rw, &lock_pid, + &lock_dev[0], &lock_dev[1], &lock_inode, + lock_start, lock_end)) continue; if (pid != lock_pid) continue; - FileLocks_LockData* ldata = xCalloc(1, sizeof(FileLocks_LockData)); - FileLocks_Data* data = &ldata->data; + FileLocks_LockData *ldata = xCalloc(1, sizeof(FileLocks_LockData)); + FileLocks_Data *data = &ldata->data; data->id = lock_id; data->locktype = xStrdup(lock_type); data->exclusive = xStrdup(lock_excl); @@ -530,9 +623,12 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { data->dev[1] = lock_dev[1]; data->inode = lock_inode; data->start = strtoull(lock_start, NULL, 10); - if (!String_eq(lock_end, "EOF")) { + if (!String_eq(lock_end, "EOF")) + { data->end = strtoull(lock_end, NULL, 10); - } else { + } + else + { data->end = ULLONG_MAX; } @@ -544,37 +640,43 @@ FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid) { return pdata; } -void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred) { +void Platform_getPressureStall(const char *file, bool some, double *ten, double *sixty, double *threehundred) +{ *ten = *sixty = *threehundred = 0; char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/pressure/%s", file); - FILE* fd = fopen(procname, "r"); - if (!fd) { + FILE *fd = fopen(procname, "r"); + if (!fd) + { *ten = *sixty = *threehundred = NAN; return; } int total = fscanf(fd, "some avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); - if (!some) { + if (!some) + { total = fscanf(fd, "full avg10=%32lf avg60=%32lf avg300=%32lf total=%*f ", ten, sixty, threehundred); } - (void) total; + (void)total; assert(total == 3); fclose(fd); } -bool Platform_getDiskIO(DiskIOData* data) { - FILE* fd = fopen(PROCDIR "/diskstats", "r"); +bool Platform_getDiskIO(DiskIOData *data) +{ + FILE *fd = fopen(PROCDIR "/diskstats", "r"); if (!fd) return false; - char lastTopDisk[32] = { '\0' }; + char lastTopDisk[32] = {'\0'}; unsigned long long int read_sum = 0, write_sum = 0, timeSpend_sum = 0; char lineBuffer[256]; - while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { + while (fgets(lineBuffer, sizeof(lineBuffer), fd)) + { char diskname[32]; unsigned long long int read_tmp, write_tmp, timeSpend_tmp; - if (sscanf(lineBuffer, "%*d %*d %31s %*u %*u %llu %*u %*u %*u %llu %*u %*u %llu", diskname, &read_tmp, &write_tmp, &timeSpend_tmp) == 4) { + if (sscanf(lineBuffer, "%*d %*d %31s %*u %*u %llu %*u %*u %*u %llu %*u %*u %llu", diskname, &read_tmp, &write_tmp, &timeSpend_tmp) == 4) + { if (String_startsWith(diskname, "dm-")) continue; @@ -601,22 +703,24 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(NetworkIOData* data) { - FILE* fd = fopen(PROCDIR "/net/dev", "r"); +bool Platform_getNetworkIO(NetworkIOData *data) +{ + FILE *fd = fopen(PROCDIR "/net/dev", "r"); if (!fd) return false; memset(data, 0, sizeof(NetworkIOData)); char lineBuffer[512]; - while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { + while (fgets(lineBuffer, sizeof(lineBuffer), fd)) + { char interfaceName[32]; unsigned long long int bytesReceived, packetsReceived, bytesTransmitted, packetsTransmitted; if (sscanf(lineBuffer, "%31s %llu %llu %*u %*u %*u %*u %*u %*u %llu %llu", - interfaceName, - &bytesReceived, - &packetsReceived, - &bytesTransmitted, - &packetsTransmitted) != 5) + interfaceName, + &bytesReceived, + &packetsReceived, + &bytesTransmitted, + &packetsTransmitted) != 5) continue; if (String_eq(interfaceName, "lo:")) @@ -644,17 +748,19 @@ bool Platform_getNetworkIO(NetworkIOData* data) { // READ FROM /proc // ---------------------------------------- -static double Platform_Battery_getProcBatInfo(void) { - DIR* batteryDir = opendir(PROC_BATTERY_DIR); +static double Platform_Battery_getProcBatInfo(void) +{ + DIR *batteryDir = opendir(PROC_BATTERY_DIR); if (!batteryDir) return NAN; uint64_t totalFull = 0; uint64_t totalRemain = 0; - struct dirent* dirEntry = NULL; - while ((dirEntry = readdir(batteryDir))) { - const char* entryName = dirEntry->d_name; + struct dirent *dirEntry = NULL; + while ((dirEntry = readdir(batteryDir))) + { + const char *entryName = dirEntry->d_name; if (!String_startsWith(entryName, "BAT")) continue; @@ -671,31 +777,35 @@ static double Platform_Battery_getProcBatInfo(void) { if (r < 0) continue; - const char* line; + const char *line; - //Getting total charge for all batteries - char* buf = bufInfo; - while ((line = strsep(&buf, "\n")) != NULL) { + // Getting total charge for all batteries + char *buf = bufInfo; + while ((line = strsep(&buf, "\n")) != NULL) + { char field[100] = {0}; int val = 0; if (2 != sscanf(line, "%99[^:]:%d", field, &val)) continue; - if (String_eq(field, "last full capacity")) { + if (String_eq(field, "last full capacity")) + { totalFull += val; break; } } - //Getting remaining charge for all batteries + // Getting remaining charge for all batteries buf = bufState; - while ((line = strsep(&buf, "\n")) != NULL) { + while ((line = strsep(&buf, "\n")) != NULL) + { char field[100] = {0}; int val = 0; if (2 != sscanf(line, "%99[^:]:%d", field, &val)) continue; - if (String_eq(field, "remaining capacity")) { + if (String_eq(field, "remaining capacity")) + { totalRemain += val; break; } @@ -704,10 +814,11 @@ static double Platform_Battery_getProcBatInfo(void) { closedir(batteryDir); - return totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN; + return totalFull > 0 ? ((double)totalRemain * 100.0) / (double)totalFull : NAN; } -static ACPresence procAcpiCheck(void) { +static ACPresence procAcpiCheck(void) +{ char buffer[1024] = {0}; ssize_t r = xReadfile(PROC_POWERSUPPLY_ACSTATE_FILE, buffer, sizeof(buffer)); if (r < 1) @@ -716,7 +827,8 @@ static ACPresence procAcpiCheck(void) { return String_eq(buffer, "on-line") ? AC_PRESENT : AC_ABSENT; } -static void Platform_Battery_getProcData(double* percent, ACPresence* isOnAC) { +static void Platform_Battery_getProcData(double *percent, ACPresence *isOnAC) +{ *isOnAC = procAcpiCheck(); *percent = AC_ERROR != *isOnAC ? Platform_Battery_getProcBatInfo() : NAN; } @@ -725,20 +837,22 @@ static void Platform_Battery_getProcData(double* percent, ACPresence* isOnAC) { // READ FROM /sys // ---------------------------------------- -static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { +static void Platform_Battery_getSysData(double *percent, ACPresence *isOnAC) +{ *percent = NAN; *isOnAC = AC_ERROR; - DIR* dir = opendir(SYS_POWERSUPPLY_DIR); + DIR *dir = opendir(SYS_POWERSUPPLY_DIR); if (!dir) return; uint64_t totalFull = 0; uint64_t totalRemain = 0; - const struct dirent* dirEntry; - while ((dirEntry = readdir(dir))) { - const char* entryName = dirEntry->d_name; + const struct dirent *dirEntry; + while ((dirEntry = readdir(dir))) + { + const char *entryName = dirEntry->d_name; #ifdef HAVE_OPENAT int entryFd = openat(dirfd(dir), entryName, O_DIRECTORY | O_PATH); @@ -749,19 +863,28 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { xSnprintf(entryFd, sizeof(entryFd), SYS_POWERSUPPLY_DIR "/%s", entryName); #endif - enum { AC, BAT } type; - if (String_startsWith(entryName, "BAT")) { + enum + { + AC, + BAT + } type; + if (String_startsWith(entryName, "BAT")) + { type = BAT; - } else if (String_startsWith(entryName, "AC")) { + } + else if (String_startsWith(entryName, "AC")) + { type = AC; - } else { + } + else + { char buffer[32]; ssize_t ret = xReadfileat(entryFd, "type", buffer, sizeof(buffer)); if (ret <= 0) goto next; /* drop optional trailing newlines */ - for (char* buf = &buffer[(size_t)ret - 1]; *buf == '\n'; buf--) + for (char *buf = &buffer[(size_t)ret - 1]; *buf == '\n'; buf--) *buf = '\0'; if (String_eq(buffer, "Battery")) @@ -772,7 +895,8 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { goto next; } - if (type == BAT) { + if (type == BAT) + { char buffer[1024]; ssize_t r = xReadfileat(entryFd, "uevent", buffer, sizeof(buffer)); if (r < 0) @@ -783,21 +907,24 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { double fullCharge = 0; double capacityLevel = NAN; - const char* line; + const char *line; - char* buf = buffer; - while ((line = strsep(&buf, "\n")) != NULL) { + char *buf = buffer; + while ((line = strsep(&buf, "\n")) != NULL) + { char field[100] = {0}; int val = 0; if (2 != sscanf(line, "POWER_SUPPLY_%99[^=]=%d", field, &val)) continue; - if (String_eq(field, "CAPACITY")) { + if (String_eq(field, "CAPACITY")) + { capacityLevel = val / 100.0; continue; } - if (String_eq(field, "ENERGY_FULL") || String_eq(field, "CHARGE_FULL")) { + if (String_eq(field, "ENERGY_FULL") || String_eq(field, "CHARGE_FULL")) + { fullCharge = val; totalFull += fullCharge; full = true; @@ -806,7 +933,8 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { continue; } - if (String_eq(field, "ENERGY_NOW") || String_eq(field, "CHARGE_NOW")) { + if (String_eq(field, "ENERGY_NOW") || String_eq(field, "CHARGE_NOW")) + { totalRemain += val; now = true; if (full) @@ -817,14 +945,16 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { if (!now && full && !isnan(capacityLevel)) totalRemain += capacityLevel * fullCharge; - - } else if (type == AC) { + } + else if (type == AC) + { if (*isOnAC != AC_ERROR) goto next; char buffer[2]; ssize_t r = xReadfileat(entryFd, "online", buffer, sizeof(buffer)); - if (r < 1) { + if (r < 1) + { *isOnAC = AC_ERROR; goto next; } @@ -835,38 +965,45 @@ static void Platform_Battery_getSysData(double* percent, ACPresence* isOnAC) { *isOnAC = AC_PRESENT; } -next: + next: Compat_openatArgClose(entryFd); } closedir(dir); - *percent = totalFull > 0 ? ((double) totalRemain * 100.0) / (double) totalFull : NAN; + *percent = totalFull > 0 ? ((double)totalRemain * 100.0) / (double)totalFull : NAN; } -void Platform_getBattery(double* percent, ACPresence* isOnAC) { +void Platform_getBattery(double *percent, ACPresence *isOnAC) +{ time_t now = time(NULL); // update battery reading is slow. Update it each 10 seconds only. - if (now < Platform_Battery_cacheTime + 10) { + if (now < Platform_Battery_cacheTime + 10) + { *percent = Platform_Battery_cachePercent; *isOnAC = Platform_Battery_cacheIsOnAC; return; } - if (Platform_Battery_method == BAT_PROC) { + if (Platform_Battery_method == BAT_PROC) + { Platform_Battery_getProcData(percent, isOnAC); if (isnan(*percent)) Platform_Battery_method = BAT_SYS; } - if (Platform_Battery_method == BAT_SYS) { + if (Platform_Battery_method == BAT_SYS) + { Platform_Battery_getSysData(percent, isOnAC); if (isnan(*percent)) Platform_Battery_method = BAT_ERR; } - if (Platform_Battery_method == BAT_ERR) { + if (Platform_Battery_method == BAT_ERR) + { *percent = NAN; *isOnAC = AC_ERROR; - } else { + } + else + { *percent = CLAMP(*percent, 0.0, 100.0); } Platform_Battery_cachePercent = *percent; @@ -874,103 +1011,121 @@ void Platform_getBattery(double* percent, ACPresence* isOnAC) { Platform_Battery_cacheTime = now; } -void Platform_longOptionsUsage(const char* name) +void Platform_longOptionsUsage(const char *name) { #ifdef HAVE_LIBCAP printf( -" --drop-capabilities[=off|basic|strict] Drop Linux capabilities when running as root\n" -" off - do not drop any capabilities\n" -" basic (default) - drop all capabilities not needed by %s\n" -" strict - drop all capabilities except those needed for\n" -" core functionality\n", name); + " --drop-capabilities[=off|basic|strict] Drop Linux capabilities when running as root\n" + " off - do not drop any capabilities\n" + " basic (default) - drop all capabilities not needed by %s\n" + " strict - drop all capabilities except those needed for\n" + " core functionality\n", + name); #else - (void) name; + (void)name; #endif } -CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv) { +CommandLineStatus Platform_getLongOption(int opt, int argc, char **argv) +{ #ifndef HAVE_LIBCAP - (void) argc; - (void) argv; + (void)argc; + (void)argv; #endif - switch (opt) { + switch (opt) + { #ifdef HAVE_LIBCAP - case 160: { - const char* mode = optarg; - if (!mode && optind < argc && argv[optind] != NULL && - (argv[optind][0] != '\0' && argv[optind][0] != '-')) { - mode = argv[optind++]; - } - - if (!mode || String_eq(mode, "basic")) { - Platform_capabilitiesMode = CAP_MODE_BASIC; - } else if (String_eq(mode, "off")) { - Platform_capabilitiesMode = CAP_MODE_OFF; - } else if (String_eq(mode, "strict")) { - Platform_capabilitiesMode = CAP_MODE_STRICT; - } else { - fprintf(stderr, "Error: invalid capabilities mode \"%s\".\n", mode); - return STATUS_ERROR_EXIT; - } - return STATUS_OK; + case 160: + { + const char *mode = optarg; + if (!mode && optind < argc && argv[optind] != NULL && + (argv[optind][0] != '\0' && argv[optind][0] != '-')) + { + mode = argv[optind++]; } + + if (!mode || String_eq(mode, "basic")) + { + Platform_capabilitiesMode = CAP_MODE_BASIC; + } + else if (String_eq(mode, "off")) + { + Platform_capabilitiesMode = CAP_MODE_OFF; + } + else if (String_eq(mode, "strict")) + { + Platform_capabilitiesMode = CAP_MODE_STRICT; + } + else + { + fprintf(stderr, "Error: invalid capabilities mode \"%s\".\n", mode); + return STATUS_ERROR_EXIT; + } + return STATUS_OK; + } #endif - default: - break; + default: + break; } return STATUS_ERROR_EXIT; } #ifdef HAVE_LIBCAP -static int dropCapabilities(enum CapMode mode) { +static int dropCapabilities(enum CapMode mode) +{ if (mode == CAP_MODE_OFF) return 0; /* capabilities we keep to operate */ const cap_value_t keepcapsStrict[] = { - CAP_DAC_READ_SEARCH, - CAP_SYS_PTRACE, + CAP_DAC_READ_SEARCH, + CAP_SYS_PTRACE, }; const cap_value_t keepcapsBasic[] = { - CAP_DAC_READ_SEARCH, /* read non world-readable process files of other users, like /proc/[pid]/io */ - CAP_KILL, /* send signals to processes of other users */ - CAP_SYS_NICE, /* lower process nice value / change nice value for arbitrary processes */ - CAP_SYS_PTRACE, /* read /proc/[pid]/exe */ + CAP_DAC_READ_SEARCH, /* read non world-readable process files of other users, like /proc/[pid]/io */ + CAP_KILL, /* send signals to processes of other users */ + CAP_SYS_NICE, /* lower process nice value / change nice value for arbitrary processes */ + CAP_SYS_PTRACE, /* read /proc/[pid]/exe */ #ifdef HAVE_DELAYACCT - CAP_NET_ADMIN, /* communicate over netlink socket for delay accounting */ + CAP_NET_ADMIN, /* communicate over netlink socket for delay accounting */ #endif }; - const cap_value_t* const keepcaps = (mode == CAP_MODE_BASIC) ? keepcapsBasic : keepcapsStrict; + const cap_value_t *const keepcaps = (mode == CAP_MODE_BASIC) ? keepcapsBasic : keepcapsStrict; const size_t ncap = (mode == CAP_MODE_BASIC) ? ARRAYSIZE(keepcapsBasic) : ARRAYSIZE(keepcapsStrict); cap_t caps = cap_init(); - if (caps == NULL) { + if (caps == NULL) + { fprintf(stderr, "Error: can not initialize capabilities: %s\n", strerror(errno)); return -1; } - if (cap_clear(caps) < 0) { + if (cap_clear(caps) < 0) + { fprintf(stderr, "Error: can not clear capabilities: %s\n", strerror(errno)); cap_free(caps); return -1; } cap_t currCaps = cap_get_proc(); - if (currCaps == NULL) { + if (currCaps == NULL) + { fprintf(stderr, "Error: can not get current process capabilities: %s\n", strerror(errno)); cap_free(caps); return -1; } - for (size_t i = 0; i < ncap; i++) { + for (size_t i = 0; i < ncap; i++) + { if (!CAP_IS_SUPPORTED(keepcaps[i])) continue; cap_flag_value_t current; - if (cap_get_flag(currCaps, keepcaps[i], CAP_PERMITTED, ¤t) < 0) { + if (cap_get_flag(currCaps, keepcaps[i], CAP_PERMITTED, ¤t) < 0) + { fprintf(stderr, "Error: can not get current value of capability %d: %s\n", keepcaps[i], strerror(errno)); cap_free(currCaps); cap_free(caps); @@ -980,14 +1135,16 @@ static int dropCapabilities(enum CapMode mode) { if (current != CAP_SET) continue; - if (cap_set_flag(caps, CAP_PERMITTED, 1, &keepcaps[i], CAP_SET) < 0) { + if (cap_set_flag(caps, CAP_PERMITTED, 1, &keepcaps[i], CAP_SET) < 0) + { fprintf(stderr, "Error: can not set permitted capability %d: %s\n", keepcaps[i], strerror(errno)); cap_free(currCaps); cap_free(caps); return -1; } - if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &keepcaps[i], CAP_SET) < 0) { + if (cap_set_flag(caps, CAP_EFFECTIVE, 1, &keepcaps[i], CAP_SET) < 0) + { fprintf(stderr, "Error: can not set effective capability %d: %s\n", keepcaps[i], strerror(errno)); cap_free(currCaps); cap_free(caps); @@ -995,7 +1152,8 @@ static int dropCapabilities(enum CapMode mode) { } } - if (cap_set_proc(caps) < 0) { + if (cap_set_proc(caps) < 0) + { fprintf(stderr, "Error: can not set process capabilities: %s\n", strerror(errno)); cap_free(currCaps); cap_free(caps); @@ -1009,13 +1167,15 @@ static int dropCapabilities(enum CapMode mode) { } #endif -bool Platform_init(void) { +bool Platform_init(void) +{ #ifdef HAVE_LIBCAP if (dropCapabilities(Platform_capabilitiesMode) < 0) return false; #endif - if (access(PROCDIR, R_OK) != 0) { + if (access(PROCDIR, R_OK) != 0) + { fprintf(stderr, "Error: could not read procfs (compiled to look in %s).\n", PROCDIR); return false; } @@ -1026,21 +1186,26 @@ bool Platform_init(void) { char target[PATH_MAX]; ssize_t ret = readlink(PROCDIR "/self/ns/pid", target, sizeof(target) - 1); - if (ret > 0) { + if (ret > 0) + { target[ret] = '\0'; - if (!String_eq("pid:[4026531836]", target)) { // magic constant PROC_PID_INIT_INO from include/linux/proc_ns.h#L46 + if (!String_eq("pid:[4026531836]", target)) + { // magic constant PROC_PID_INIT_INO from include/linux/proc_ns.h#L46 Running_containerized = true; return true; // early return } } - FILE* fd = fopen(PROCDIR "/1/mounts", "r"); - if (fd) { + FILE *fd = fopen(PROCDIR "/1/mounts", "r"); + if (fd) + { char lineBuffer[256]; - while (fgets(lineBuffer, sizeof(lineBuffer), fd)) { + while (fgets(lineBuffer, sizeof(lineBuffer), fd)) + { // detect lxc or overlayfs and guess that this means we are running containerized - if (String_startsWith(lineBuffer, "lxcfs /proc") || String_startsWith(lineBuffer, "overlay ")) { + if (String_startsWith(lineBuffer, "lxcfs /proc") || String_startsWith(lineBuffer, "overlay ")) + { Running_containerized = true; break; } @@ -1051,7 +1216,8 @@ bool Platform_init(void) { return true; } -void Platform_done(void) { +void Platform_done(void) +{ #ifdef HAVE_SENSORS_SENSORS_H LibSensors_cleanup(); #endif diff --git a/linux/Platform.h b/linux/Platform.h index e6fa1610..9d58727a 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -34,10 +34,9 @@ in the source distribution for its full text. /* GNU/Hurd does not have PATH_MAX in limits.h */ #ifndef PATH_MAX - #define PATH_MAX 4096 +#define PATH_MAX 4096 #endif - extern const ScreenDefaults Platform_defaultScreens[]; extern const unsigned int Platform_numberOfDefaultScreens; @@ -46,90 +45,98 @@ extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; -extern const MeterClass* const Platform_meterTypes[]; +extern const MeterClass *const Platform_meterTypes[]; bool Platform_init(void); void Platform_done(void); extern bool Running_containerized; -void Platform_setBindings(Htop_Action* keys); +void Platform_setBindings(Htop_Action *keys); int Platform_getUptime(void); -void Platform_getLoadAverage(double* one, double* five, double* fifteen); +float Platform_getTemp(void); + +float Platform_getFreq(void); + +void Platform_getLoadAverage(double *one, double *five, double *fifteen); int Platform_getMaxPid(void); -double Platform_setCPUValues(Meter* this, unsigned int cpu); +double Platform_setCPUValues(Meter *this, unsigned int cpu); -void Platform_setMemoryValues(Meter* this); +void Platform_setMemoryValues(Meter *this); -void Platform_setSwapValues(Meter* this); +void Platform_setSwapValues(Meter *this); -void Platform_setZramValues(Meter* this); +void Platform_setZramValues(Meter *this); -void Platform_setZfsArcValues(Meter* this); +void Platform_setZfsArcValues(Meter *this); -void Platform_setZfsCompressedArcValues(Meter* this); +void Platform_setZfsCompressedArcValues(Meter *this); -char* Platform_getProcessEnv(pid_t pid); +char *Platform_getProcessEnv(pid_t pid); -char* Platform_getInodeFilename(pid_t pid, ino_t inode); +char *Platform_getInodeFilename(pid_t pid, ino_t inode); -FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid); +FileLocks_ProcessData *Platform_getProcessLocks(pid_t pid); -void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred); +void Platform_getPressureStall(const char *file, bool some, double *ten, double *sixty, double *threehundred); -bool Platform_getDiskIO(DiskIOData* data); +bool Platform_getDiskIO(DiskIOData *data); -bool Platform_getNetworkIO(NetworkIOData* data); +bool Platform_getNetworkIO(NetworkIOData *data); -void Platform_getBattery(double* percent, ACPresence* isOnAC); +void Platform_getBattery(double *percent, ACPresence *isOnAC); -static inline void Platform_getHostname(char* buffer, size_t size) { +static inline void Platform_getHostname(char *buffer, size_t size) +{ Generic_hostname(buffer, size); } -static inline void Platform_getRelease(char** string) { +static inline void Platform_getRelease(char **string) +{ *string = Generic_uname(); } #ifdef HAVE_LIBCAP - #define PLATFORM_LONG_OPTIONS \ - {"drop-capabilities", optional_argument, 0, 160}, +#define PLATFORM_LONG_OPTIONS \ + {"drop-capabilities", optional_argument, 0, 160}, #else - #define PLATFORM_LONG_OPTIONS +#define PLATFORM_LONG_OPTIONS #endif -void Platform_longOptionsUsage(const char* name); +void Platform_longOptionsUsage(const char *name); -CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv); +CommandLineStatus Platform_getLongOption(int opt, int argc, char **argv); -static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) { +static inline void Platform_gettime_realtime(struct timeval *tv, uint64_t *msec) +{ Generic_gettime_realtime(tv, msec); } -static inline void Platform_gettime_monotonic(uint64_t* msec) { +static inline void Platform_gettime_monotonic(uint64_t *msec) +{ Generic_gettime_monotonic(msec); } -static inline Hashtable* Platform_dynamicMeters(void) { return NULL; } +static inline Hashtable *Platform_dynamicMeters(void) { return NULL; } -static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { } +static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable *table) {} -static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { } +static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter *meter) {} -static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { } +static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter *meter) {} -static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { } +static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter *meter, ATTR_UNUSED RichString *out) {} -static inline Hashtable* Platform_dynamicColumns(void) { return NULL; } +static inline Hashtable *Platform_dynamicColumns(void) { return NULL; } -static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { } +static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable *table) {} -static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { return NULL; } +static inline const char *Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { return NULL; } -static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) { return false; } +static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process *proc, ATTR_UNUSED RichString *str, ATTR_UNUSED unsigned int key) { return false; } #endif