support icon indicating copy to clipboard operation
support copied to clipboard

"The program was stopped" message should start with a newline

Open dlech opened this issue 3 years ago • 5 comments

Describe the bug When a SystemExit or SystemAbort is raise, we print a special message that hides the stack trace. If there is already text on a line in a terminal, this message is just appended to that line which makes it hard to read.

To reproduce

Firmware v3.2.0

Steps to reproduce the behavior:

  1. Connect to a hub in Pybricks Code
  2. Start the REPL
  3. Type something but don't press enter
  4. Press the stop button

Expected behavior The message should be on a new line.

Screenshots image

dlech avatar Dec 21 '22 22:12 dlech

Since this mainly happens during REPL usage, perhaps we could do something like:

diff --git a/bricks/_common/micropython.c b/bricks/_common/micropython.c
index 4c97f428..7cc98ddc 100644
--- a/bricks/_common/micropython.c
+++ b/bricks/_common/micropython.c
@@ -116,6 +116,7 @@ static void run_repl() {
         // Print which exception triggered this.
         print_final_exception(nlr.ret_val);
     }
+    mp_print_str(&mp_plat_print, "\n");
 }
 #endif

laurensvalk avatar Dec 22 '22 10:12 laurensvalk

I would rather make is universally the same. I often write programs with, e.g. print(..., sep=' ').

dlech avatar Dec 22 '22 16:12 dlech

Adding a simple \n would fix this but it makes the overal output of multiple runs a bit harder to read, since the stop message is usually one line removed from the corresponding program output.

Image

I'm not sure if a fancier solution like a conditional break is worth it though, so maybe the above is OK?

laurensvalk avatar Oct 02 '24 08:10 laurensvalk

A traceback message would also be printed at the location the cursor happens to be. I will not object against a "\n" but will also not complain about no newline.

BertLindeman avatar Oct 02 '24 12:10 BertLindeman

We could use ANSI escape codes to change the color of the SystemExit message to help break things up visually.

dlech avatar Oct 02 '24 13:10 dlech

Just in time for the third anniversary of this issue 😎

This is fixed by having flush write \r\n if the last write did not include it. This also fixes interruptions of long prints:

Image

laurensvalk avatar Nov 02 '25 18:11 laurensvalk