~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2006-08-07 01:20:08 UTC
  • mto: This revision was merged to the branch mainline in revision 425.
  • Revision ID: aaron.bentley@utoronto.ca-20060807012008-0d1b132f9741c555
Update to match 0.9 api

Show diffs side-by-side

added added

removed removed

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