~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to userinteractor.py

  • Committer: Michael Ellerman
  • Date: 2005-11-29 07:12:26 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051129071226-a04b3f827880025d
Unshelve --pick was broken, because we deleted the whole patch, even when only
part of it was unshelved. So now if we unshelve part of a patch, the patch is
replaced with a new patch that has just the unshelved parts. That's a long way
of saying it does what you'd expect.

Implementing this required changing HunkSelector to return both the selected,
and unselected hunks (ie. patches to shelve, and patches to keep).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
1
3
import sys
2
 
from bzrlib.osutils import getchar
3
 
 
4
4
 
5
5
class UserOption:
6
6
    def __init__(self, char, action, help, default=False):
113
113
                sys.stdout.write(opt.char)
114
114
            sys.stdout.write('?] (%s): ' % default.char)
115
115
 
116
 
            response = getchar()
 
116
            response = self.__getchar()
117
117
 
118
118
            # default, which we see as newline, is 'n'
119
119
            if response in ['\n', '\r', '\r\n']:
132
132
    def __show_help(self):
133
133
        for opt in self._options:
134
134
            print '  %s - %s' % (opt.char, opt.help)
 
135
 
 
136
    if sys.platform == "win32":
 
137
        import msvcrt
 
138
        def __getchar(self):
 
139
            return msvcrt.getche()
 
140
    else:
 
141
        def __getchar(self):
 
142
            import tty
 
143
            import termios
 
144
            fd = sys.stdin.fileno()
 
145
            settings = termios.tcgetattr(fd)
 
146
            try:
 
147
                tty.setraw(fd)
 
148
                ch = sys.stdin.read(1)
 
149
            finally:
 
150
                termios.tcsetattr(fd, termios.TCSADRAIN, settings)
 
151
            return ch