Skip to content

Commit cf532fb

Browse files
committed
Implement REPL commands and remove F1 for help (curses shows that scrambled)
1 parent bc5c0b2 commit cf532fb

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Lib/_pyrepl/commands.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,6 @@ def do(self):
396396
pass
397397

398398

399-
class help(Command):
400-
def do(self):
401-
self.reader.msg = self.reader.help_text
402-
self.reader.dirty = 1
403-
404-
405399
class invalid_key(Command):
406400
def do(self):
407401
pending = self.reader.console.getpending()

Lib/_pyrepl/reader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def make_default_syntax_table():
160160
(r"\M-\<backspace>", "backward-kill-word"),
161161
(r"\<end>", "end-of-line"), # was 'end'
162162
(r"\<home>", "beginning-of-line"), # was 'home'
163-
(r"\<f1>", "help"),
164163
(r"\EOF", "end"), # the entries in the terminfo database for xterms
165164
(r"\EOH", "home"), # seem to be wrong. this is a less than ideal
166165
# workaround

Lib/_pyrepl/simple_interact.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
allowing multiline input and multiline history entries.
2424
"""
2525

26+
import _sitebuiltins
2627
import linecache
2728
import 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+
5160
def 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("\nKeyboardInterrupt\n")
91106
console.resetbuffer()

0 commit comments

Comments
 (0)