]>
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]
34 # SGR foreground color codes
36 'BLACK': '30', 'BLACK_B': '90',
37 'RED': '31', 'RED_B': '91',
38 'GREEN': '32', 'GREEN_B': '92',
39 'YELLOW': '33', 'YELLOW_B': '93',
40 'BLUE': '34', 'BLUE_B': '94',
41 'MAGENTA': '35', 'MAGENTA_B': '95',
42 'CYAN': '36', 'CYAN_B': '96',
43 'WHITE': '37', 'WHITE_B': '97' }
48 def status(msg
, *args
, **kwargs
):
49 """Write a status message.
51 args are treated as substitutions for msg.
53 The following keyword arguments are allowed:
54 level : One of DEFAULT, VERBOSE or DEBUG.
55 linebreak: If True a new line is appended to msg (default: True).
56 truncate : Truncate output if larger then term width (default: False).
59 level
= kwargs
.get('level', DEFAULT
)
65 if kwargs
.get('linebreak', True):
66 msg
= '%s%s' % (msg
, os
.linesep
)
71 if kwargs
.get('truncate', False) and level
!= ERROR
:
72 add_newline
= msg
.endswith('\n')
73 msglines
= msg
.splitlines()
74 for no
, line
in enumerate(msglines
):
76 msglines
[no
] = line
[:width
-3]+"..."
77 msg
= os
.linesep
.join(msglines
)
79 msg
= '%s%s' % (msg
, os
.linesep
)
80 if isinstance(msg
, unicode):
81 msg
= msg
.encode('utf-8')
82 color
= kwargs
.get('color', None)
83 bold
= kwargs
.get('bold', None)
84 if color
in _colors
and os
.name
!= 'nt':
85 msg
= '%s%s%s' % ("\x1b["+_colors
[color
]+(";1" if bold
else "")+"m", msg
, "\x1b[0m")
89 def update_config(options
):
90 """Update UI configuration."""
92 _level
= options
.verbosity