Misc CRT cleanup

This commit is contained in:
Christian Göttsche 2020-12-14 15:45:48 +01:00 committed by BenBE
parent c9583c692d
commit 61b8e31b41
2 changed files with 28 additions and 37 deletions

48
CRT.c
View File

@ -41,28 +41,26 @@ in the source distribution for its full text.
#define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorPairGrayBlack ColorPair(Magenta,Magenta)
#define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta)
static const char* const CRT_treeStrAscii[TREE_STR_COUNT] = { static const char* const CRT_treeStrAscii[LAST_TREE_STR] = {
"-", // TREE_STR_HORZ [TREE_STR_VERT] = "|",
"|", // TREE_STR_VERT [TREE_STR_RTEE] = "`",
"`", // TREE_STR_RTEE [TREE_STR_BEND] = "`",
"`", // TREE_STR_BEND [TREE_STR_TEND] = ",",
",", // TREE_STR_TEND [TREE_STR_OPEN] = "+",
"+", // TREE_STR_OPEN [TREE_STR_SHUT] = "-",
"-", // TREE_STR_SHUT
}; };
#ifdef HAVE_LIBNCURSESW #ifdef HAVE_LIBNCURSESW
static const char* const CRT_treeStrUtf8[TREE_STR_COUNT] = { static const char* const CRT_treeStrUtf8[LAST_TREE_STR] = {
"\xe2\x94\x80", // TREE_STR_HORZ ─ [TREE_STR_VERT] = "\xe2\x94\x82", // │
"\xe2\x94\x82", // TREE_STR_VERT │ [TREE_STR_RTEE] = "\xe2\x94\x9c", // ├
"\xe2\x94\x9c", // TREE_STR_RTEE ├ [TREE_STR_BEND] = "\xe2\x94\x94", // └
"\xe2\x94\x94", // TREE_STR_BEND └ [TREE_STR_TEND] = "\xe2\x94\x8c", // ┌
"\xe2\x94\x8c", // TREE_STR_TEND ┌ [TREE_STR_OPEN] = "+", // +, TODO use 🮯 'BOX DRAWINGS LIGHT HORIZONTAL
"+", // TREE_STR_OPEN +, TODO use 🮯 'BOX DRAWINGS LIGHT HORIZONTAL // WITH VERTICAL STROKE' (U+1FBAF, "\xf0\x9f\xae\xaf") when
// WITH VERTICAL STROKE' (U+1FBAF, "\xf0\x9f\xae\xaf") when // Unicode 13 is common
// Unicode 13 is common [TREE_STR_SHUT] = "\xe2\x94\x80", // ─
"\xe2\x94\x80", // TREE_STR_SHUT ─
}; };
bool CRT_utf8 = false; bool CRT_utf8 = false;
@ -92,7 +90,7 @@ static const char* initDegreeSign(void) {
const int* CRT_colors; const int* CRT_colors;
int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[COLORSCHEME_DEFAULT] = { [COLORSCHEME_DEFAULT] = {
[RESET_COLOR] = ColorPair(White, Black), [RESET_COLOR] = ColorPair(White, Black),
[DEFAULT_COLOR] = ColorPair(White, Black), [DEFAULT_COLOR] = ColorPair(White, Black),
@ -604,9 +602,7 @@ int CRT_scrollHAmount = 5;
int CRT_scrollWheelVAmount = 10; int CRT_scrollWheelVAmount = 10;
const char* CRT_termType; ColorScheme CRT_colorScheme = COLORSCHEME_DEFAULT;
int CRT_colorScheme = 0;
ATTR_NORETURN ATTR_NORETURN
static void CRT_handleSIGTERM(int sgn) { static void CRT_handleSIGTERM(int sgn) {
@ -673,14 +669,14 @@ void CRT_init(const int* delay, int colorScheme, bool allowUnicode) {
start_color(); start_color();
} }
CRT_termType = getenv("TERM"); const char* termType = getenv("TERM");
if (String_eq(CRT_termType, "linux")) { if (termType && String_eq(termType, "linux")) {
CRT_scrollHAmount = 20; CRT_scrollHAmount = 20;
} else { } else {
CRT_scrollHAmount = 5; CRT_scrollHAmount = 5;
} }
if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) { if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) {
define_key("\033[H", KEY_HOME); define_key("\033[H", KEY_HOME);
define_key("\033[F", KEY_END); define_key("\033[F", KEY_END);
define_key("\033[7~", KEY_HOME); define_key("\033[7~", KEY_HOME);
@ -752,7 +748,7 @@ void CRT_done() {
} }
void CRT_fatalError(const char* note) { void CRT_fatalError(const char* note) {
char* sysMsg = strerror(errno); const char* sysMsg = strerror(errno);
CRT_done(); CRT_done();
fprintf(stderr, "%s: %s\n", note, sysMsg); fprintf(stderr, "%s: %s\n", note, sysMsg);
exit(2); exit(2);

17
CRT.h
View File

@ -16,26 +16,25 @@ in the source distribution for its full text.
typedef enum TreeStr_ { typedef enum TreeStr_ {
TREE_STR_HORZ,
TREE_STR_VERT, TREE_STR_VERT,
TREE_STR_RTEE, TREE_STR_RTEE,
TREE_STR_BEND, TREE_STR_BEND,
TREE_STR_TEND, TREE_STR_TEND,
TREE_STR_OPEN, TREE_STR_OPEN,
TREE_STR_SHUT, TREE_STR_SHUT,
TREE_STR_COUNT LAST_TREE_STR
} TreeStr; } TreeStr;
typedef enum ColorSchemes_ { typedef enum ColorScheme_ {
COLORSCHEME_DEFAULT = 0, COLORSCHEME_DEFAULT,
COLORSCHEME_MONOCHROME, COLORSCHEME_MONOCHROME,
COLORSCHEME_BLACKONWHITE, COLORSCHEME_BLACKONWHITE,
COLORSCHEME_LIGHTTERMINAL, COLORSCHEME_LIGHTTERMINAL,
COLORSCHEME_MIDNIGHT, COLORSCHEME_MIDNIGHT,
COLORSCHEME_BLACKNIGHT, COLORSCHEME_BLACKNIGHT,
COLORSCHEME_BROKENGRAY, COLORSCHEME_BROKENGRAY,
LAST_COLORSCHEME, LAST_COLORSCHEME
} ColorSchemes; } ColorScheme;
typedef enum ColorElements_ { typedef enum ColorElements_ {
RESET_COLOR, RESET_COLOR,
@ -144,17 +143,13 @@ extern const char* const* CRT_treeStr;
extern const int* CRT_colors; extern const int* CRT_colors;
extern int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT];
extern int CRT_cursorX; extern int CRT_cursorX;
extern int CRT_scrollHAmount; extern int CRT_scrollHAmount;
extern int CRT_scrollWheelVAmount; extern int CRT_scrollWheelVAmount;
extern const char* CRT_termType; extern ColorScheme CRT_colorScheme;
extern int CRT_colorScheme;
#ifdef HAVE_SETUID_ENABLED #ifdef HAVE_SETUID_ENABLED