diff -r f6e399ae670f Doc/library/readline.rst --- a/Doc/library/readline.rst Fri Jul 24 09:07:12 2015 +0300 +++ b/Doc/library/readline.rst Sun Jul 26 11:49:22 2015 +0100 @@ -114,6 +114,12 @@ line buffer. +.. function:: forced_update_display() + + Forcibly redisplay the line buffer and prompt, even if Readline thinks + they're displayed correctly. + + .. function:: set_startup_hook([function]) Set or remove the startup_hook function. If *function* is specified, it will be @@ -185,6 +191,12 @@ Append a line to the history buffer, as if it was the last line typed. +.. function:: reading_line() + + Returns True if the interpreter is in the process of reading a line + using Readline at the time the call is made. Returns False otherwise. + + .. seealso:: Module :mod:`rlcompleter` diff -r f6e399ae670f Misc/ACKS --- a/Misc/ACKS Fri Jul 24 09:07:12 2015 +0300 +++ b/Misc/ACKS Sun Jul 26 11:49:22 2015 +0100 @@ -1355,6 +1355,7 @@ Michael Stone Serhiy Storchaka Ken Stox +Barney Stratford Dan Stromberg Donald Stufft Daniel Stutzbach diff -r f6e399ae670f Modules/readline.c --- a/Modules/readline.c Fri Jul 24 09:07:12 2015 +0300 +++ b/Modules/readline.c Sun Jul 26 11:49:22 2015 +0100 @@ -771,6 +771,41 @@ contents of the line buffer."); +/* Forcibly redisplay the line buffer */ + +static PyObject * +forced_update_display(PyObject *self, PyObject *noarg) +{ + rl_forced_update_display(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(doc_forced_update_display, +"forced_update_display() -> None\n\ +Forcibly redraw the current line."); + + + +/* Are we reading a line of input right now? */ + +static int reading = 0; + +static PyObject * +reading_line (PyObject *self, PyObject *noarg) +{ + if (reading) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + +PyDoc_STRVAR(doc_reading_line, +"reading_line() -> bool\n\ +Are we reading a line of text into the interpreter right now?"); + + + + /* Table of functions exported by the module */ static struct PyMethodDef readline_methods[] = @@ -779,6 +814,7 @@ {"get_line_buffer", get_line_buffer, METH_NOARGS, doc_get_line_buffer}, {"insert_text", insert_text, METH_VARARGS, doc_insert_text}, {"redisplay", redisplay, METH_NOARGS, doc_redisplay}, + {"forced_update_display", forced_update_display, METH_NOARGS, doc_forced_update_display}, {"read_init_file", read_init_file, METH_VARARGS, doc_read_init_file}, {"read_history_file", read_history_file, METH_VARARGS, doc_read_history_file}, @@ -822,6 +858,7 @@ #ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER {"clear_history", py_clear_history, METH_NOARGS, doc_clear_history}, #endif + {"reading_line", reading_line, METH_NOARGS, doc_reading_line}, {0, 0} }; @@ -1114,6 +1151,7 @@ rl_catch_signals = 0; #endif + reading = 1; rl_callback_handler_install (prompt, rlhandler); FD_ZERO(&selectset); @@ -1160,6 +1198,7 @@ } } + reading = 0; return completed_input_string; } @@ -1197,7 +1236,9 @@ return NULL; } rl_event_hook = PyOS_InputHook; + reading = 1; p = readline(prompt); + reading = 0; PyOS_setsig(SIGINT, old_inthandler); return p;