Commit 53f3ba22 authored by Ronny Eichler's avatar Ronny Eichler
Browse files

Use Python 3 terminal size detection (works for Windows)

parent e3361618
......@@ -3,8 +3,8 @@
from __future__ import print_function
import os
from termcolor import colored
import re
from termcolor import colored
def fmt_size(num, unit='B', si=True, sep=' ', col=False, pad=0):
colors = {"k": "blue", "M": "green", "G": "red", "T": "cyan",
......@@ -24,6 +24,7 @@ def fmt_size(num, unit='B', si=True, sep=' ', col=False, pad=0):
return "{:5.0f}{}{}{} ".format(num, sep, prefix, unit, pad=pad-6)
num /= divisor
def fext(fname):
"""Grabs the file extension of a file.
......@@ -73,7 +74,7 @@ def dir_size(path):
return total_size
def terminal_size():
"""Get size of currently used terminal. In many cases this is inaccruate.
"""Get size of currently used terminal. In many cases this is inaccurate.
Returns:
Tuple of width, height.
......@@ -81,7 +82,10 @@ def terminal_size():
Raises:
Unknown error when not run from a terminal.
"""
return map(int, os.popen('stty size', 'r').read().split())
# return map(int, os.popen('stty size', 'r').read().split())
# Python 3.3+
ts = os.get_terminal_size()
return ts.lines, ts.columns
def _find_getch():
"""Helper to wait for a single character press, instead of having to use raw_input() requiring Enter
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment