[PATCH] D15077: [PATCH] Save and restore current term setting in terminalHasColors(). PR25007
Péter Radics via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 11 06:17:04 PST 2015
mitchnull updated this revision to Diff 42518.
mitchnull added a comment.
removed the ref to the PR from the comment
http://reviews.llvm.org/D15077
Files:
lib/Support/Unix/Process.inc
Index: lib/Support/Unix/Process.inc
===================================================================
--- lib/Support/Unix/Process.inc
+++ lib/Support/Unix/Process.inc
@@ -353,11 +353,15 @@
// First, acquire a global lock because these C routines are thread hostile.
MutexGuard G(*TermColorMutex);
+ // Save the current term (if set) to be restored after the test.
+ struct term *OrigTerm = set_curterm((struct term *)nullptr);
int errret = 0;
- if (setupterm((char *)nullptr, fd, &errret) != 0)
+ if (setupterm((char *)nullptr, fd, &errret) != 0) {
// Regardless of why, if we can't get terminfo, we shouldn't try to print
// colors.
+ (void)set_curterm(OrigTerm);
return false;
+ }
// Test whether the terminal as set up supports color output. How to do this
// isn't entirely obvious. We can use the curses routine 'has_colors' but it
@@ -375,8 +379,9 @@
bool HasColors = tigetnum(const_cast<char *>("colors")) > 0;
// Now extract the structure allocated by setupterm and free its memory
- // through a really silly dance.
- struct term *termp = set_curterm((struct term *)nullptr);
+ // through a really silly dance. Also restore the previously saved term
+ // here.
+ struct term *termp = set_curterm(OrigTerm);
(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: D15077.42518.patch
Type: text/x-patch
Size: 1407 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151211/fab0a97b/attachment.bin>
More information about the llvm-commits
mailing list