]> granicus.if.org Git - clang/commitdiff
[clang-format] Don't flash an ugly cmd prompt in Vim on Windows
authorReid Kleckner <reid@kleckner.net>
Mon, 10 Jun 2013 14:16:26 +0000 (14:16 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 10 Jun 2013 14:16:26 +0000 (14:16 +0000)
Reviewers: klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D941

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183654 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-format/clang-format.py

index bc47fcbb7d2e080562d8bdcc96c016c6b618e8e0..60e2e550289c5e15644a60a746af08b8577212b5 100644 (file)
@@ -19,6 +19,7 @@
 
 import json
 import subprocess
+import sys
 import vim
 
 # Change this to the full path if clang-format is not on the path.
@@ -39,11 +40,18 @@ offset = int(vim.eval('line2byte(' +
 length = int(vim.eval('line2byte(' +
                       str(vim.current.range.end + 2) + ')')) - offset - 2
 
+# Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.
+startupinfo = None
+if sys.platform.startswith('win32'):
+  startupinfo = subprocess.STARTUPINFO()
+  startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+  startupinfo.wShowWindow = subprocess.SW_HIDE
+
 # Call formatter.
 p = subprocess.Popen([binary, '-offset', str(offset), '-length', str(length),
                       '-style', style, '-cursor', str(cursor)],
                      stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                     stdin=subprocess.PIPE)
+                     stdin=subprocess.PIPE, startupinfo=startupinfo)
 stdout, stderr = p.communicate(input=text)
 
 # If successful, replace buffer contents.