]>
Tony Duckles's Git Repositories (git.nynim.org) - svn2svn.git/blob - svn2svn/ui.py
1 # -*- coding: utf-8 -*-
3 """User interface functions."""
9 # First try to import the Mercurial implementation.
11 if getattr(mercurial
.ui
.ui(), 'termwidth', False):
12 termwidth
= mercurial
.ui
.ui().termwidth
14 from mercurial
.util
import termwidth
16 # Fallback to local copy of Mercurial's implementation.
18 if 'COLUMNS' in os
.environ
:
20 return int(os
.environ
['COLUMNS'])
24 import termios
, array
, fcntl
25 for dev
in (sys
.stdout
, sys
.stdin
):
30 arri
= fcntl
.ioctl(fd
, termios
.TIOCGWINSZ
, '\0' * 8)
31 return array
.array('h', arri
)[1]
50 def status(msg
, *args
, **kwargs
):
51 """Write a status message.
53 args are treated as substitutions for msg.
55 The following keyword arguments are allowed:
56 level : One of DEFAULT, VERBOSE or DEBUG.
57 linebreak: If True a new line is appended to msg (default: True).
58 truncate : Truncate output if larger then term width (default: True).
61 level
= kwargs
.get('level', DEFAULT
)
67 if kwargs
.get('linebreak', True):
68 msg
= '%s%s' % (msg
, os
.linesep
)
73 if kwargs
.get('truncate', True) and level
!= ERROR
:
74 add_newline
= msg
.endswith('\n')
75 msglines
= msg
.splitlines()
76 for no
, line
in enumerate(msglines
):
78 msglines
[no
] = line
[:width
-3]+"..."
79 msg
= os
.linesep
.join(msglines
)
81 msg
= '%s%s' % (msg
, os
.linesep
)
82 if isinstance(msg
, unicode):
83 msg
= msg
.encode('utf-8')
88 def update_config(options
):
89 """Update UI configuration."""
91 _level
= options
.verbosity