/*
htop - CRT.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
#include "config.h" // IWYU pragma: keep
#include "CRT.h"
#include <errno.h>
#include <langinfo.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "ProvideCurses.h"
#include "XUtils.h"
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>
#endif
#define ColorIndex(i,j) ((7-(i))*8+(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 Magenta COLOR_MAGENTA
#define Cyan COLOR_CYAN
#define White COLOR_WHITE
#define ColorPairGrayBlack ColorPair(Magenta,Magenta)
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
#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] = "-",
};
#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", // ▽
};
bool CRT_utf8 = false;
#endif
const char* const* CRT_treeStr = CRT_treeStrAscii;
static const int* CRT_delay;
const char* CRT_degreeSign;
static const char* initDegreeSign(void) {
#ifdef HAVE_LIBNCURSESW
if (CRT_utf8)
return "\xc2\xb0";
static char buffer[4];
// this might fail if the current locale does not support wide characters
int r = snprintf(buffer, sizeof(buffer), "%lc", 176);
if (r > 0)
return buffer;
#endif
return "";
}
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_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,