]>
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]
37 _debug_showcmd
= False
40 def status(msg
, *args
, **kwargs
):
41 """Write a status message.
43 args are treated as substitutions for msg.
45 The following keyword arguments are allowed:
46 level : One of DEFAULT, VERBOSE or DEBUG.
47 linebreak: If True a new line is appended to msg (default: True).
48 truncate : Truncate output if larger then term width (default: True).
51 level
= kwargs
.get('level', DEFAULT
)
57 if kwargs
.get('linebreak', True):
58 msg
= '%s%s' % (msg
, os
.linesep
)
63 if kwargs
.get('truncate', True) and level
!= ERROR
:
64 add_newline
= msg
.endswith('\n')
65 msglines
= msg
.splitlines()
66 for no
, line
in enumerate(msglines
):
68 msglines
[no
] = line
[:width
-3]+"..."
69 msg
= os
.linesep
.join(msglines
)
71 msg
= '%s%s' % (msg
, os
.linesep
)
72 if isinstance(msg
, unicode):
73 msg
= msg
.encode('utf-8')
78 def update_config(options
):
79 """Update UI configuration."""
80 global _level
,_debug_showcmd
81 _level
= options
.verbosity
82 _debug_showcmd
= options
.showcmd