From 94de8b61f8bc1226cb431b8fe7a28bf0e29427ff Mon Sep 17 00:00:00 2001 From: Elizaveta Shashkova Date: Wed, 2 Aug 2017 15:50:24 +0300 Subject: [PATCH] Update console after IPython detection and fix Console folding (PY-25468) --- python/helpers/pydev/pydevconsole.py | 3 +-- .../com/jetbrains/python/console/PyConsoleStartFolding.java | 2 +- .../python/console/PydevConsoleExecuteActionHandler.kt | 2 +- .../python/console/PythonConsoleExecuteActionHandler.kt | 1 + python/src/com/jetbrains/python/console/PythonConsoleView.java | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/python/helpers/pydev/pydevconsole.py b/python/helpers/pydev/pydevconsole.py index 7e2343397fc1..b50f3d4e3b6e 100644 --- a/python/helpers/pydev/pydevconsole.py +++ b/python/helpers/pydev/pydevconsole.py @@ -371,8 +371,7 @@ def get_interpreter(): except AttributeError: interpreterInterface = InterpreterInterface(None, None, threading.currentThread()) setattr(__builtin__, 'interpreter', interpreterInterface) - sys.stderr.write(interpreterInterface.get_greeting_msg()) - sys.stderr.flush() + print(interpreterInterface.get_greeting_msg()) return interpreterInterface diff --git a/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java b/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java index fd5bc0e651dd..ba41d35f8a59 100644 --- a/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java +++ b/python/src/com/jetbrains/python/console/PyConsoleStartFolding.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull; public class PyConsoleStartFolding implements ConsoleCommunicationListener, FoldingListener, DocumentListener { private PythonConsoleView myConsoleView; private int myNumberOfCommandExecuted = 0; - private int myNumberOfCommandToStop = 1; + private int myNumberOfCommandToStop = 2; private boolean doNotAddFoldingAgain = false; private FoldRegion myStartFoldRegion; private static final String DEFAULT_FOLDING_MESSAGE = "Python Console"; diff --git a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt index 15535c53fa12..8ed2b9f7d178 100644 --- a/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt +++ b/python/src/com/jetbrains/python/console/PydevConsoleExecuteActionHandler.kt @@ -87,7 +87,7 @@ open class PydevConsoleExecuteActionHandler(private val myConsoleView: LanguageC consoleComm.execInterpreter(code) {} } - private fun updateConsoleState() { + override fun updateConsoleState() { if (!isEnabled) { executingPrompt() } diff --git a/python/src/com/jetbrains/python/console/PythonConsoleExecuteActionHandler.kt b/python/src/com/jetbrains/python/console/PythonConsoleExecuteActionHandler.kt index 1aa8565b877a..c000b080f049 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleExecuteActionHandler.kt +++ b/python/src/com/jetbrains/python/console/PythonConsoleExecuteActionHandler.kt @@ -29,4 +29,5 @@ abstract class PythonConsoleExecuteActionHandler(processHandler: ProcessHandler, abstract fun canExecuteNow(): Boolean abstract var isEnabled: Boolean abstract val consoleCommunication: ConsoleCommunication + abstract fun updateConsoleState() } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index 20c63f8b1b84..2441230be0af 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -295,6 +295,7 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable VirtualFile file = getVirtualFile(); if (PyConsoleUtil.detectIPythonImported(text, outputType)) { PyConsoleUtil.markIPython(file); + getExecuteActionHandler().updateConsoleState(); } if (PyConsoleUtil.detectIPythonAutomagicOn(text)) { PyConsoleUtil.setIPythonAutomagic(file, true);