~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2006-08-02 03:23:09 UTC
  • mto: This revision was merged to the branch mainline in revision 425.
  • Revision ID: aaron.bentley@utoronto.ca-20060802032309-6ad0139e61304b19
Etienne Goyer: remove unused shebangs, update packaging

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