~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2006-08-09 17:16:46 UTC
  • mfrom: (423.1.7 bzrtools)
  • Revision ID: abentley@panoramicfeedback.com-20060809171646-317f34d7ab1da7fe
Merge from other bzrtools

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
1
import sys
4
2
 
5
3
from userinteractor import UserInteractor, UserOption
 
4
from errors import NoColor
6
5
import copy
7
6
 
8
7
class HunkSelector:
9
8
    strings = {}
10
9
 
11
 
    def __init__(self, patches):
12
 
        try:
13
 
            from colordiff import DiffWriter
14
 
            from terminal import has_ansi_colors
15
 
            if has_ansi_colors():
16
 
                self.diff_stream = DiffWriter(sys.stdout)
17
 
            else:
 
10
    def __init__(self, patches, color=None):
 
11
        if color is True or color is None:
 
12
            try:
 
13
                from colordiff import DiffWriter
 
14
                from terminal import has_ansi_colors
 
15
                if has_ansi_colors():
 
16
                    self.diff_stream = DiffWriter(sys.stdout)
 
17
                else:
 
18
                    if color is True:
 
19
                        raise NoColor()
 
20
                    self.diff_stream = sys.stdout
 
21
            except ImportError:
 
22
                if color is True:
 
23
                    raise NoBzrtoolsColor()
18
24
                self.diff_stream = sys.stdout
19
 
        except ImportError:
 
25
        else:
20
26
            self.diff_stream = sys.stdout
 
27
            
21
28
        self.standard_options = [
22
29
            UserOption('y', self._selected, self.strings['select_desc'],
23
30
                default=True),
165
172
        return (selected_patches, unselected_patches)
166
173
 
167
174
class ShelveHunkSelector(HunkSelector):
168
 
    def __init__(self, patches):
 
175
    def __init__(self, patches, color=None):
169
176
        self.strings = {}
170
177
        self.strings['status_selected'] = '%d hunks to be shelved'
171
178
        self.strings['status_unselected'] = '%d hunks to be kept'
174
181
        self.strings['finish_desc'] = 'shelve selected changes.'
175
182
        self.strings['prompt'] = 'Shelve this change? (%(count)d of %(total)d)'
176
183
        self.strings['end_prompt'] = 'Shelve these changes?'
177
 
        HunkSelector.__init__(self, patches)
 
184
        HunkSelector.__init__(self, patches, color)
178
185
 
179
186
class UnshelveHunkSelector(HunkSelector):
180
 
    def __init__(self, patches):
 
187
    def __init__(self, patches, color=None):
181
188
        self.strings = {}
182
189
        self.strings['status_selected'] = '%d hunks to be unshelved'
183
190
        self.strings['status_unselected'] = '%d hunks left on shelf'
187
194
        self.strings['prompt'] = 'Unshelve this change? ' \
188
195
            '(%(count)d of %(total)d)'
189
196
        self.strings['end_prompt'] = 'Unshelve these changes?'
190
 
        HunkSelector.__init__(self, patches)
 
197
        HunkSelector.__init__(self, patches, color)