Comments
Patch
new file mode 100644
@@ -0,0 +1,13 @@
+ $ cat > prompt.py << 'EOF'
+ > from mercurial import exthelper
+ > eh = exthelper.exthelper()
+ > cmdtable = eh.cmdtable
+ > @eh.command(b'prompt', [], norepo=True)
+ > def prompt(ui):
+ > chosen = ui.promptchoice(b"is stdin present? (y/N) $$ &Yes $$ &No", default=1)
+ > ui.write(b"chosen: %d\n" % chosen)
+ > EOF
+
+ $ hg --config extensions.prompt=prompt.py prompt 0<&-
+ is stdin present? (y/N) n
+ chosen: 1
@@ -114,6 +114,11 @@
if pycompat.ispy3:
+ # Stdio objects can be 'None' on Python 3. Most code paths (for example,
+ # dispatch.initstdio) do not expect that. Fix them by opening devnull.
+ sys.stdin = sys.stdin or open(os.devnull, "r")
+ sys.stdout = sys.stdout or open(os.devnull, "w")
+ sys.stderr = sys.stderr or sys.stdout
# Python 3 implements its own I/O streams.
# TODO: .buffer might not exist if std streams were replaced; we'll need
# a silly wrapper to make a bytes stream backed by a unicode one.