utils.sys.get_terminal_columns_n

Here are the examples of the python api utils.sys.get_terminal_columns_n taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: promptastic Source File: promptastic.py
    def _compute_padding_length_first_line(self):
        """
        Compute the padding length, which is the number of empty spaces to place between
        the left part and the right part.
        """
        # Check whether the right part starts with a Divider.
        right_starts_w_divider = (True if self.first_line_right and
                                  isinstance(self.first_line_right[0], basics.Divider) else False)

        # Terminal width.
        cols = get_terminal_columns_n()

        # Total length of the text (without the initial divider of the right part, in case).
        text_len = (self._get_total_segments_length(self.first_line_left) +
                    self._get_total_segments_length(self.first_line_right))
        text_len -= basics.Divider().length() if right_starts_w_divider else 0

        # Padding dimension formula.
        padding_len = cols - (text_len % cols)

        # If the padding length is exactly one column, then we don't need padding at all.
        if padding_len == cols:
            padding_len = 0
            # And we also don't need the initial divider in the right part.
            if right_starts_w_divider:
                self.first_line_right.pop(0)
        # Else: remove from padding_len the length of the initial divider, in case.
        else:
            padding_len -= basics.Divider().length() if right_starts_w_divider else 0

        return padding_len