Returns the number of lines and columns of the current terminal.
    It attempts several strategies to determine the size and if all fail,
    it returns (80, 25).

    :rtype:  int, int
    :return: The rows and columns of the terminal.
19266
def get_terminal_size(default_rows=25, default_cols=80):
    
    # Collect a list of viable input channels that may tell us something
    # about the terminal dimensions.
    fileno_list = []
    try:
        fileno_list.append(sys.stdout.fileno())
    except AttributeError:
        # Channel was redirected to an object that has no fileno()
        pass
    except ValueError:
        # Channel was closed while attemting to read it
        pass
    try:
        fileno_list.append(sys.stdin.fileno())
    except AttributeError:
        pass
    except ValueError:
        # Channel was closed while attemting to read it
        pass
    try:
        fileno_list.append(sys.stderr.fileno())
    except AttributeError:
        pass
    except ValueError:
        # Channel was closed while attemting to read it
        pass

    # Ask each channel for the terminal window size.
    for fd in fileno_list:
        try:
            rows, cols = _get_terminal_size(fd)
        except TypeError:
            # _get_terminal_size() returned None.
            pass
        else:
            return rows, cols

    # Try os.ctermid()
    try:
        fd = os.open(os.ctermid(), os.O_RDONLY)
    except AttributeError:
        # os.ctermid does not exist on Windows.
        pass
    except OSError:
        # The device pointed to by os.ctermid() does not exist.
        pass
    else:
        try:
            rows, cols = _get_terminal_size(fd)
        except TypeError:
            # _get_terminal_size() returned None.
            pass
        else:
            return rows, cols
        finally:
            os.close(fd)

    # Try `stty size`
    with open(os.devnull, 'w') as devnull:
        try:
            process = Popen(['stty', 'size'], stderr=devnull, stdout=PIPE,
                            close_fds=True)
        except (OSError, ValueError):
            pass
        else:
            errcode = process.wait()
            output = process.stdout.read()
            try:
                rows, cols = output.split()
                return int(rows), int(cols)
            except (ValueError, TypeError):
                pass

    # Try environment variables.
    try:
        return tuple(int(os.getenv(var)) for var in ('LINES', 'COLUMNS'))
    except (ValueError, TypeError):
        pass

    # Give up.
    return default_rows, default_cols
148283
def line_range(self):
        
        num_lines = len(self.text().split('\n'))
        end_line = self._start_line + num_lines - 1
        return (self._start_line, end_line)
162716
def draw(self):
        
        n_rows, n_cols = self.term.stdscr.getmaxyx()
        if n_rows < self.term.MIN_HEIGHT or n_cols < self.term.MIN_WIDTH:
            # TODO: Will crash when you try to navigate if the terminal is too
            # small at startup because self._subwindows will never be populated
            return

        self._row = 0
        self._draw_header()
        self._draw_banner()
        self._draw_content()
        self._draw_footer()
        self.term.clear_screen()
        self.term.stdscr.refresh()
1115424
def _get_size(fileno):
    # Thanks to fabric (fabfile.org), and
    # http://sqizit.bartletts.id.au/2011/02/14/pseudo-terminals-in-python/
    
    # Inline imports, because these modules are not available on Windows.
    # (This file is used by ConEmuOutput, which is used on Windows.)
    import fcntl
    import termios

    # Buffer for the C call
    buf = array.array(b'h' if six.PY2 else u'h', [0, 0, 0, 0])

    # Do TIOCGWINSZ (Get)
    # Note: We should not pass 'True' as a fourth parameter to 'ioctl'. (True
    #       is the default.) This causes segmentation faults on some systems.
    #       See: https://github.com/jonathanslenders/python-prompt-toolkit/pull/364
    fcntl.ioctl(fileno, termios.TIOCGWINSZ, buf)

    # Return rows, cols
    return buf[0], buf[1]
535633
def mem_size(self):
        
        result = self.shell.execute(self.commands.mem_size.value)
        stdout = self.shell.decode(result['stdout'])
        stderr = self.shell.decode(result['stderr'])
        return int(stdout)
