30
30
breezy in batch mode or for programs such as loggerhead.
32
32
breezy.ui.CannedInputUIFactory
33
For use in testing; the input values to be returned are provided
33
For use in testing; the input values to be returned are provided
36
36
breezy.ui.text.TextUIFactory
48
from breezy.lazy_import import lazy_import
48
from ..lazy_import import lazy_import
49
49
lazy_import(globals(), """
50
50
from breezy import (
57
from ..sixish import (
59
64
_valid_boolean_strings = dict(yes=True, no=False,
84
89
if accepted_values is None:
85
90
accepted_values = _valid_boolean_strings
87
if type(s) in (str, unicode):
92
if isinstance(s, string_types):
89
94
val = accepted_values[s.lower()]
236
241
def is_quiet(self):
237
242
return self._quiet
239
def make_output_stream(self, encoding=None, encoding_type=None):
244
def make_output_stream(self, encoding=None, encoding_type='replace'):
240
245
"""Get a stream for sending out bulk text data.
242
247
This is used for commands that produce bulk text, such as log or diff
243
248
output, as opposed to user interaction. This should work even for
244
249
non-interactive user interfaces. Typically this goes to a decorated
245
version of stdout, but in a GUI it might be appropriate to send it to a
250
version of stdout, but in a GUI it might be appropriate to send it to a
246
251
window displaying the text.
248
:param encoding: Unicode encoding for output; if not specified
249
uses the configured 'output_encoding' if any; otherwise the
253
The caller may flush but should not close the returned stream.
255
:param encoding: Unicode encoding for output; if not specified
256
uses the configured 'output_encoding' if any; otherwise the
251
258
(See get_terminal_encoding.)
253
260
:param encoding_type: How to handle encoding errors:
254
261
replace/strict/escape/exact. Default is replace.
256
# XXX: is the caller supposed to close the resulting object?
258
encoding = config.GlobalStack().get('output_encoding')
260
encoding = osutils.get_terminal_encoding(trace=True)
261
if encoding_type is None:
262
encoding_type = 'replace'
263
263
out_stream = self._make_output_stream_explicit(encoding, encoding_type)
264
264
return out_stream
319
319
fail = "brz warning: %r, %r" % (warning_id, message_args)
320
320
warnings.warn("no template for warning: " + fail) # so tests will fail etc
321
return text_type(fail)
323
return template % message_args
324
except ValueError, e:
323
return text_type(template) % message_args
324
except ValueError as e:
325
325
fail = "brz unprintable warning: %r, %r, %s" % (
326
326
warning_id, message_args, e)
327
327
warnings.warn(fail) # so tests will fail etc
328
return text_type(fail)
330
330
def choose(self, msg, choices, default=None):
331
331
"""Prompt the user for a list of alternatives.
412
412
outdated formats), not for internal program warnings like deprecated
415
This can be overridden by UIFactory subclasses to show it in some
415
This can be overridden by UIFactory subclasses to show it in some
416
416
appropriate way; the default UIFactory is noninteractive and does
417
417
nothing. format_user_warning maps it to a string, though other
418
418
presentations can be used for particular UIs.
420
:param warning_id: An identifier like 'cross_format_fetch' used to
420
:param warning_id: An identifier like 'cross_format_fetch' used to
421
421
check if the message is suppressed and to look up the string.
422
422
:param message_args: Arguments to be interpolated into the message.
426
426
def show_error(self, msg):
427
427
"""Show an error message (not an exception) to the user.
429
429
The message should not have an error prefix or trailing newline. That
430
430
will be added by the factory if appropriate.
523
523
# this is now always TextUIFactory, which in turn decides whether it
524
524
# should display progress bars etc
525
from breezy.ui.text import TextUIFactory
525
from .text import TextUIFactory, _wrap_in_stream, _wrap_out_stream
526
# GZ 2017-05-21: May want to rewrap streams on Python 3 if encoding config
528
stdin = _wrap_in_stream(stdin)
529
stdout = _wrap_out_stream(stdout)
530
stderr = _wrap_out_stream(stderr)
526
531
return TextUIFactory(stdin, stdout, stderr)