finish status bar internal simplification
This commit is contained in:
parent
d983f08f36
commit
0cd37376a0
@ -45,7 +45,7 @@ void shared_module_supervisor_status_bar_set_console(supervisor_status_bar_obj_t
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->written) {
|
||||
if (self->updated) {
|
||||
// Clear before changing state. If disabling, will remain cleared.
|
||||
supervisor_status_bar_clear();
|
||||
}
|
||||
@ -67,7 +67,7 @@ void shared_module_supervisor_status_bar_set_display(supervisor_status_bar_obj_t
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->written) {
|
||||
if (self->updated) {
|
||||
// Clear before changing state. If disabling, will remain cleared.
|
||||
terminalio_terminal_clear_status_bar(&supervisor_terminal);
|
||||
}
|
||||
@ -79,11 +79,12 @@ void shared_module_supervisor_status_bar_set_display(supervisor_status_bar_obj_t
|
||||
}
|
||||
#endif
|
||||
|
||||
bool supervisor_status_bar_get_update_in_progress(supervisor_status_bar_obj_t *self) {
|
||||
return self->update_in_progress;
|
||||
void shared_module_supervisor_status_bar_init(supervisor_status_bar_obj_t *self) {
|
||||
self->console = true;
|
||||
self->display = true;
|
||||
self->updated = false;
|
||||
}
|
||||
|
||||
void supervisor_status_bar_set_update_in_progress(supervisor_status_bar_obj_t *self, bool update_in_progress) {
|
||||
self->written = true;
|
||||
self->update_in_progress = update_in_progress;
|
||||
void shared_module_supervisor_status_bar_updated(supervisor_status_bar_obj_t *self) {
|
||||
self->updated = true;
|
||||
}
|
||||
|
@ -33,11 +33,10 @@ typedef struct {
|
||||
mp_obj_base_t base;
|
||||
bool console;
|
||||
bool display;
|
||||
bool update_in_progress;
|
||||
bool written;
|
||||
bool updated;
|
||||
} supervisor_status_bar_obj_t;
|
||||
|
||||
extern bool supervisor_status_bar_get_update_in_progress(supervisor_status_bar_obj_t *self);
|
||||
extern void supervisor_status_bar_set_update_in_progress(supervisor_status_bar_obj_t *self, bool in_progress);
|
||||
extern void shared_module_supervisor_status_bar_init(supervisor_status_bar_obj_t *self);
|
||||
extern void shared_module_supervisor_status_bar_updated(supervisor_status_bar_obj_t *self);
|
||||
|
||||
#endif // MICROPY_INCLUDED_SHARED_MODULE_SUPERVISOR_STATUS_BAR_H
|
||||
|
@ -66,13 +66,6 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
|
||||
return len;
|
||||
}
|
||||
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
// Skip the status bar OSC sequence if it's disabled for the display.
|
||||
const bool status_bar_write_ok =
|
||||
shared_module_supervisor_status_bar_get_display(&shared_module_supervisor_status_bar_obj) ||
|
||||
!supervisor_status_bar_get_update_in_progress(&shared_module_supervisor_status_bar_obj);
|
||||
#endif
|
||||
|
||||
const byte *i = data;
|
||||
uint16_t start_y = self->cursor_y;
|
||||
while (i < data + len) {
|
||||
@ -85,9 +78,6 @@ size_t common_hal_terminalio_terminal_write(terminalio_terminal_obj_t *self, con
|
||||
self->status_y = 0;
|
||||
i += 1;
|
||||
} else if (
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
status_bar_write_ok &&
|
||||
#endif
|
||||
self->osc_command == 0 &&
|
||||
self->status_bar != NULL &&
|
||||
self->status_y < self->status_bar->height_in_tiles) {
|
||||
|
@ -49,6 +49,10 @@ char serial_read(void);
|
||||
bool serial_bytes_available(void);
|
||||
bool serial_connected(void);
|
||||
|
||||
// Used for temporarily suppressing output to the console or display.
|
||||
bool serial_console_write_disable(bool disabled);
|
||||
bool serial_display_write_disable(bool disabled);
|
||||
|
||||
// These have no-op versions that are weak and the port can override. They work
|
||||
// in tandem with the cross-port mechanics like USB and BLE.
|
||||
void port_serial_early_init(void);
|
||||
|
@ -41,11 +41,6 @@
|
||||
#include "supervisor/shared/bluetooth/serial.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
#include "shared-bindings/supervisor/__init__.h"
|
||||
#include "shared-bindings/supervisor/StatusBar.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_USB
|
||||
#include "tusb.h"
|
||||
#endif
|
||||
@ -72,10 +67,10 @@ bool tud_vendor_connected(void);
|
||||
#endif
|
||||
|
||||
// Set to true to temporarily discard writes to the console only.
|
||||
static bool _console_write_disabled;
|
||||
static bool _serial_console_write_disabled;
|
||||
|
||||
// Set to true to temporarily discard writes to the display terminal only.
|
||||
static bool _display_write_disabled;
|
||||
static bool _serial_display_write_disabled;
|
||||
|
||||
#if CIRCUITPY_CONSOLE_UART
|
||||
STATIC void console_uart_print_strn(void *env, const char *str, size_t len) {
|
||||
@ -283,12 +278,6 @@ bool serial_bytes_available(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
// Detect when USB is down when the status bar write starts. If USB comes up in the middle of writing
|
||||
// the status bar, we want to the skip the rest so so junk doesn't get written out.
|
||||
static bool ignore_rest_of_status_bar_update = false;
|
||||
#endif
|
||||
|
||||
void serial_write_substring(const char *text, uint32_t length) {
|
||||
if (length == 0) {
|
||||
return;
|
||||
@ -296,26 +285,14 @@ void serial_write_substring(const char *text, uint32_t length) {
|
||||
|
||||
#if CIRCUITPY_TERMINALIO
|
||||
int errcode;
|
||||
// If the status bar is disabled for the display, common_hal_terminalio_terminal_write() will not write it.
|
||||
common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t *)text, length, &errcode);
|
||||
if (!_serial_display_write_disabled) {
|
||||
common_hal_terminalio_terminal_write(&supervisor_terminal, (const uint8_t *)text, length, &errcode);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
// If the status bar is disabled for the console, skip writing out the OSC sequence.
|
||||
if (supervisor_status_bar_get_update_in_progress(&shared_module_supervisor_status_bar_obj)) {
|
||||
if (!shared_module_supervisor_status_bar_get_console(&shared_module_supervisor_status_bar_obj)) {
|
||||
// Console status bar disabled, so just return.
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Status bar update is not in progress, so clear this history flag (will get cleared repeatedly).
|
||||
ignore_rest_of_status_bar_update = false;
|
||||
}
|
||||
|
||||
if (ignore_rest_of_status_bar_update) {
|
||||
if (_serial_console_write_disabled) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_USB_VENDOR
|
||||
if (tud_vendor_connected()) {
|
||||
@ -355,13 +332,6 @@ void serial_write_substring(const char *text, uint32_t length) {
|
||||
usb_background();
|
||||
}
|
||||
}
|
||||
#if CIRCUITPY_STATUS_BAR
|
||||
else {
|
||||
// USB was not connected for the first part of the status bar update. Ignore the rest
|
||||
// so we don't send the remaining part of the OSC sequence if USB comes up later.
|
||||
ignore_rest_of_status_bar_update = true;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
port_serial_write_substring(text, length);
|
||||
@ -371,10 +341,14 @@ void serial_write(const char *text) {
|
||||
serial_write_substring(text, strlen(text));
|
||||
}
|
||||
|
||||
void serial_console_write_disable(bool disabled) {
|
||||
bool serial_console_write_disable(bool disabled) {
|
||||
bool now = _serial_console_write_disabled;
|
||||
_serial_console_write_disabled = disabled;
|
||||
return now;
|
||||
}
|
||||
|
||||
void serial_display_write_disable(bool disabled) {
|
||||
bool serial_display_write_disable(bool disabled) {
|
||||
bool now = _serial_display_write_disabled;
|
||||
_serial_display_write_disabled = disabled;
|
||||
return now;
|
||||
}
|
||||
|
@ -53,9 +53,7 @@ static bool _suspended = false;
|
||||
// Clear if possible, but give up if we can't do it now.
|
||||
void supervisor_status_bar_clear(void) {
|
||||
if (!_suspended) {
|
||||
supervisor_status_bar_set_update_in_progress(&shared_module_supervisor_status_bar_obj, true);
|
||||
serial_write("\x1b" "]0;" "\x1b" "\\");
|
||||
supervisor_status_bar_set_update_in_progress(&shared_module_supervisor_status_bar_obj, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,9 +64,31 @@ void supervisor_status_bar_update(void) {
|
||||
}
|
||||
_forced_dirty = false;
|
||||
|
||||
supervisor_status_bar_set_update_in_progress(&shared_module_supervisor_status_bar_obj, true);
|
||||
shared_module_supervisor_status_bar_updated(&shared_module_supervisor_status_bar_obj);
|
||||
|
||||
// Neighboring "" "" are concatenated by the compiler. Without this separation, the hex code
|
||||
// Disable status bar console writes if supervisor.status_bar.console is False.
|
||||
// Also disable if there is no serial connection now. This avoids sending part
|
||||
// of the status bar update if the serial connection comes up during the update.
|
||||
bool disable_console_writes =
|
||||
!shared_module_supervisor_status_bar_get_console(&shared_module_supervisor_status_bar_obj) ||
|
||||
!serial_connected();
|
||||
|
||||
// Disable status bar display writes if supervisor.status_bar.display is False.
|
||||
bool disable_display_writes =
|
||||
!shared_module_supervisor_status_bar_get_display(&shared_module_supervisor_status_bar_obj);
|
||||
|
||||
// Suppress writes to console and/or display if status bar is not enabled for either or both.
|
||||
bool prev_console_disable;
|
||||
bool prev_display_disable;
|
||||
|
||||
if (disable_console_writes) {
|
||||
prev_console_disable = serial_console_write_disable(true);
|
||||
}
|
||||
if (disable_display_writes) {
|
||||
prev_display_disable = serial_display_write_disable(true);
|
||||
}
|
||||
|
||||
// Neighboring "..." "..." are concatenated by the compiler. Without this separation, the hex code
|
||||
// doesn't get terminated after two following characters and the value is invalid.
|
||||
// This is the OSC command to set the title and the icon text. It can be up to 255 characters
|
||||
// but some may be cut off.
|
||||
@ -91,7 +111,14 @@ void supervisor_status_bar_update(void) {
|
||||
// Send string terminator
|
||||
serial_write("\x1b" "\\");
|
||||
|
||||
supervisor_status_bar_set_update_in_progress(&shared_module_supervisor_status_bar_obj, false);
|
||||
// Restore writes to console and/or display.
|
||||
if (disable_console_writes) {
|
||||
serial_console_write_disable(prev_console_disable);
|
||||
}
|
||||
if (disable_display_writes) {
|
||||
serial_display_write_disable(prev_display_disable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void status_bar_background(void *data) {
|
||||
@ -137,8 +164,5 @@ void supervisor_status_bar_init(void) {
|
||||
status_bar_background_cb.fun = status_bar_background;
|
||||
status_bar_background_cb.data = NULL;
|
||||
|
||||
shared_module_supervisor_status_bar_obj.console = true;
|
||||
shared_module_supervisor_status_bar_obj.display = true;
|
||||
shared_module_supervisor_status_bar_obj.update_in_progress = false;
|
||||
shared_module_supervisor_status_bar_obj.written = false;
|
||||
shared_module_supervisor_status_bar_init(&shared_module_supervisor_status_bar_obj);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user