Esempio n. 1
0
def space_examples(list_examples, rows):
    """ makes the example text """
    examples_with_index = []

    for i, _ in list(enumerate(list_examples)):
        examples_with_index.append("[" + str(i + 1) + "] " +
                                   list_examples[i][0] + list_examples[i][1])

    example = "".join(exam for exam in examples_with_index)
    num_newline = example.count('\n')

    page_number = ''
    if num_newline > rows * PART_SCREEN_EXAMPLE:
        len_of_excerpt = math.floor(float(rows) * PART_SCREEN_EXAMPLE)

        group = example.split('\n')
        end = int(get_section() * len_of_excerpt)
        begin = int((get_section() - 1) * len_of_excerpt)

        if get_section() * len_of_excerpt < num_newline:
            example = '\n'.join(group[begin:end]) + "\n"
        else:  # default chops top off
            example = '\n'.join(group[begin:]) + "\n"
            while ((get_section() - 1) * len_of_excerpt) > num_newline:
                sub_section()
        page_number = '\n' + str(get_section()) + "/" + str(
            math.ceil(num_newline / len_of_excerpt))

    return example + page_number
Esempio n. 2
0
def space_examples(list_examples, rows):
    """ makes the example text """
    examples_with_index = []

    for i, _ in list(enumerate(list_examples)):
        examples_with_index.append("[" + str(i + 1) + "] " + list_examples[i][0] +
                                   list_examples[i][1])

    example = "".join(exam for exam in examples_with_index)
    num_newline = example.count('\n')

    page_number = ''
    if num_newline > rows * PART_SCREEN_EXAMPLE:
        len_of_excerpt = math.floor(float(rows) * PART_SCREEN_EXAMPLE)

        group = example.split('\n')
        end = int(get_section() * len_of_excerpt)
        begin = int((get_section() - 1) * len_of_excerpt)

        if get_section() * len_of_excerpt < num_newline:
            example = '\n'.join(group[begin:end]) + "\n"
        else:  # default chops top off
            example = '\n'.join(group[begin:]) + "\n"
            while ((get_section() - 1) * len_of_excerpt) > num_newline:
                sub_section()
        page_number = '\n' + str(get_section()) + "/" + str(math.ceil(num_newline / len_of_excerpt))

    return example + page_number
Esempio n. 3
0
    def space_examples(self, list_examples, rows):
        """ makes the example text """
        examples_with_index = []
        for i in range(len(list_examples)):
            examples_with_index.append("[" + str(i + 1) + "]" + list_examples[i][0] +\
            list_examples[i][1])

        example = "".join(exam for exam in examples_with_index)
        num_newline = example.count('\n')
        if num_newline > rows / 3:
            len_of_excerpt = math.floor(rows / 3)
            group = example.split('\n')
            end = int(get_section() * len_of_excerpt)
            begin = int((get_section() - 1) * len_of_excerpt)

            if get_section() * len_of_excerpt < num_newline:
                example = '\n'.join(group[begin:end]) + "\n"
            else: # default chops top off
                example = '\n'.join(group[begin:]) + "\n"
                while ((get_section() - 1) * len_of_excerpt) > num_newline:
                    sub_section()
        return example
    def generate_help_text(self, text):
        """ generates the help text based on commands typed """
        command = param_descrip = example = ""
        any_documentation = False
        is_command = True
        rows, _ = get_window_dim()
        rows = int(rows)
        if not self.completer:
            return param_descrip, example

        for word in text.split():
            if word.startswith("-"):
                # any parameter
                is_command = False
            if is_command:
                command += str(word) + " "

            if self.completer and self.completer.is_completable(
                    command.rstrip()):
                cmdstp = command.rstrip()
                any_documentation = True

                if word in self.completer.command_parameters[
                        cmdstp] and self.completer.has_description(cmdstp +
                                                                   " " + word):
                    param_descrip = word + ":\n" + \
                        self.completer.param_description.get(cmdstp + " " + word, '')

                self.description_docs = u'{}'.format(
                    self.completer.command_description[cmdstp])

                if cmdstp in self.completer.command_examples:
                    string_example = ""
                    for example in self.completer.command_examples[cmdstp]:
                        for part in example:
                            string_example += part
                    example = space_examples(
                        self.completer.command_examples[cmdstp], rows,
                        get_section())

        if not any_documentation:
            self.description_docs = u''
        return param_descrip, example
Esempio n. 5
0
    def generate_help_text(self, text):
        """ generates the help text based on commands typed """
        command = param_descrip = example = ""
        any_documentation = False
        is_command = True
        rows, _ = get_window_dim()
        rows = int(rows)
        if not self.completer:
            return param_descrip, example

        for word in text.split():
            if word.startswith("-"):
                # any parameter
                is_command = False
            if is_command:
                command += str(word) + " "

            if self.completer and self.completer.is_completable(command.rstrip()):
                cmdstp = command.rstrip()
                any_documentation = True

                if word in self.completer.command_parameters[cmdstp] and self.completer.has_description(
                        cmdstp + " " + word):
                    param_descrip = word + ":\n" + \
                        self.completer.param_description.get(cmdstp + " " + word, '')

                self.description_docs = u'{}'.format(
                    self.completer.command_description[cmdstp])

                if cmdstp in self.completer.command_examples:
                    string_example = ""
                    for example in self.completer.command_examples[cmdstp]:
                        for part in example:
                            string_example += part
                    example = space_examples(
                        self.completer.command_examples[cmdstp], rows, get_section())

        if not any_documentation:
            self.description_docs = u''
        return param_descrip, example