From 733acad9c69ab6c8905a9e4274b51a5f6cc82eb1 Mon Sep 17 00:00:00 2001 From: Aaron John Date: Sat, 22 Jun 2024 14:06:57 -0700 Subject: [PATCH] Move termType check into its own function Co-authored-by: Benny Baumann --- CRT.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CRT.c b/CRT.c index 149cd519..63df1cec 100644 --- a/CRT.c +++ b/CRT.c @@ -1001,6 +1001,27 @@ void CRT_setMouse(bool enabled) { } #endif +static bool terminalSupportsDefinedKeys(const char* termType) { + if (!termType) { + return false; + } + + switch (termType[0]) { + case 'v': + if (String_eq(termType, "vt220")) { + return true; + } + break; + case 'x': + if (String_eq(termType, "xterm")) { + return true; + } + break; + } + + return false; +} + void CRT_init(const Settings* settings, bool allowUnicode, bool retainScreenOnExit) { initscr(); @@ -1046,7 +1067,7 @@ void CRT_init(const Settings* settings, bool allowUnicode, bool retainScreenOnEx CRT_scrollHAmount = 5; } - if (termType && (String_startsWith(termType, "xterm") || String_eq(termType, "vt220"))) { + if (terminalSupportsDefinedKeys(termType)) { #ifdef HTOP_NETBSD #define define_key(s_, k_) define_key((char*)s_, k_) IGNORE_WCASTQUAL_BEGIN