[llvm] 075de2d - Save and restore previous terminal after setting the terminal for checking if terminal supports colors.

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 11 01:47:13 PST 2021


Author: Augusto Noronha
Date: 2021-03-11T10:47:06+01:00
New Revision: 075de2d8a7567a6a39e8477407960aa2545b68c2

URL: https://github.com/llvm/llvm-project/commit/075de2d8a7567a6a39e8477407960aa2545b68c2
DIFF: https://github.com/llvm/llvm-project/commit/075de2d8a7567a6a39e8477407960aa2545b68c2.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/Support/Unix/Process.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 291eaad65ec0..c3d8f7001de3 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -336,6 +336,7 @@ static bool terminalHasColors(int fd) {
   // First, acquire a global lock because these C routines are thread hostile.
   std::lock_guard<std::mutex> G(*TermColorMutex);
 
+  struct term *previous_term = set_curterm(nullptr);
   int errret = 0;
   if (setupterm(nullptr, fd, &errret) != 0)
     // Regardless of why, if we can't get terminfo, we shouldn't try to print
@@ -359,7 +360,7 @@ static bool terminalHasColors(int fd) {
 
   // Now extract the structure allocated by setupterm and free its memory
   // through a really silly dance.
-  struct term *termp = set_curterm(nullptr);
+  struct term *termp = set_curterm(previous_term);
   (void)del_curterm(termp); // Drop any errors here.
 
   // Return true if we found a color capabilities for the current terminal.


        


More information about the llvm-commits mailing list