]>
Tony Duckles's Git Repositories (git.nynim.org) - svn2svn.git/blob - svn2svn/ui.py
1 """ User interface functions """
7 if 'COLUMNS' in os
.environ
:
9 return int(os
.environ
['COLUMNS'])
13 import termios
, array
, fcntl
14 for dev
in (sys
.stdout
, sys
.stdin
):
19 arri
= fcntl
.ioctl(fd
, termios
.TIOCGWINSZ
, '\0' * 8)
20 return array
.array('h', arri
)[1]
39 def status(msg
, *args
, **kwargs
):
40 """Write a status message.
42 args are treated as substitutions for msg.
44 The following keyword arguments are allowed:
45 level : One of DEFAULT, VERBOSE or DEBUG.
46 linebreak: If True a new line is appended to msg (default: True).
47 truncate : Truncate output if larger then term width (default: True).
50 level
= kwargs
.get('level', DEFAULT
)
56 if kwargs
.get('linebreak', True):
57 msg
= '%s%s' % (msg
, os
.linesep
)
62 if kwargs
.get('truncate', True) and level
!= ERROR
:
63 add_newline
= msg
.endswith('\n')
64 msglines
= msg
.splitlines()
65 for no
, line
in enumerate(msglines
):
67 msglines
[no
] = line
[:width
-3]+"..."
68 msg
= os
.linesep
.join(msglines
)
70 msg
= '%s%s' % (msg
, os
.linesep
)
71 if isinstance(msg
, unicode):
72 msg
= msg
.encode('utf-8')
77 def update_config(options
):
78 """Update UI configuration."""
80 _level
= options
.verbosity