~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/ui/__init__.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
    This tells the library how to display things to the user.  Through this
107
107
    layer different applications can choose the style of UI.
108
108
 
109
 
    UI Factories are also context managers, for some syntactic sugar some users
110
 
    need.
111
 
 
112
109
    :ivar suppressed_warnings: Identifiers for user warnings that should 
113
110
        no be emitted.
114
111
    """
126
123
        self.suppressed_warnings = set()
127
124
        self._quiet = False
128
125
 
129
 
    def __enter__(self):
130
 
        """Context manager entry support.
131
 
 
132
 
        Override in a concrete factory class if initialisation before use is
133
 
        needed.
134
 
        """
135
 
        return self # This is bound to the 'as' clause in a with statement.
136
 
 
137
 
    def __exit__(self, exc_type, exc_val, exc_tb):
138
 
        """Context manager exit support.
139
 
 
140
 
        Override in a concrete factory class if more cleanup than a simple
141
 
        self.clear_term() is needed when the UIFactory is finished with.
142
 
        """
143
 
        self.clear_term()
144
 
        return False # propogate exceptions.
145
 
 
146
126
    def be_quiet(self, state):
147
127
        """Tell the UI to be more quiet, or not.
148
128
 
178
158
        version of stdout, but in a GUI it might be appropriate to send it to a 
179
159
        window displaying the text.
180
160
     
181
 
        :param encoding: Unicode encoding for output; if not specified 
182
 
            uses the configured 'output_encoding' if any; otherwise the 
183
 
            terminal encoding. 
 
161
        :param encoding: Unicode encoding for output; default is the 
 
162
            terminal encoding, which may be different from the user encoding.
184
163
            (See get_terminal_encoding.)
185
164
 
186
165
        :param encoding_type: How to handle encoding errors:
188
167
        """
189
168
        # XXX: is the caller supposed to close the resulting object?
190
169
        if encoding is None:
191
 
            from bzrlib import config
192
 
            encoding = config.GlobalConfig().get_user_option(
193
 
                'output_encoding')
194
 
        if encoding is None:
195
 
            encoding = osutils.get_terminal_encoding(trace=True)
 
170
            encoding = osutils.get_terminal_encoding()
196
171
        if encoding_type is None:
197
172
            encoding_type = 'replace'
198
173
        out_stream = self._make_output_stream_explicit(encoding, encoding_type)
377
352
                "without an upgrade path.\n" % (inter.target._format,))
378
353
 
379
354
 
 
355
 
380
356
class SilentUIFactory(UIFactory):
381
357
    """A UI Factory which never prints anything.
382
358