def get_detail(self, source, depth, row_idx): result = RowData(start=row_idx) ellipsis = ' ...' reserved = stringWidth(ellipsis, const.FONT, const.FONT_SIZE_SMALL) max_width = const.PAGE_WIDTH - ((depth + 2) * const.INDENT) - reserved get_width = lambda text, font=const.FONT, size=const.FONT_SIZE_SMALL: \ stringWidth(text, font, size) options = '' options += '-b ' if source['ignore_space_change'] else '' options += '-w ' if source['ignore_whitespaces'] else '' options += '-B ' if source['ignore_blank_lines'] else '' options += '-u ' if source['unified'] else '' options += '-c ' if source['context'] and not source['unified'] else '' options = ' ( ' + options + ')' if options else '' detailed_text = [] if source['passed'] else [ ('*** a.text ***', self._get_truncated_lines(source['first'], const.NUM_DISPLAYED_ROWS)), ('*** b.text ***', self._get_truncated_lines(source['second'], const.NUM_DISPLAYED_ROWS)) ] detailed_text.append( ('No difference found{}'.format(options) if source['passed'] else 'Differences{}:'.format(options), [] if source['passed'] else self._get_truncated_lines( source['delta'], const.NUM_DISPLAYED_ROWS * 5))) for title, body in detailed_text: title_line = RowData(content=title, start=row_idx, style=RowStyle( font=(const.FONT, const.FONT_SIZE_SMALL), left_padding=const.INDENT * (depth + 1), text_color=colors.black if source['passed'] else colors.red)) result += title_line row_idx = title_line.end for flag, line in body: lines = split_line(line, max_width, get_width) body_text = RowData( content=[ # Be aware of the case len(line) == 0 lines[0] + ellipsis if len(lines) > 1 else line, '', '', '' ], start=row_idx, style=RowStyle( font=(const.FONT, const.FONT_SIZE_SMALL), left_padding=const.INDENT * (depth + 2), top_padding=0, bottom_padding=const.COMPACT_LINE_SPACING, text_color=colors.gray if flag else colors.black)) result += body_text row_idx = body_text.end return result
def get_detail(self, source, depth, row_idx): result = RowData(start=row_idx) ellipsis = " ..." reserved = stringWidth(ellipsis, const.FONT, const.FONT_SIZE_SMALL) max_width = const.PAGE_WIDTH - ((depth + 2) * const.INDENT) - reserved def get_width(text, font=const.FONT, size=const.FONT_SIZE_SMALL): return stringWidth(text, font, size) options = "" options += "-b " if source["ignore_space_change"] else "" options += "-w " if source["ignore_whitespaces"] else "" options += "-B " if source["ignore_blank_lines"] else "" options += "-u " if source["unified"] else "" options += "-c " if source["context"] and not source["unified"] else "" options = " ( " + options + ")" if options else "" detailed_text = ([] if source["passed"] else [ ( "*** a.text ***", self._get_truncated_lines(source["first"], const.NUM_DISPLAYED_ROWS), ), ( "*** b.text ***", self._get_truncated_lines(source["second"], const.NUM_DISPLAYED_ROWS), ), ]) detailed_text.append(( "No difference found{}".format(options) if source["passed"] else "Differences{}:".format(options), [] if source["passed"] else self._get_truncated_lines( source["delta"], const.NUM_DISPLAYED_ROWS * 5), )) for title, body in detailed_text: title_line = RowData( content=title, start=row_idx, style=RowStyle( font=(const.FONT, const.FONT_SIZE_SMALL), left_padding=const.INDENT * (depth + 1), text_color=colors.black if source["passed"] else colors.red, ), ) result += title_line row_idx = title_line.end for flag, line in body: lines = split_line(line, max_width, get_width) body_text = RowData( content=[ # Be aware of the case len(line) == 0 lines[0] + ellipsis if len(lines) > 1 else line, "", "", "", ], start=row_idx, style=RowStyle( font=(const.FONT, const.FONT_SIZE_SMALL), left_padding=const.INDENT * (depth + 2), top_padding=0, bottom_padding=const.COMPACT_LINE_SPACING, text_color=colors.gray if flag else colors.black, ), ) result += body_text row_idx = body_text.end return result