~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2006-03-24 19:01:30 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060324190130-2208c693486a8b33
Added apache index scraping to the branches command

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
 
1
#!/usr/bin/python
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()
24
 
                self.diff_stream = sys.stdout
25
 
        else:
26
 
            self.diff_stream = sys.stdout
27
 
            
 
9
    def __init__(self, patches):
28
10
        self.standard_options = [
29
11
            UserOption('y', self._selected, self.strings['select_desc'],
30
12
                default=True),
83
65
    # Called once for each hunk
84
66
    def _hunk_callback(self, hunk, count):
85
67
        if self.last_printed != count:
86
 
            self.diff_stream.write(str(hunk.patch.get_header()))
87
 
            self.diff_stream.write(str(hunk))
 
68
            print hunk.patch.get_header(), hunk
88
69
            self.last_printed = count
89
70
 
90
71
        if hunk.selected:
172
153
        return (selected_patches, unselected_patches)
173
154
 
174
155
class ShelveHunkSelector(HunkSelector):
175
 
    def __init__(self, patches, color=None):
 
156
    def __init__(self, patches):
176
157
        self.strings = {}
177
158
        self.strings['status_selected'] = '%d hunks to be shelved'
178
159
        self.strings['status_unselected'] = '%d hunks to be kept'
181
162
        self.strings['finish_desc'] = 'shelve selected changes.'
182
163
        self.strings['prompt'] = 'Shelve this change? (%(count)d of %(total)d)'
183
164
        self.strings['end_prompt'] = 'Shelve these changes?'
184
 
        HunkSelector.__init__(self, patches, color)
 
165
        HunkSelector.__init__(self, patches)
185
166
 
186
167
class UnshelveHunkSelector(HunkSelector):
187
 
    def __init__(self, patches, color=None):
 
168
    def __init__(self, patches):
188
169
        self.strings = {}
189
170
        self.strings['status_selected'] = '%d hunks to be unshelved'
190
171
        self.strings['status_unselected'] = '%d hunks left on shelf'
194
175
        self.strings['prompt'] = 'Unshelve this change? ' \
195
176
            '(%(count)d of %(total)d)'
196
177
        self.strings['end_prompt'] = 'Unshelve these changes?'
197
 
        HunkSelector.__init__(self, patches, color)
 
178
        HunkSelector.__init__(self, patches)