diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index c899266d8..fe6009bcc 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -7,6 +7,7 @@ #include #include #include +#include extern "C" { #include @@ -364,9 +365,16 @@ void ConsoleController::resetSandbox() { m_sandboxController.reset(); } +void ConsoleController::refreshPrintOutput() { + m_selectableTableView.reloadData(); + m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines()); + AppsContainer::sharedAppsContainer()->redrawWindow(); +} + /* printText is called by the Python machine. * The text argument is not always null-terminated. */ void ConsoleController::printText(const char * text, size_t length) { + micropython_port_vm_hook_loop_content(); size_t textCutIndex = firstNewLineCharIndex(text, length); if (textCutIndex >= length) { /* If there is no new line in text, just append it to the output diff --git a/apps/code/console_controller.h b/apps/code/console_controller.h index 538f1d21b..b6a9df39b 100644 --- a/apps/code/console_controller.h +++ b/apps/code/console_controller.h @@ -62,6 +62,7 @@ public: void displaySandbox() override; void hideSandbox() override; void resetSandbox() override; + void refreshPrintOutput() override; void printText(const char * text, size_t length) override; const char * inputText(const char * prompt) override; diff --git a/python/port/helpers.cpp b/python/port/helpers.cpp index 438f7ca47..132effcdd 100644 --- a/python/port/helpers.cpp +++ b/python/port/helpers.cpp @@ -1,4 +1,5 @@ #include "helpers.h" +#include "port.h" #include extern "C" { #include "mphalport.h" @@ -18,6 +19,12 @@ bool micropython_port_vm_hook_loop() { return false; } + return micropython_port_vm_hook_loop_content(); +} + +bool micropython_port_vm_hook_loop_content() { + assert(MicroPython::ExecutionEnvironment::currentExecutionEnvironment() != nullptr); + MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->refreshPrintOutput(); // Check if the user asked for an interruption from the keyboard return micropython_port_interrupt_if_needed(); } diff --git a/python/port/helpers.h b/python/port/helpers.h index b9ab24cb7..850a08a94 100644 --- a/python/port/helpers.h +++ b/python/port/helpers.h @@ -10,6 +10,7 @@ extern "C" { // These methods return true if they have been interrupted bool micropython_port_vm_hook_loop(); +bool micropython_port_vm_hook_loop_content(); bool micropython_port_interruptible_msleep(int32_t delay); bool micropython_port_interrupt_if_needed(); int micropython_port_random(); diff --git a/python/port/port.h b/python/port/port.h index f0b3a0407..e6e27df96 100644 --- a/python/port/port.h +++ b/python/port/port.h @@ -22,6 +22,7 @@ public: virtual void hideSandbox() {} virtual void resetSandbox() {} virtual void printText(const char * text, size_t length) {} + virtual void refreshPrintOutput() {} void interrupt(); void setSandboxIsDisplayed(bool display); protected: