color: don't fail on error messages when no curses (issue4237) stable
authorMads Kiilerich <madski@unity3d.com>
Sat, 03 May 2014 03:29:30 +0200
branchstable
changeset 21227 75aaae8ad660
parent 21226 4898c37e03c0
child 21229 54d7657d7d1e
color: don't fail on error messages when no curses (issue4237) The error only occured when Python didn't have curses - such as on Windows and when Python was built without curses support. No curses can also be emulated by (re)moving .../lib/python2.7/curses/ from the Python installation. It is left as an exercise to figure out exactly what changed in Mercurial that triggered this error.
hgext/color.py
tests/test-status-color.t
--- a/hgext/color.py	Sat May 03 10:33:54 2014 +0200
+++ b/hgext/color.py	Sat May 03 03:29:30 2014 +0200
@@ -230,7 +230,7 @@
                         'cyan': (False, curses.COLOR_CYAN),
                         'white': (False, curses.COLOR_WHITE)}
 except ImportError:
-    _terminfo_params = False
+    _terminfo_params = {}
 
 _styles = {'grep.match': 'red bold',
            'grep.linenumber': 'green',
--- a/tests/test-status-color.t	Sat May 03 10:33:54 2014 +0200
+++ b/tests/test-status-color.t	Sat May 03 03:29:30 2014 +0200
@@ -319,4 +319,17 @@
   \x1b[0;31;1mU a\x1b[0m (esc)
   \x1b[0;32;1mR b\x1b[0m (esc)
 
+color coding of error message with current availability of curses
+
+  $ hg unknowncommand > /dev/null
+  hg: unknown command 'unknowncommand'
+  [255]
+
+color coding of error message without curses
+
+  $ echo 'raise ImportError' > curses.py
+  $ PYTHONPATH=`pwd`:$PYTHONPATH hg unknowncommand > /dev/null
+  hg: unknown command 'unknowncommand'
+  [255]
+
   $ cd ..