Skip to content

Commit

Permalink
Real change set to demo almost all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ymattw committed Nov 10, 2024
1 parent 2cf801f commit 89f02ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ydiff
Term based tool to view *colored*, *incremental* diff in a version controlled
workspace (supports Git, Mercurial, Perforce and Svn so far) or from stdin,
with *side by side* (similar to ``diff -y``) and *auto pager* support. Requires
python3 and ``less``.
python >= 3.0 and ``less`` as a pager.

.. image:: https://github.com/ymattw/ydiff/blob/master/img/side-by-side.png
:alt: side by side
Expand Down
17 changes: 8 additions & 9 deletions ydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Color(object):
FG_BRIGHT_CYAN = '\x1b[96m'


# Build a tuple for easy comparing by ANSI color codes
# Build a tuple for easy comparison of ANSI escape sequences
COLOR_CODES = tuple(v for k, v in vars(Color).items()
if not k.startswith('__') and not callable(v))

Expand Down Expand Up @@ -144,20 +144,19 @@ def strsplit(text, width):
return first, second, first_width


def strtrim(text, width, wrap_marker, pad):
def strtrim(text, width, wrap_char, pad):
r"""strtrim() trims given string respecting the escape sequences (using
strsplit), so that if text is larger than width, it's trimmed to have
width-1 chars plus wrap_marker. Additionally, if pad is True, short strings
width-1 chars plus wrap_char. Additionally, if pad is True, short strings
are padded with space to have exactly needed width.
Returns resulting string.
"""
text, _, tlen = strsplit(text, width + 1)
if tlen > width:
text, _, _ = strsplit(text, width - 1)
text += wrap_marker
text += wrap_char
elif pad:
# The string is short enough, but it might need to be padded.
text = '%s%*s' % (text, width - tlen, '')
return text

Expand Down Expand Up @@ -409,11 +408,11 @@ def __init__(self, side_by_side=False, width=0, tab_width=8, wrap=False,
def markup(self, diff):
"""Returns a generator"""
if self._side_by_side:
for line in self._markup_side_by_side(diff):
yield line
it = self._markup_side_by_side
else:
for line in self._markup_unified(diff):
yield line
it = self._markup_unified
for line in it(diff):
yield line

def _markup_unified(self, diff):
"""Returns a generator"""
Expand Down

0 comments on commit 89f02ac

Please sign in to comment.