diff options
author | Georg Brandl <georg@python.org> | 2008-01-27 20:23:25 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-27 20:23:25 +0000 |
commit | 4f7a8f3f9671298fde1f13438a066ea308c6813e (patch) | |
tree | d0d7e515e2bebd490ed62bc8e018f1a9819d7c0a /sphinx/util/console.py | |
parent | cf0dcada7103919438d8286f3c5ab5b65dcf08dc (diff) | |
download | sphinx-git-4f7a8f3f9671298fde1f13438a066ea308c6813e.tar.gz |
More refactoring:
* Move refcounting into an addon module.
* Rename the extension manager to Application and use it throughout.
* Fix some bugs found by pylint.
* Add "ifconfig" addon.
Diffstat (limited to 'sphinx/util/console.py')
-rw-r--r-- | sphinx/util/console.py | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/sphinx/util/console.py b/sphinx/util/console.py index 69c3d2bb2..ea41e2496 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -11,6 +11,30 @@ codes = {} +def get_terminal_width(): + """Borrowed from the py lib.""" + try: + import os, termios, fcntl, struct + call = fcntl.ioctl(0, termios.TIOCGWINSZ, "\000"*8) + height, width = struct.unpack("hhhh", call)[:2] + terminal_width = width + except (SystemExit, KeyboardInterrupt): + raise + except: + # FALLBACK + terminal_width = int(os.environ.get('COLUMNS', 80))-1 + return terminal_width + +_tw = get_terminal_width() + +def print_and_backspace(text, func): + if not codes: + # if no coloring, don't output fancy backspaces + func(text) + else: + func(text.ljust(_tw) + _tw * "\b") + + def nocolor(): codes.clear() @@ -31,8 +55,8 @@ _attrs = { 'blink': '05m', } -for name, value in _attrs.items(): - codes[name] = '\x1b[' + value +for _name, _value in _attrs.items(): + codes[_name] = '\x1b[' + _value _colors = [ ('black', 'darkgray'), @@ -49,5 +73,5 @@ for i, (dark, light) in enumerate(_colors): codes[dark] = '\x1b[%im' % (i+30) codes[light] = '\x1b[%i;01m' % (i+30) -for name in codes: - create_color_func(name) +for _name in codes: + create_color_func(_name) |