755595
def terminal_width():
    """"""
    try:
        if os.name == 'nt':
            _WindowsCSBI.initialize()
            return _WindowsCSBI.get_info(_WindowsCSBI.HANDLE_STDOUT)['terminal_width']
        return struct.unpack('hhhh', fcntl.ioctl(0, termios.TIOCGWINSZ, '\000' * 8))[1]
    except IOError:
        return 80
1146719
def _term_size(self):
        
        for fd in (0, 1, 2):
            try:
                return self._ioctl_GWINSZ(fd)
            except:
                pass
        # try os.ctermid()
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            try:
                return self._ioctl_GWINSZ(fd)
            finally:
                os.close(fd)
        except:
            pass
        # try `stty size`
        try:
            return tuple(int(x) for x in os.popen("stty size", "r").read().split())
        except:
            pass
        # try environment variables
        try:
            return tuple(int(os.getenv(var)) for var in ("LINES", "COLUMNS"))
        except:
            pass
        # i give up. return default.
        return (25, 80)
736140
def GetNumberOfRows(self):
    
    if not self._database_object:
      raise IOError('Not opened.')

    if self._number_of_rows is None:
      self._number_of_rows = self._database_object.GetNumberOfRows(
          self._table_name)

    return self._number_of_rows
1122848
def terminal_size():  # decide on *some* terminal size
    """"""
    cr = _ioctl_GWINSZ(0) or _ioctl_GWINSZ(
        1) or _ioctl_GWINSZ(2)  # try open fds
    if not cr:                                                  # ...then ctty
        try:
            fd = os.open(os.ctermid(), os.O_RDONLY)
            cr = _ioctl_GWINSZ(fd)
            os.close(fd)
        except BaseException:
            pass
        if not cr:                            # env vars or finally defaults
            try:
                cr = os.environ['LINES'], os.environ['COLUMNS']
            except BaseException:
                cr = 25, 80
    return int(cr[1]), int(cr[0])
1251266
def get_linenumbertable(self):
          # noqa

        lnt = self._lnt
        if lnt is None:
            buff = self.get_attribute("LineNumberTable")
            if buff is None:
                lnt = tuple()
            else:
                with unpack(buff) as up:
                    lnt = tuple(up.unpack_struct_array(_HH))
            self._lnt = lnt
        return lnt
932136
def num_col(self):
        
        ret = ctypes.c_uint()
        _check_call(_LIB.XGDMatrixNumCol(self.handle,
                                         ctypes.byref(ret)))
        return ret.value
1305453
def col_widths(self):
        # type: () -> defaultdict
        
        _widths = defaultdict(int)

        all_rows = [self.headers]
        all_rows.extend(self._rows)

        for row in all_rows:
            for idx, col in enumerate(row):
                _col_l = len(col)
                if _col_l > _widths[idx]:
                    _widths[idx] = _col_l

        return _widths
403494
def columnize(items, width=None, file=sys.stdout):
    
    if not items:
        return
    if width is None:
        width = shutil.get_terminal_size()[0] if file is sys.stdout else 80
    items = [rendering.vtmlrender(x) for x in items]
    maxcol = max(items, key=len)
    colsize = len(maxcol) + 2
    cols = width // colsize
    if cols < 2:
        for x in items:
            print(x, file=file)
        return
    lines = math.ceil(len(items) / cols)
    for i in range(lines):
        row = items[i:None:lines]
        print(*[x.ljust(colsize) for x in row], sep='', file=file)
117788
def size(self):
        
        if self._size is None:
            self._size = sum(s.len for s in self.statements if type(s) is stmt.IMark)
        return self._size
841610
def get_relativelinenumbertable(self):
        

        lnt = self.get_linenumbertable()
        if lnt:
            lineoff = lnt[0][1]
            return tuple((o, l - lineoff) for (o, l) in lnt)
        else:
            return tuple()
935271
def terminal_size(self):
        """"""
        try:
            _, columns = os.popen('stty size', 'r').read().split()
            return min(int(columns) - 10, 100)
        except ValueError:
            return self.default_terminal_size
879749
def _size_36():
    
    from shutil import get_terminal_size
    dim = get_terminal_size()
    if isinstance(dim, list):
        return dim[0], dim[1]
    return dim.lines, dim.columns