Proposed fix for the reported terminal issue in PR25007.
- Save the current term settings before doing the check for color support.
- Restore the term settings after the tests (or if the test fails).
This fixes the reported issue for me (with vim-clang-complete), and keeps the original terminal color detection working (-f[no-]color-diagnostics).
I chose to duplicate the cleanup logic (set_curterm(OrigTerm)) twice (once on the error path and once on the normal path) instead of restructuring the function to keep the patch simpler.
Another option would be to use the already set up term in case set_curterm returns non-NULL term, but I felt this approach is safer (and closer to the original logic).
Please don't cite PRs in comments. The comment line above is sufficient.