Commit 6cc4bf32 authored by Kirill Smelkov's avatar Kirill Smelkov

gpython: Factor-out interactive-console functionality into its own function

We will soon need this to be run from several places when implementing
support for -i.

/reviewed-by @jerome
/reviewed-on nexedi/pygolang!15
parent 3cb9f8c1
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2018-2020 Nexedi SA and Contributors. # Copyright (C) 2018-2021 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -181,25 +181,7 @@ def pymain(argv, init=None): ...@@ -181,25 +181,7 @@ def pymain(argv, init=None):
sys.path.insert(0, '') # cwd sys.path.insert(0, '') # cwd
def run(): def run():
import code _interact()
from six.moves import input as raw_input
# like code.interact() but with overridden console.raw_input _and_
# readline imported (code.interact mutually excludes those two).
try:
import readline # enable interactive editing
except ImportError:
pass
console = code.InteractiveConsole()
def _(prompt):
# python behaviour: don't print '>>>' if stdin is not a tty
# (builtin raw_input always prints prompt)
if not sys.stdin.isatty():
prompt=''
return raw_input(prompt)
console.raw_input = _
console.interact()
# ---- options processed -> start the interpreter ---- # ---- options processed -> start the interpreter ----
...@@ -270,6 +252,29 @@ def pymain(argv, init=None): ...@@ -270,6 +252,29 @@ def pymain(argv, init=None):
run() run()
# _interact runs interactive console.
def _interact():
import code, sys
from six.moves import input as raw_input
# like code.interact() but with overridden console.raw_input _and_
# readline imported (code.interact mutually excludes those two).
try:
import readline # enable interactive editing
except ImportError:
pass
console = code.InteractiveConsole()
def _(prompt):
# python behaviour: don't print '>>>' if stdin is not a tty
# (builtin raw_input always prints prompt)
if not sys.stdin.isatty():
prompt=''
return raw_input(prompt)
console.raw_input = _
console.interact()
# execfile was removed in py3 # execfile was removed in py3
def _execfile(path, globals=None, locals=None): def _execfile(path, globals=None, locals=None):
import six import six
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment