2323allowing multiline input and multiline history entries.
2424"""
2525
26+ import _sitebuiltins
2627import linecache
2728import sys
2829
@@ -48,6 +49,14 @@ def _strip_final_indent(text):
4849 return text
4950
5051
52+ REPL_COMMANDS = {
53+ "exit" : _sitebuiltins .Quitter ('exit' , '' ),
54+ "quit" : _sitebuiltins .Quitter ('quit' ,'' ),
55+ "copyright" : _sitebuiltins ._Printer ('copyright' , sys .copyright ),
56+ "help" : _sitebuiltins ._Helper (),
57+ }
58+
59+
5160def run_multiline_interactive_console (mainmodule = None , future_flags = 0 ):
5261 import code
5362 import __main__
@@ -81,11 +90,17 @@ def more_lines(unicodetext):
8190 statement = multiline_input (more_lines , ps1 , ps2 , returns_unicode = True )
8291 except EOFError :
8392 break
93+
8494 input_name = f"<python-input-{ input_n } >"
8595 linecache ._register_code (input_name , statement , "<stdin>" )
86- more = console .push (_strip_final_indent (statement ), filename = input_name )
96+ maybe_repl_command = REPL_COMMANDS .get (statement .strip ())
97+ if maybe_repl_command is not None :
98+ maybe_repl_command ()
99+ continue
100+ else :
101+ more = console .push (_strip_final_indent (statement ), filename = input_name )
102+ assert not more
87103 input_n += 1
88- assert not more
89104 except KeyboardInterrupt :
90105 console .write ("\n KeyboardInterrupt\n " )
91106 console .resetbuffer ()
0 commit comments