diff mercurial/util.py @ 13734:16118b4859a1

util: add Mac-specific check whether we're in a GUI session (issue2553) The previous test assumed that 'os.name' was "mac" on Mac OS X. This is not the case; 'mac' was classic Mac OS, whereas Mac OS X has 'os.name' be 'posix'. Please note that this change will break Mercurial on hypothetical non-Mac OS X deployments of Darwin. Credit to Brodie Rao for thinking of CGSessionCopyCurrentDictionary() and Kevin Bullock for testing.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Wed, 23 Mar 2011 09:43:34 +0100
parents d724a69309e0
children bc7b5d1c1999
line wrap: on
line diff
--- a/mercurial/util.py	Wed Mar 23 01:14:43 2011 +0100
+++ b/mercurial/util.py	Wed Mar 23 09:43:34 2011 +0100
@@ -769,7 +769,18 @@
 
 def gui():
     '''Are we running in a GUI?'''
-    return os.name == "nt" or os.name == "mac" or os.environ.get("DISPLAY")
+    if sys.platform == 'darwin':
+        if 'SSH_CONNECTION' in os.environ:
+            # handle SSH access to a box where the user is logged in
+            return False
+        elif getattr(osutil, 'isgui', None):
+            # check if a CoreGraphics session is available
+            return osutil.isgui()
+        else:
+            # pure build; use a safe default
+            return True
+    else:
+        return os.name == "nt" or os.environ.get("DISPLAY")
 
 def mktempcopy(name, emptyok=False, createmode=None):
     """Create a temporary file with the same contents from name