MCPcopy Index your code
hub / github.com/gitless-vcs/gitless / _highlight

Function _highlight

gitless/cli/pprint.py:341–372  ·  view source on GitHub ↗

Returns the sections that should be bolded in the given lines. Returns: two tuples. Each tuple indicates the start and end of the section of the line that should be bolded for line1 and line2 respectively.

(line1, line2)

Source from the content-addressed store, hash-verified

339
340
341def _highlight(line1, line2):
342 """Returns the sections that should be bolded in the given lines.
343
344 Returns:
345 two tuples. Each tuple indicates the start and end of the section
346 of the line that should be bolded for line1 and line2 respectively.
347 """
348 start1 = start2 = 0
349 match = re.search(r'\S', line1) # ignore leading whitespace
350 if match:
351 start1 = match.start()
352 match = re.search(r'\S', line2)
353 if match:
354 start2 = match.start()
355 length = min(len(line1), len(line2)) - 1
356 bold_start1 = start1
357 bold_start2 = start2
358 while (bold_start1 <= length and bold_start2 <= length and
359 line1[bold_start1] == line2[bold_start2]):
360 bold_start1 += 1
361 bold_start2 += 1
362 match = re.search(r'\s*$', line1) # ignore trailing whitespace
363 bold_end1 = match.start() - 1
364 match = re.search(r'\s*$', line2)
365 bold_end2 = match.start() - 1
366 while (bold_end1 >= bold_start1 and bold_end2 >= bold_start2 and
367 line1[bold_end1] == line2[bold_end2]):
368 bold_end1 -= 1
369 bold_end2 -= 1
370 if bold_start1 - start1 > 0 or len(line1) - 1 - bold_end1 > 0:
371 return (bold_start1 + 1, bold_end1 + 2), (bold_start2 + 1, bold_end2 + 2)
372 return None, None

Callers 1

_hunkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected