Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 25 additions & 12 deletions src/diff_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -25,7 +24,7 @@
DELETE_EMPH = 'diff.deleted_highlight'


class colorui(color.colorui):
class colorui(ui.ui):
hunk = None
tab = None

Expand Down Expand Up @@ -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'

Expand All @@ -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)
47 changes: 37 additions & 10 deletions tests/test_diff_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
Expand Down