4141#include "supervisor/shared/bluetooth/serial.h"
4242#endif
4343
44- #if CIRCUITPY_STATUS_BAR
45- #include "shared-bindings/supervisor/__init__.h"
46- #include "shared-bindings/supervisor/StatusBar.h"
47- #endif
48-
4944#if CIRCUITPY_USB
5045#include "tusb.h"
5146#endif
@@ -72,10 +67,10 @@ bool tud_vendor_connected(void);
7267#endif
7368
7469// Set to true to temporarily discard writes to the console only.
75- static bool _console_write_disabled ;
70+ static bool _serial_console_write_disabled ;
7671
7772// Set to true to temporarily discard writes to the display terminal only.
78- static bool _display_write_disabled ;
73+ static bool _serial_display_write_disabled ;
7974
8075#if CIRCUITPY_CONSOLE_UART
8176STATIC void console_uart_print_strn (void * env , const char * str , size_t len ) {
@@ -283,39 +278,21 @@ bool serial_bytes_available(void) {
283278 return false;
284279}
285280
286- #if CIRCUITPY_STATUS_BAR
287- // Detect when USB is down when the status bar write starts. If USB comes up in the middle of writing
288- // the status bar, we want to the skip the rest so so junk doesn't get written out.
289- static bool ignore_rest_of_status_bar_update = false;
290- #endif
291-
292281void serial_write_substring (const char * text , uint32_t length ) {
293282 if (length == 0 ) {
294283 return ;
295284 }
296285
297286 #if CIRCUITPY_TERMINALIO
298287 int errcode ;
299- // If the status bar is disabled for the display, common_hal_terminalio_terminal_write() will not write it.
300- common_hal_terminalio_terminal_write (& supervisor_terminal , (const uint8_t * )text , length , & errcode );
301- #endif
302-
303- #if CIRCUITPY_STATUS_BAR
304- // If the status bar is disabled for the console, skip writing out the OSC sequence.
305- if (supervisor_status_bar_get_update_in_progress (& shared_module_supervisor_status_bar_obj )) {
306- if (!shared_module_supervisor_status_bar_get_console (& shared_module_supervisor_status_bar_obj )) {
307- // Console status bar disabled, so just return.
308- return ;
309- }
310- } else {
311- // Status bar update is not in progress, so clear this history flag (will get cleared repeatedly).
312- ignore_rest_of_status_bar_update = false;
288+ if (!_serial_display_write_disabled ) {
289+ common_hal_terminalio_terminal_write (& supervisor_terminal , (const uint8_t * )text , length , & errcode );
313290 }
291+ #endif
314292
315- if (ignore_rest_of_status_bar_update ) {
293+ if (_serial_console_write_disabled ) {
316294 return ;
317295 }
318- #endif
319296
320297 #if CIRCUITPY_USB_VENDOR
321298 if (tud_vendor_connected ()) {
@@ -355,13 +332,6 @@ void serial_write_substring(const char *text, uint32_t length) {
355332 usb_background ();
356333 }
357334 }
358- #if CIRCUITPY_STATUS_BAR
359- else {
360- // USB was not connected for the first part of the status bar update. Ignore the rest
361- // so we don't send the remaining part of the OSC sequence if USB comes up later.
362- ignore_rest_of_status_bar_update = true;
363- }
364- #endif
365335 #endif
366336
367337 port_serial_write_substring (text , length );
@@ -371,10 +341,14 @@ void serial_write(const char *text) {
371341 serial_write_substring (text , strlen (text ));
372342}
373343
374- void serial_console_write_disable (bool disabled ) {
344+ bool serial_console_write_disable (bool disabled ) {
345+ bool now = _serial_console_write_disabled ;
375346 _serial_console_write_disabled = disabled ;
347+ return now ;
376348}
377349
378- void serial_display_write_disable (bool disabled ) {
350+ bool serial_display_write_disable (bool disabled ) {
351+ bool now = _serial_display_write_disabled ;
379352 _serial_display_write_disabled = disabled ;
353+ return now ;
380354}
0 commit comments