(self)
Do the actual printing.

        This prints the generated output in an aligned, pretty form. it aims
        for a total width of 160 characters, but will use whatever the tty
        reports it's value to be. Though this is much wider than the standard
        80 characters of terminals, and even than the newer 120, compressing
        it to those lengths makes the output hard to read.

        Each column will have a specific width, and will be line wrapped.
Do the actual printing.
Do the actual printing .
def print_aligned(self) -> None:
        """Do the actual printing.

        This prints the generated output in an aligned, pretty form. it aims
        for a total width of 160 characters, but will use whatever the tty
        reports it's value to be. Though this is much wider than the standard
        80 characters of terminals, and even than the newer 120, compressing
        it to those lengths makes the output hard to read.

        Each column will have a specific width, and will be line wrapped.
        """
        total_width = shutil.get_terminal_size(fallback=(160, 0))[0]
        _col = max(total_width // 5, 20)
        four_column = (_col, _col, _col, total_width - (3 * _col))
        # In this case we don't have the choices field, so we can redistribute
        # the extra 40 characters to val and desc
        three_column = (_col, _col * 2, total_width // 2)

        for line in zip(self.name_col, self.value_col, self.choices_col, self.descr_col):
            if not any(line):
                print('')
                continue

            # This is a header, like `Subproject foo:`,
            # We just want to print that and get on with it
            if line[0] and not any(line[1:]):
                print(line[0])
                continue

            # wrap will take a long string, and create a list of strings no
            # longer than the size given. Then that list can be zipped into, to
            # print each line of the output, such the that columns are printed
            # to the right width, row by row.
            if self.has_choices:
                name = textwrap.wrap(line[0], four_column[0])
                val = textwrap.wrap(line[1], four_column[1])
                choice = textwrap.wrap(line[2], four_column[2])
                desc = textwrap.wrap(line[3], four_column[3])
                for l in itertools.zip_longest(name, val, choice, desc, fillvalue=''):
                    # We must use the length modifier here to get even rows, as
                    # `textwrap.wrap` will only shorten, not lengthen each item
                    print('{:{widths[0]}} {:{widths[1]}} {:{widths[2]}} {}'.format(*l, widths=four_column))
            else:
                name = textwrap.wrap(line[0], three_column[0])
                val = textwrap.wrap(line[1], three_column[1])
                desc = textwrap.wrap(line[3], three_column[2])
                for l in itertools.zip_longest(name, val, desc, fillvalue=''):
                    print('{:{widths[0]}} {:{widths[1]}} {}'.format(*l, widths=three_column))
def print_aligned ( self ) -> None : total_width = shutil . get_terminal_size ( fallback = ( 160 , 0 ) ) [ 0 ] _col = max ( total_width // 5 , 20 ) four_column = ( _col , _col , _col , total_width - ( 3 * _col ) ) # In this case we don't have the choices field, so we can redistribute # the extra 40 characters to val and desc three_column = ( _col , _col * 2 , total_width // 2 ) for line in zip ( self . name_col , self . value_col , self . choices_col , self . descr_col ) : if not any ( line ) : print ( '' ) continue # This is a header, like `Subproject foo:`, # We just want to print that and get on with it if line [ 0 ] and not any ( line [ 1 : ] ) : print ( line [ 0 ] ) continue # wrap will take a long string, and create a list of strings no # longer than the size given. Then that list can be zipped into, to # print each line of the output, such the that columns are printed # to the right width, row by row. if self . has_choices : name = textwrap . wrap ( line [ 0 ] , four_column [ 0 ] ) val = textwrap . wrap ( line [ 1 ] , four_column [ 1 ] ) choice = textwrap . wrap ( line [ 2 ] , four_column [ 2 ] ) desc = textwrap . wrap ( line [ 3 ] , four_column [ 3 ] ) for l in itertools . zip_longest ( name , val , choice , desc , fillvalue = '' ) : # We must use the length modifier here to get even rows, as # `textwrap.wrap` will only shorten, not lengthen each item print ( '{:{widths[0]}} {:{widths[1]}} {:{widths[2]}} {}' . format ( * l , widths = four_column ) ) else : name = textwrap . wrap ( line [ 0 ] , three_column [ 0 ] ) val = textwrap . wrap ( line [ 1 ] , three_column [ 1 ] ) desc = textwrap . wrap ( line [ 3 ] , three_column [ 2 ] ) for l in itertools . zip_longest ( name , val , desc , fillvalue = '' ) : print ( '{:{widths[0]}} {:{widths[1]}} {}' . format ( * l , widths = three_column ) )