Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more forgiving terminal selection for ncurses #2082

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions userspace/sysdig/csysdig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> terminal_types =
{
MOUSE_CAPABLE_TERM,
eterm,
"xterm",
"xterm-color"
};

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);
Expand Down
Loading