Skip to content

Commit

Permalink
Don't interrupt program execution when REPL is started right after up…
Browse files Browse the repository at this point in the history
…load.

Fixes #283
  • Loading branch information
elmot committed Jul 24, 2024
1 parent b7a03ac commit 9350458
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
7 changes: 4 additions & 3 deletions scripts/microrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MicroPythonRunConfiguration(project: Project, factory: ConfigurationFactor
if (runReplOnSuccess && state != null) {
return RunStateWrapper(state) {
ApplicationManager.getApplication().invokeLater {
project.service<MicroPythonReplManager>().startOrRestartRepl()
project.service<MicroPythonReplManager>().startOrRestartRepl(false)
ToolWindowManager.getInstance(project).getToolWindow("MicroPython")?.show()
}
}
Expand Down

0 comments on commit 9350458

Please sign in to comment.