~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to userinteractor.py

  • Committer: Aaron Bentley
  • Date: 2012-01-20 02:00:40 UTC
  • Revision ID: aaron@aaronbentley.com-20120120020040-7y4c93fhnnahidxg
Remove rspush

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
1
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 = self.__getchar()
 
116
            response = 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