~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-18 20:37:53 UTC
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: bialix@ukr.net-20060718203753-fa30c2f3cc59316b
don't use curses on win32

Show diffs side-by-side

added added

removed removed

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