changeset 30650:ae37e395a110

color: drop use of the 'global' keyword for _terminfo_params Using 'global' is usually a bad sign. Here it is used so that one can empty the content of a dict at the global scope. We '_terminfo_params.clear()' and drop the global.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 18 Nov 2016 18:27:13 +0100
parents b0a0f7b9ed90
children 27e48410380d
files hgext/color.py
diffstat 1 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/color.py	Wed Dec 21 13:51:34 2016 -0800
+++ b/hgext/color.py	Fri Nov 18 18:27:13 2016 +0100
@@ -197,7 +197,6 @@
 def _terminfosetup(ui, mode):
     '''Initialize terminfo data and the terminal if we're in terminfo mode.'''
 
-    global _terminfo_params
     # If we failed to load curses, we go ahead and return.
     if not _terminfo_params:
         return
@@ -215,7 +214,7 @@
     try:
         curses.setupterm()
     except curses.error as e:
-        _terminfo_params = {}
+        _terminfo_params.clear()
         return
 
     for key, (b, e, c) in _terminfo_params.items():
@@ -232,11 +231,9 @@
         if mode == "terminfo":
             ui.warn(_("no terminfo entry for setab/setaf: reverting to "
               "ECMA-48 color\n"))
-        _terminfo_params = {}
+        _terminfo_params.clear()
 
 def _modesetup(ui, coloropt):
-    global _terminfo_params
-
     if coloropt == 'debug':
         return 'debug'
 
@@ -281,13 +278,13 @@
             ui.warn(_('warning: failed to set color mode to %s\n') % mode)
 
     if realmode == 'win32':
-        _terminfo_params = {}
+        _terminfo_params.clear()
         if not w32effects:
             modewarn()
             return None
         _effects.update(w32effects)
     elif realmode == 'ansi':
-        _terminfo_params = {}
+        _terminfo_params.clear()
     elif realmode == 'terminfo':
         _terminfosetup(ui, mode)
         if not _terminfo_params: