From 729c1368ca048088fff29711af3e6b529f377dfc Mon Sep 17 00:00:00 2001 From: Loris Degioanni Date: Tue, 9 Apr 2024 15:29:40 -0700 Subject: [PATCH 1/2] more forgiving terminal selection for ncurses: try more capable terminals first, and revert to more basic terminals if they don't work Signed-off-by: Loris Degioanni --- userspace/sysdig/csysdig.cpp | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/userspace/sysdig/csysdig.cpp b/userspace/sysdig/csysdig.cpp index 4b48f02561..767ac2a068 100644 --- a/userspace/sysdig/csysdig.cpp +++ b/userspace/sysdig/csysdig.cpp @@ -754,21 +754,45 @@ sysdig_init_res csysdig_init(int argc, char **argv) #ifndef NOCURSESUI if(output_type == chisel_table::OT_CURSES) { + char* eterm = getenv("TERM"); + + std::vector terminal_types = + { + MOUSE_CAPABLE_TERM, + eterm, + "xterm-color", + "xterm" + }; + + SCREEN* screen = NULL; + + if(force_term_compat) + { + terminal_types.clear(); + terminal_types.push_back(MOUSE_CAPABLE_TERM_COMPAT); + } + // - // Check if terminal has mouse support + // Try some of the most capable terminals, reverting to basic + // xterm if none works // - const char* mct = force_term_compat? MOUSE_CAPABLE_TERM_COMPAT : MOUSE_CAPABLE_TERM; - terminal_with_mouse = (tgetent(NULL, mct) != 0); + for(const auto& term : terminal_types) + { + screen = newterm(term.c_str(), stdout, stdin); + if(screen != NULL) + { + break; + } + } - if(terminal_with_mouse) + if(screen == NULL) { - // - // Enable fine-grained mouse activity capture by setting xterm-1002 - // - setenv("TERM", mct, 1); + fprintf(stderr, "Error: Failed to initialize terminal.\n"); + exit(1); } - (void) initscr(); // initialize the curses library + set_term(screen); + (void) nonl(); // tell curses not to do NL->CR/NL on output intrflush(stdscr, false); keypad(stdscr, true); From 3de412503d54cd77c410f59b51c9aaf6e9197161 Mon Sep 17 00:00:00 2001 From: Loris Degioanni Date: Tue, 9 Apr 2024 15:51:04 -0700 Subject: [PATCH 2/2] minor reordering of terminal selection Signed-off-by: Loris Degioanni --- userspace/sysdig/csysdig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/userspace/sysdig/csysdig.cpp b/userspace/sysdig/csysdig.cpp index 767ac2a068..8c038fab1c 100644 --- a/userspace/sysdig/csysdig.cpp +++ b/userspace/sysdig/csysdig.cpp @@ -760,8 +760,8 @@ sysdig_init_res csysdig_init(int argc, char **argv) { MOUSE_CAPABLE_TERM, eterm, - "xterm-color", - "xterm" + "xterm", + "xterm-color" }; SCREEN* screen = NULL;