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