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



commit 7d5bbb74d43901252e598c0fcd37548abb48c170
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 |  6 +++++-
 2 files changed, 17 insertions(+), 2 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..30e4c576 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
@@ -408,9 +409,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
 
 


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