Skip to content

Commit 075de2d

Browse files
augusto2112labath
authored andcommitted
Save and restore previous terminal after setting the terminal for checking if terminal supports colors.
The call to "set_curterm" inside the "terminalHasColors" function breaks the EditLine configuration on some Linux distributions, causing certain characters that have functions bound to them to not show up and backspace to stop deleting characters (only visually). This patch ensures that term struct is restored after the routine for cheking if terminal supports colors is done, which fixes the aforementioned issue. Reviewed By: labath Differential Revision: https://reviews.llvm.org/D95230
1 parent bafe418 commit 075de2d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

llvm/lib/Support/Unix/Process.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ static bool terminalHasColors(int fd) {
336336
// First, acquire a global lock because these C routines are thread hostile.
337337
std::lock_guard<std::mutex> G(*TermColorMutex);
338338

339+
struct term *previous_term = set_curterm(nullptr);
339340
int errret = 0;
340341
if (setupterm(nullptr, fd, &errret) != 0)
341342
// Regardless of why, if we can't get terminfo, we shouldn't try to print
@@ -359,7 +360,7 @@ static bool terminalHasColors(int fd) {
359360

360361
// Now extract the structure allocated by setupterm and free its memory
361362
// through a really silly dance.
362-
struct term *termp = set_curterm(nullptr);
363+
struct term *termp = set_curterm(previous_term);
363364
(void)del_curterm(termp); // Drop any errors here.
364365

365366
// Return true if we found a color capabilities for the current terminal.

0 commit comments

Comments
 (0)