~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to hunk_selector.py

  • Committer: Aaron Bentley
  • Date: 2006-07-11 18:53:52 UTC
  • mfrom: (0.3.5 my_shelf)
  • Revision ID: abentley@panoramicfeedback.com-20060711185352-562216f86dac6f7f
Merge shelf colorizing

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
import sys
 
4
 
3
5
from userinteractor import UserInteractor, UserOption
4
6
import copy
5
7
 
7
9
    strings = {}
8
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:
 
18
                self.diff_stream = sys.stdout
 
19
        except ImportError:
 
20
            self.diff_stream = sys.stdout
10
21
        self.standard_options = [
11
22
            UserOption('y', self._selected, self.strings['select_desc'],
12
23
                default=True),
65
76
    # Called once for each hunk
66
77
    def _hunk_callback(self, hunk, count):
67
78
        if self.last_printed != count:
68
 
            print hunk.patch.get_header(), hunk
 
79
            self.diff_stream.write(str(hunk.patch.get_header()))
 
80
            self.diff_stream.write(str(hunk))
69
81
            self.last_printed = count
70
82
 
71
83
        if hunk.selected: