Rev 6156: Don't try to use osutils.getchar() where it's known to not work. in file:///home/vila/src/bzr/bugs/856261-unshelve-line-based/
v.ladeuil+lp at free.fr
Tue Sep 27 16:17:25 UTC 2011
revision-id: v.ladeuil+lp at free.fr-20110927161725-6b2z9jq6229bry6c
parent: pqm at pqm.ubuntu.com-20110921151127-hojrogt4w8w2z6si
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 856261-unshelve-line-based
timestamp: Tue 2011-09-27 18:17:25 +0200
Don't try to use osutils.getchar() where it's known to not work.
Instead, consider that input always end up with a newline and read a full
This allows shelve (without --all) to just work in a regular shell under
emacs as well as in the test suite.
-------------- next part --------------
=== modified file 'bzrlib/shelf_ui.py'
--- a/bzrlib/shelf_ui.py 2011-09-16 15:39:47 +0000
+++ b/bzrlib/shelf_ui.py 2011-09-27 16:17:25 +0000
@@ -257,14 +257,30 @@
:param message: The message to prompt a user with.
:return: A character.
- if not sys.stdin.isatty():
- # Since there is no controlling terminal we will hang when trying
- # to prompt the user, better abort now. See
+ char_based = os.environ.get('INSIDE_EMACS', None) is not None
+ if char_based and not sys.stdin.isatty():
+ # Since there is no controlling terminal we will hang when
+ # trying to prompt the user, better abort now. See
# for more context.
- raise errors.BzrError(gettext("You need a controlling terminal."))
+ raise errors.BzrError("You need a controlling terminal.")
- char = osutils.getchar()
+ if char_based:
+ # We peek one char at a time which requires a real term here
+ char = osutils.getchar()
+ # While running tests (or under emacs) the input is line buffered
+ # so we must not use osutils.getchar(). Instead we switch to a mode
+ # where each line is terminated by a new line
+ line = sys.stdin.readline()
+ if line:
+ # XXX: Warn if more than one char is typed ?
+ char = line
+ # In the char based implementation, the default value is
+ # selected when the user just hit enter, so we return that here
+ # for edge cases.
+ char = '\n'
sys.stdout.write("\r" + ' ' * len(message) + '\r')
More information about the bazaar-commits