diff --git a/.travis.yml b/.travis.yml index 6938b6a..684c922 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,20 @@ language: python +sudo: false python: 3.5 -env: - matrix: - - TOXENV=py26 - - TOXENV=py27 - - TOXENV=py33 - - TOXENV=py34 - - TOXENV=py35 - - TOXENV=hg35 - - TOXENV=hg36 - - TOXENV=hg41 - - TOXENV=coverage +matrix: + include: + - python: 2.7 + env: TOXENV=py27 + - python: 3.3 + env: TOXENV=py33 + - python: 3.4 + env: TOXENV=py34 + - python: 3.5 + env: TOXENV=py35 + - env: TOXENV=hg35 + - env: TOXENV=hg36 + - env: TOXENV=hg41 + - env: TOXENV=hg42 + - env: TOXENV=coverage install: pip install docutils tox script: tox diff --git a/src/diff_highlight.py b/src/diff_highlight.py index 4bb2e0d..e8b9dfd 100644 --- a/src/diff_highlight.py +++ b/src/diff_highlight.py @@ -14,8 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from hgext import color -from mercurial import extensions +from mercurial import extensions, ui, util from mercurial.i18n import _ from highlights.pprint import INSERTED, DELETED, pprint_hunk @@ -25,7 +24,7 @@ DELETE_EMPH = 'diff.deleted_highlight' -class colorui(color.colorui): +class colorui(ui.ui): hunk = None tab = None @@ -89,23 +88,37 @@ def uisetup(ui): return try: - extensions.find('color') - except KeyError: - ui.warn(_("warning: 'diff-highlight' requires 'color' extension " - "to be enabled, but not\n")) - return + from hgext import color as colorext + + try: + extensions.find('color') + except KeyError: + ui.warn(_("warning: 'diff-highlight' requires 'color' extension " + "to be enabled, but not\n")) + return + except ImportError: + colorext = None + try: + from mercurial import color + except ImportError: + pass if not isinstance(ui, colorui): colorui.__bases__ = (ui.__class__,) ui.__class__ = colorui + ver = tuple(int(s) if s.isdigit() else s for s in util.version().split('.')) + def colorconfig(orig, *args, **kwargs): ret = orig(*args, **kwargs) - try: - from mercurial.color import _styles as styles - except ImportError: + if ver < (4, 1): + styles = colorext._styles + elif ver < (4, 2): styles = color._styles + else: + styles = color._defaultstyles + if INSERT_EMPH not in styles: styles[INSERT_EMPH] = styles[INSERT_NORM] + ' inverse' @@ -114,4 +127,4 @@ def colorconfig(orig, *args, **kwargs): return ret - extensions.wrapfunction(color, 'configstyles', colorconfig) + extensions.wrapfunction(colorext if ver < (4, 2) else color, 'configstyles', colorconfig) diff --git a/tests/test_diff_highlight.py b/tests/test_diff_highlight.py index 57ce452..f7df1d3 100644 --- a/tests/test_diff_highlight.py +++ b/tests/test_diff_highlight.py @@ -7,10 +7,16 @@ import unittest if sys.version_info < (3, 0): + try: + from hgext import color + + colorext = color + except ImportError: + colorext = None try: from mercurial import color except ImportError: - from hgext import color + pass from diff_highlight import colorui from mercurial.util import version as mercurial_version else: @@ -20,12 +26,24 @@ class TestDiffHighlight(unittest.TestCase): @unittest.skipIf(color is None, "mercurial is not supported py3") def test_colorui(self): - import curses - curses.setupterm("xterm", 1) - color._styles['diff.inserted_highlight'] = 'green inverse' - color._styles['diff.deleted_highlight'] = 'red inverse' + try: + import curses + + curses.setupterm("xterm", 1) + except ImportError: + pass ui = colorui() + if mercurial_version() >= "4.2.0": + ui.setconfig('ui', 'color', 'always') + color.setup(ui) + styles = ui._styles + else: + colorui.__bases__ = (colorext.colorui,) + styles = color._styles + styles['diff.inserted_highlight'] = 'green inverse' + styles['diff.deleted_highlight'] = 'red inverse' + if mercurial_version() >= "3.7.0": ui.pushbuffer(labeled=True) else: @@ -44,13 +62,22 @@ def test_colorui(self): ui.write(" ", '') ui.write("\n", '') - stop = "\x1b(B\x1b[m" + if mercurial_version() >= "4.2.0": + stop = "\x1b[0m" + + def start(*colors): + return "\x1b[0;" + ";".join(str(c) for c in colors) + "m" + + def restart(*colors): + return stop + start(*colors) + else: + stop = "\x1b(B\x1b[m" - def start(*colors): - return stop + "".join("\x1b[%dm" % c for c in colors) + def start(*colors): + return stop + "".join("\x1b[%dm" % c for c in colors) - def restart(*colors): - return stop + start(*colors) + def restart(*colors): + return stop + start(*colors) if mercurial_version() >= "3.7.0": lines = ui.popbuffer().splitlines() diff --git a/tox.ini b/tox.ini index c28ba24..d38641c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py26,py27,py32,py33,py34,py35,hg35,hg36,hg41 +envlist=py26,py27,py32,py33,py34,py35,hg35,hg36,hg41,hg42 [testenv] deps= @@ -71,6 +71,12 @@ deps= {[testenv:py3_common]deps} mercurial<4.2 +[testenv:hg42] +basepython= python2.7 +deps= + {[testenv:py3_common]deps} + mercurial<4.3 + [testenv:coverage] basepython= python2.7 deps=