[meld/windows-fixes] misc, vc._vc: Request no visible console window on Windows (#496)




commit 5024c8f6ec775f169b12dab0d5410aa9185142ef
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Aug 10 13:47:39 2022 +1000

    misc, vc._vc: Request no visible console window on Windows (#496)
    
    This is an attempt to avoid having console windows show briefly every
    time we run a VC command on Windows.

 meld/misc.py   | 13 ++++++++++++-
 meld/vc/_vc.py | 19 +++++++++++++++----
 2 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index 18920e0f..ce84b55f 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -205,6 +205,15 @@ def shorten_names(*names: str) -> List[str]:
     return [name or _("[None]") for name in basenames]
 
 
+def get_hide_window_startupinfo():
+    if os.name != "nt":
+        return None
+
+    startupinfo = subprocess.STARTUPINFO()
+    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
+    return startupinfo
+
+
 SubprocessGenerator = Generator[Union[Tuple[int, str], None], None, None]
 
 
@@ -238,7 +247,9 @@ def read_pipe_iter(
             self.proc = subprocess.Popen(
                 command, cwd=workdir, stdin=subprocess.PIPE,
                 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
-                universal_newlines=True)
+                universal_newlines=True,
+                startupinfo=get_hide_window_startupinfo(),
+            )
             self.proc.stdin.close()
             childout, childerr = self.proc.stdout, self.proc.stderr
             bits: List[str] = []
diff --git a/meld/vc/_vc.py b/meld/vc/_vc.py
index 08c904cf..0ad4b9e4 100644
--- a/meld/vc/_vc.py
+++ b/meld/vc/_vc.py
@@ -34,6 +34,7 @@ from typing import ClassVar
 from gi.repository import Gio, GLib
 
 from meld.conf import _
+from meld.misc import get_hide_window_startupinfo
 
 # ignored, new, normal, ignored changes,
 # error, placeholder, vc added
@@ -163,7 +164,9 @@ class Vc:
         cmd = (self.CMD,) + args
         return subprocess.Popen(
             cmd, cwd=self.location, stdout=subprocess.PIPE,
-            universal_newlines=use_locale_encoding)
+            universal_newlines=use_locale_encoding,
+            startupinfo=get_hide_window_startupinfo(),
+        )
 
     def get_files_to_commit(self, paths):
         """Get a list of files that will be committed from paths
@@ -408,9 +411,12 @@ def popen(cmd, cwd=None, use_locale_encoding=True):
     text stream with universal newlines.
     If use_locale_encoding is False output is treated as binary stream.
     """
+
     process = subprocess.Popen(
         cmd, cwd=cwd, stdout=subprocess.PIPE,
-        universal_newlines=use_locale_encoding)
+        universal_newlines=use_locale_encoding,
+        startupinfo=get_hide_window_startupinfo(),
+    )
     return process.stdout
 
 
@@ -427,7 +433,9 @@ def call_temp_output(cmd, cwd, file_id='', suffix=None):
     of the temporary file's name.
     """
     process = subprocess.Popen(
-        cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+        startupinfo=get_hide_window_startupinfo(),
+    )
     vc_file = process.stdout
 
     # Error handling here involves doing nothing; in most cases, the only
@@ -443,7 +451,10 @@ def call_temp_output(cmd, cwd, file_id='', suffix=None):
 # Return the return value of a given command
 def call(cmd, cwd=None):
     devnull = open(os.devnull, "wb")
-    return subprocess.call(cmd, cwd=cwd, stdout=devnull, stderr=devnull)
+    return subprocess.call(
+        cmd, cwd=cwd, stdout=devnull, stderr=devnull,
+        startupinfo=get_hide_window_startupinfo(),
+    )
 
 
 base_re = re.compile(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]