python-lottie  0.6.11+deved4e6c7
A framework to work with lottie files and telegram animated stickers (tgs)
linediff.py
Go to the documentation of this file.
1 from io import StringIO
2 from difflib import SequenceMatcher
3 from ..exporters import prettyprint
4 
5 
6 def difflines_str(a, b, widtha=None, widthb=None):
7  lines_a = a.splitlines()
8  lines_b = b.splitlines()
9  ia = 0
10  ib = 0
11 
12  if widtha is None:
13  widtha = max(map(len, lines_a))
14  if widthb is None:
15  widthb = max(map(len, lines_b))
16 
17  for ja, jb, size in SequenceMatcher(None, lines_a, lines_b, False).get_matching_blocks():
18  sideprinter(lines_a[ia:ja], lines_b[ib:jb], widtha, widthb, "\x1b[31m>", "=", "<\x1b[m")
19  ia = ja+size
20  ib = jb+size
21  sideprinter(lines_a[ja:ia], lines_b[jb:ib], widtha, widthb, "\x1b[m ", "|", " \x1b[m")
22 
23 
24 def sideprinter(left, right, widtha=40, widthb=40, prefix="", infix=" | ", suffix=""):
25  if len(left) > len(right):
26  right += [""] * (len(left) - len(right))
27  else:
28  left += [""] * (len(right) - len(left))
29  for l, r in zip(left, right):
30  print("".join([prefix, l[:widtha].ljust(widtha), infix, r[:widthb].ljust(widthb), suffix]))
31 
32 
33 def difflines(a, b, widtha=None, widthb=None):
34  ioa = StringIO()
35  prettyprint(a, ioa)
36  iob = StringIO()
37  prettyprint(b, iob)
38  difflines_str(ioa.getvalue(), iob.getvalue(), widtha, widthb)
def prettyprint(lottie_object, out=sys.stdout, indent=" ", _i="")
Definition: pretty_print.py:14
def difflines_str(a, b, widtha=None, widthb=None)
Definition: linediff.py:6
def difflines(a, b, widtha=None, widthb=None)
Definition: linediff.py:33
def sideprinter(left, right, widtha=40, widthb=40, prefix="", infix=" | ", suffix="")
Definition: linediff.py:24