diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-06-14 08:45:43 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-06-14 08:45:43 (GMT) |
commit | 6afbc653a7bba73ecc56a6ba37632d25376dbe2f (patch) | |
tree | bcec120a14051455328b70343121cf89171a2169 /Lib | |
parent | 11a693d3304eb896de35733848b5bd9f2b5b4ab5 (diff) | |
download | cpython-6afbc653a7bba73ecc56a6ba37632d25376dbe2f.zip cpython-6afbc653a7bba73ecc56a6ba37632d25376dbe2f.tar.gz cpython-6afbc653a7bba73ecc56a6ba37632d25376dbe2f.tar.bz2 |
Issue #16182: set_pre_input_hook() may not exist; document, and update test
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_readline.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/Lib/test/test_readline.py b/Lib/test/test_readline.py index 51e136c..b59b6b0 100644 --- a/Lib/test/test_readline.py +++ b/Lib/test/test_readline.py @@ -129,24 +129,32 @@ class TestReadline(unittest.TestCase): script = r"""import readline -if readline.__doc__ and "libedit" in readline.__doc__: - readline.parse_and_bind(r'bind ^B ed-prev-char') - readline.parse_and_bind(r'bind "\t" rl_complete') +is_editline = readline.__doc__ and "libedit" in readline.__doc__ +inserted = "[\xEFnserted]" +macro = "|t\xEB[after]" +set_pre_input_hook = getattr(readline, "set_pre_input_hook", None) +if is_editline or not set_pre_input_hook: # The insert_line() call via pre_input_hook() does nothing with Editline, # so include the extra text that would have been inserted here - readline.parse_and_bind('bind -s ^A "[\xEFnserted]|t\xEB[after]"') + macro = inserted + macro + +if is_editline: + readline.parse_and_bind(r'bind ^B ed-prev-char') + readline.parse_and_bind(r'bind "\t" rl_complete') + readline.parse_and_bind(r'bind -s ^A "{}"'.format(macro)) else: readline.parse_and_bind(r'Control-b: backward-char') readline.parse_and_bind(r'"\t": complete') readline.parse_and_bind(r'set disable-completion off') readline.parse_and_bind(r'set show-all-if-ambiguous off') readline.parse_and_bind(r'set show-all-if-unmodified off') - readline.parse_and_bind('Control-a: "|t\xEB[after]"') + readline.parse_and_bind(r'Control-a: "{}"'.format(macro)) def pre_input_hook(): - readline.insert_text("[\xEFnserted]") + readline.insert_text(inserted) readline.redisplay() -readline.set_pre_input_hook(pre_input_hook) +if set_pre_input_hook: + set_pre_input_hook(pre_input_hook) def completer(text, state): if text == "t\xEB": |