~ubuntu-branches/ubuntu/saucy/bzr/saucy

« back to all changes in this revision

Viewing changes to bzrlib/ui/text.py

  • Committer: Jelmer Vernooij
  • Date: 2012-12-13 17:46:53 UTC
  • mfrom: (3815.3552.5 upstream)
  • Revision ID: jelmer@samba.org-20121213174653-hy4ie5wue839uyq3
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import warnings
32
32
 
33
33
from bzrlib import (
 
34
    config,
34
35
    debug,
35
36
    progress,
36
37
    osutils,
155
156
            return index
156
157
 
157
158
 
 
159
opt_progress_bar = config.Option(
 
160
    'progress_bar', help='Progress bar type.',
 
161
    default_from_env=['BZR_PROGRESS_BAR'], default=None,
 
162
    invalid='error')
 
163
 
 
164
 
158
165
class TextUIFactory(UIFactory):
159
 
    """A UI factory for Text user interefaces."""
 
166
    """A UI factory for Text user interfaces."""
160
167
 
161
168
    def __init__(self,
162
169
                 stdin=None,
231
238
            password = self.stdin.readline()
232
239
            if not password:
233
240
                password = None
234
 
            elif password[-1] == '\n':
235
 
                password = password[:-1]
 
241
            else:
 
242
                password = password.decode(self.stdin.encoding)
 
243
 
 
244
                if password[-1] == '\n':
 
245
                    password = password[:-1]
236
246
        return password
237
247
 
238
248
    def get_password(self, prompt=u'', **kwargs):
266
276
        username = self.stdin.readline()
267
277
        if not username:
268
278
            username = None
269
 
        elif username[-1] == '\n':
270
 
            username = username[:-1]
 
279
        else:
 
280
            username = username.decode(self.stdin.encoding)
 
281
            if username[-1] == '\n':
 
282
                username = username[:-1]
271
283
        return username
272
284
 
273
285
    def make_progress_view(self):
279
291
        # do that.  otherwise, guess based on $TERM and tty presence.
280
292
        if self.is_quiet():
281
293
            return NullProgressView()
282
 
        elif os.environ.get('BZR_PROGRESS_BAR') == 'text':
283
 
            return TextProgressView(self.stderr)
284
 
        elif os.environ.get('BZR_PROGRESS_BAR') == 'none':
285
 
            return NullProgressView()
286
 
        elif progress._supports_progress(self.stderr):
287
 
            return TextProgressView(self.stderr)
288
 
        else:
289
 
            return NullProgressView()
 
294
        pb_type = config.GlobalStack().get('progress_bar')
 
295
        if pb_type == 'none': # Explicit requirement
 
296
            return NullProgressView()
 
297
        if (pb_type == 'text' # Explicit requirement
 
298
            or progress._supports_progress(self.stderr)): # Guess
 
299
            return TextProgressView(self.stderr)
 
300
        # No explicit requirement and no successful guess
 
301
        return NullProgressView()
290
302
 
291
303
    def _make_output_stream_explicit(self, encoding, encoding_type):
292
304
        if encoding_type == 'exact':