[PATCH] D95230: Save and restore previous terminal after setting the terminal for checking if terminal supports colors.

Augusto Noronha via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 06:35:00 PST 2021


augusto2112 created this revision.
augusto2112 added reviewers: labath, chandlerc, aprantl.
Herald added subscribers: dexonsmith, hiraditya.
augusto2112 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95230

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


Index: llvm/lib/Support/Unix/Process.inc
===================================================================
--- llvm/lib/Support/Unix/Process.inc
+++ llvm/lib/Support/Unix/Process.inc
@@ -332,6 +332,7 @@
   // 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
@@ -355,7 +356,7 @@
 
   // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95230.318510.patch
Type: text/x-patch
Size: 899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210122/7dfb8c92/attachment.bin>


More information about the llvm-commits mailing list