Beispiel #1
0
    def __str__(self):
        """
        Create a string representation of this multi-diff
        """
        def limit(text, length):
            """Limit text to specified length, terminate color mode and add END_LONG_LINE if trimmed."""
            if len(text) > length:
                maxlen = length - len(END_LONG_LINE)
                res = text[:maxlen]
                if self.colored:
                    res += END_COLOR
                return res + END_LONG_LINE
            else:
                return text

        _, term_width = det_terminal_size()

        base = self.color_line(self.base_fn, PURPLE)
        filenames = ', '.join(map(os.path.basename, self.files))
        output = [
            "Comparing %s with %s" % (base, filenames),
            '=' * SEP_WIDTH,
        ]

        diff = False
        for i in range(len(self.base_lines)):
            lines = filter(None, self.get_line(i))
            if lines:
                output.append('\n'.join(
                    [limit(line, term_width) for line in lines]))
                diff = True

        if not diff:
            output.append("(no diff)")

        output.append('=' * SEP_WIDTH)

        return '\n'.join(output)
    def __str__(self):
        """
        Create a string representation of this multi-diff
        """
        def limit(text, length):
            """Limit text to specified length, terminate color mode and add END_LONG_LINE if trimmed."""
            if len(text) > length:
                maxlen = length - len(END_LONG_LINE)
                res = text[:maxlen]
                if self.colored:
                    res += END_COLOR
                return res + END_LONG_LINE
            else:
                return text

        _, term_width = det_terminal_size()

        base = self.color_line(self.base_fn, PURPLE)
        filenames = ', '.join(map(os.path.basename, self.files))
        output = [
            "Comparing %s with %s" % (base, filenames),
            '=' * SEP_WIDTH,
        ]

        diff = False
        for i in range(len(self.base_lines)):
            lines = filter(None, self.get_line(i))
            if lines:
                output.append('\n'.join([limit(line, term_width) for line in lines]))
                diff = True

        if not diff:
            output.append("(no diff)")

        output.append('=' * SEP_WIDTH)

        return '\n'.join(output)
Beispiel #3
0
 def test_det_terminal_size(self):
     """Test det_terminal_size function."""
     (height, width) = st.det_terminal_size()
     self.assertTrue(isinstance(height, int) and height >= 0)
     self.assertTrue(isinstance(width, int) and width >= 0)
 def test_det_terminal_size(self):
     """Test det_terminal_size function."""
     (height, width) = st.det_terminal_size()
     self.assertTrue(isinstance(height, int) and height > 0)
     self.assertTrue(isinstance(width, int) and width > 0)