diff --git a/scripts/microrepl.py b/scripts/microrepl.py index 333a7cde..3ad9a19b 100755 --- a/scripts/microrepl.py +++ b/scripts/microrepl.py @@ -79,8 +79,8 @@ def main(): """ The function that actually runs the REPL. """ - if len(sys.argv) != 2: - print("Usage: microrepl.py /path/to/device") + if len(sys.argv) not in range(2, 3): + print("Usage: microrepl.py /path/to/device [--nointerrupt]") port = sys.argv[1] print('Device path', port) @@ -97,7 +97,8 @@ def main(): miniterm.set_tx_encoding('utf-8') miniterm.start() sleep(0.5) - miniterm.serial.write(b'\x03') # Connecting stops the running program. + if len(sys.argv) != 3 or sys.argv[2] != '--nointerrupt': + miniterm.serial.write(b'\x03') # Connecting stops the running program. try: miniterm.join(True) except KeyboardInterrupt: diff --git a/src/main/kotlin/com/jetbrains/micropython/repl/MicroPythonReplManager.kt b/src/main/kotlin/com/jetbrains/micropython/repl/MicroPythonReplManager.kt index 07627d33..d7bbf796 100644 --- a/src/main/kotlin/com/jetbrains/micropython/repl/MicroPythonReplManager.kt +++ b/src/main/kotlin/com/jetbrains/micropython/repl/MicroPythonReplManager.kt @@ -7,7 +7,7 @@ import com.intellij.util.messages.Topic interface MicroPythonReplControl { fun stopRepl() - fun startOrRestartRepl() + fun startOrRestartRepl(interrupt: Boolean = true) } @Service(Service.Level.PROJECT) @@ -16,8 +16,8 @@ class MicroPythonReplManager(private val project: Project) : MicroPythonReplCont project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).stopRepl() - override fun startOrRestartRepl() = - project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).startOrRestartRepl() + override fun startOrRestartRepl(interrupt: Boolean) = + project.messageBus.syncPublisher(MICROPYTHON_REPL_CONTROL).startOrRestartRepl(interrupt) } diff --git a/src/main/kotlin/com/jetbrains/micropython/repl/ToolWindowReplTab.kt b/src/main/kotlin/com/jetbrains/micropython/repl/ToolWindowReplTab.kt index e98fbaa6..dc754969 100644 --- a/src/main/kotlin/com/jetbrains/micropython/repl/ToolWindowReplTab.kt +++ b/src/main/kotlin/com/jetbrains/micropython/repl/ToolWindowReplTab.kt @@ -140,7 +140,7 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep } } - override fun startOrRestartRepl() { + override fun startOrRestartRepl(interrupt: Boolean) { interruptBanner() application.executeOnPooledThread { synchronized(this) { @@ -150,12 +150,12 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep } } application.invokeLater( - { startRepl() }, + { startRepl(interrupt) }, { module.project.isDisposed }) } } - private fun startRepl() { + private fun startRepl(interrupt: Boolean) { val facet = module.microPythonFacet ?: return val devicePath = facet.getOrDetectDevicePathSynchronously() @@ -173,7 +173,9 @@ class ToolWindowReplTab(val module: Module, parent: Disposable) : MicroPythonRep facet.pythonPath!!, "${MicroPythonFacet.scriptsPath}/microrepl.py", devicePath - ) + ).apply { + if(!interrupt) add("--nointerrupt") + } val terminalRunner = LocalTerminalDirectRunner(module.project) diff --git a/src/main/kotlin/com/jetbrains/micropython/run/MicroPythonRunConfiguration.kt b/src/main/kotlin/com/jetbrains/micropython/run/MicroPythonRunConfiguration.kt index b3909e40..2bf887b8 100644 --- a/src/main/kotlin/com/jetbrains/micropython/run/MicroPythonRunConfiguration.kt +++ b/src/main/kotlin/com/jetbrains/micropython/run/MicroPythonRunConfiguration.kt @@ -87,7 +87,7 @@ class MicroPythonRunConfiguration(project: Project, factory: ConfigurationFactor if (runReplOnSuccess && state != null) { return RunStateWrapper(state) { ApplicationManager.getApplication().invokeLater { - project.service().startOrRestartRepl() + project.service().startOrRestartRepl(false) ToolWindowManager.getInstance(project).getToolWindow("MicroPython")?.show() } }