~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2011-01-26 01:11:59 UTC
  • Revision ID: aaron@aaronbentley.com-20110126011159-xsh6z4n8bgxy0k9k
Ignore the_kraken changelogs.

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
                                                  check_style=False)
 
18
                else:
 
19
                    if color is True:
 
20
                        raise NoColor()
 
21
                    self.diff_stream = sys.stdout
 
22
            except ImportError:
 
23
                if color is True:
 
24
                    raise NoBzrtoolsColor()
18
25
                self.diff_stream = sys.stdout
19
 
        except ImportError:
 
26
        else:
20
27
            self.diff_stream = sys.stdout
 
28
 
21
29
        self.standard_options = [
22
30
            UserOption('y', self._selected, self.strings['select_desc'],
23
31
                default=True),
165
173
        return (selected_patches, unselected_patches)
166
174
 
167
175
class ShelveHunkSelector(HunkSelector):
168
 
    def __init__(self, patches):
 
176
    def __init__(self, patches, color=None):
169
177
        self.strings = {}
170
178
        self.strings['status_selected'] = '%d hunks to be shelved'
171
179
        self.strings['status_unselected'] = '%d hunks to be kept'
174
182
        self.strings['finish_desc'] = 'shelve selected changes.'
175
183
        self.strings['prompt'] = 'Shelve this change? (%(count)d of %(total)d)'
176
184
        self.strings['end_prompt'] = 'Shelve these changes?'
177
 
        HunkSelector.__init__(self, patches)
 
185
        HunkSelector.__init__(self, patches, color)
178
186
 
179
187
class UnshelveHunkSelector(HunkSelector):
180
 
    def __init__(self, patches):
 
188
    def __init__(self, patches, color=None):
181
189
        self.strings = {}
182
190
        self.strings['status_selected'] = '%d hunks to be unshelved'
183
191
        self.strings['status_unselected'] = '%d hunks left on shelf'
187
195
        self.strings['prompt'] = 'Unshelve this change? ' \
188
196
            '(%(count)d of %(total)d)'
189
197
        self.strings['end_prompt'] = 'Unshelve these changes?'
190
 
        HunkSelector.__init__(self, patches)
 
198
        HunkSelector.__init__(self, patches, color)