Пример #1
0
def get_help_string(unit, brief=False, width=None):
    """
    Retrieves the help string from a given refinery unit.
    """
    if brief:
        return terminalfit(documentation(unit), width=width)
    else:
        from io import StringIO
        try:
            argp = unit(_terminal_width=width).argp
        except ArgparseError as fail:
            argp = fail.parser
        buffer = StringIO('w')
        argp.print_help(buffer)
        info = buffer.getvalue()
        return info
Пример #2
0
    def test_terminalfit(self):
        @inspect.getdoc
        class data:
            """
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed venenatis ac urna id ultricies. Integer eu semper mauris. Nunc sed
            nunc non ante volutpat egestas. Nam nec risus sed ex dignissim pharetra. Integer vel augue erat. Vivamus hendrerit convallis
            tortor in varius. Morbi sed nulla eget turpis volutpat maximus id vitae nisi:

            1. Aenean ullamcorper egestas lorem ornare ultrices.
            2. Donec quis gravida orci.
            3. Fusce auctor, orci sit amet vehicula varius, elit dolor feugiat nisl, at congue sapien sapien ut felis. Etiam pharetra est
               non turpis facilisis ullamcorper.

            Ut quis ipsum varius, pellentesque mauris nec, rutrum quam. Proin dictum neque ut sem hendrerit, nec lobortis sem scelerisque.
            Nullam eget justo in nunc lacinia porttitor eget nec quam. Morbi volutpat egestas risus, eget malesuada nulla vulputate eu. Cras
            leo ipsum, porttitor et malesuada a, laoreet nec metus:

            - Donec porttitor suscipit dapibus.
            - Phasellus sodales erat id imperdiet rutrum.
            - Vestibulum in augue vel libero tempor vestibulum.
            """

        @inspect.getdoc
        class wish:
            """
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed venenatis ac urna id
            ultricies. Integer eu semper mauris. Nunc sed nunc non ante volutpat egestas. Nam nec
            risus sed ex dignissim pharetra. Integer vel augue erat. Vivamus hendrerit convallis
            tortor in varius. Morbi sed nulla eget turpis volutpat maximus id vitae nisi:

            1. Aenean ullamcorper egestas lorem ornare ultrices.
            2. Donec quis gravida orci.
            3. Fusce auctor, orci sit amet vehicula varius, elit dolor feugiat nisl, at congue
               sapien sapien ut felis. Etiam pharetra est non turpis facilisis ullamcorper.

            Ut quis ipsum varius, pellentesque mauris nec, rutrum quam. Proin dictum neque ut sem
            hendrerit, nec lobortis sem scelerisque. Nullam eget justo in nunc lacinia porttitor eget
            nec quam. Morbi volutpat egestas risus, eget malesuada nulla vulputate eu. Cras leo ipsum,
            porttitor et malesuada a, laoreet nec metus:

            - Donec porttitor suscipit dapibus.
            - Phasellus sodales erat id imperdiet rutrum.
            - Vestibulum in augue vel libero tempor vestibulum.
            """

        self.assertEqual(tools.terminalfit(data, width=90), wish)
Пример #3
0
def get_help_string(unit, brief=False, width=None):
    """
    Retrieves the help string from a given refinery unit.
    """
    if brief:
        return terminalfit(documentation(unit), width=width)
    else:
        from io import StringIO
        from os import environ
        try:
            environ['REFINERY_TERMSIZE'] = str(width)
            argp = unit.argparser()
        except ArgparseError as fail:
            argp = fail.parser
        buffer = StringIO('w')
        argp.print_help(buffer)
        info = buffer.getvalue()
        return info
Пример #4
0
def get_help_string(unit, brief=False, width=None):
    """
    Retrieves the help string from a given refinery unit.
    """
    if brief:
        return terminalfit(documentation(unit), width=width)
    else:
        from io import StringIO
        from refinery.lib.environment import environment
        _ts = environment.term_size.value
        environment.term_size.value = width
        try:
            argp = unit.argparser()
        except ArgparseError as fail:
            argp = fail.parser
        else:
            buffer = StringIO('w')
            argp.print_help(buffer)
            info = buffer.getvalue()
            return info
        finally:
            environment.term_size.value = _ts
Пример #5
0
 def add_text(self, text):
     if isinstance(text, str):
         text = terminalfit(text, width=get_terminal_size())
     return super().add_text(text)
Пример #6
0
 def process(self, data: str) -> str:
     return terminalfit(data, self.args.delta, self.args.width)