Example #1
0
def get_terminal_size():
    """
    Try to determine terminal size at run time. If that is not possible,
    returns the default size of 80x24.
    """
    try:
        sz = _get_terminal_size()
    except ValueError:
        """
        This can result from the 'underlying buffer being detached', which
        occurs during running the unittest on Windows (but not on Linux?)
        """
        terminal_size = namedtuple('Terminal_Size', 'columns lines')
        sz = terminal_size(80, 24)

    return sz
Example #2
0
            def inner():
                try:
                    # shutil.get_terminal_size was added to the standard
                    # library in Python 3.3
                    try:
                        from shutil import get_terminal_size as _get_terminal_size  # pylint: disable=no-name-in-module
                    except ImportError:
                        from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size  # pylint: disable=import-error

                    size = _get_terminal_size()
                except ValueError:
                    # This can result from the 'underlying buffer being detached', which
                    # occurs during running the unittest on Windows (but not on Linux?)
                    terminal_size = namedtuple('Terminal_Size', 'columns lines')
                    size = terminal_size(80, 24)

                return size
Example #3
0
def get_terminal_size():
    """Returns terminal dimensions
    :return: Returns ``(width, height)``.  If there's no terminal
             to be found, we'll just return ``(80, 24)``.
    """
    try:
        # shutil.get_terminal_size was added to the standard
        # library in Python 3.3
        try:
            from shutil import get_terminal_size as _get_terminal_size  # pylint: disable=no-name-in-module
        except ImportError:
            from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size  # pylint: disable=import-error

        sz = _get_terminal_size()
    except ValueError:
        """
        This can result from the 'underlying buffer being detached', which
        occurs during running the unittest on Windows (but not on Linux?)
        """
        terminal_size = namedtuple('Terminal_Size', 'columns lines')
        sz = terminal_size(80, 24)

    return sz
Example #4
0
def get_terminal_size(defaultx=80, defaulty=25):
    return _get_terminal_size((defaultx, defaulty))