~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to userinteractor.py

  • Committer: Aaron Bentley
  • Date: 2011-06-27 23:07:10 UTC
  • Revision ID: aaron@aaronbentley.com-20110627230710-orth0tzf1kwknfen
Better handling of compound tar names.

Show diffs side-by-side

added added

removed removed

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