summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-08-23 18:07:59 -0400
committerGitHub <noreply@github.com>2024-08-23 22:07:59 +0000
commitbbd3a7e637b0223647405adf76b23092ab957157 (patch)
tree3d9eb32c312ea44767628cf36423937429e0ef4e /cli/util
parent38bc4021e633183f33453a6557cedae4e6ee91d0 (diff)
fix: handle showing warnings while the progress bar is shown (#25187)
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/draw_thread.rs17
-rw-r--r--cli/util/logger.rs8
2 files changed, 18 insertions, 7 deletions
diff --git a/cli/util/draw_thread.rs b/cli/util/draw_thread.rs
index d9ab176a9..164a8fc71 100644
--- a/cli/util/draw_thread.rs
+++ b/cli/util/draw_thread.rs
@@ -40,7 +40,7 @@ struct InternalEntry {
struct InternalState {
// this ensures only one actual draw thread is running
drawer_id: usize,
- hide: bool,
+ hide_count: usize,
has_draw_thread: bool,
next_entry_id: u16,
entries: Vec<InternalEntry>,
@@ -56,7 +56,7 @@ impl InternalState {
static INTERNAL_STATE: Lazy<Arc<Mutex<InternalState>>> = Lazy::new(|| {
Arc::new(Mutex::new(InternalState {
drawer_id: 0,
- hide: false,
+ hide_count: 0,
has_draw_thread: false,
entries: Vec::new(),
next_entry_id: 0,
@@ -113,7 +113,7 @@ impl DrawThread {
pub fn hide() {
let internal_state = &*INTERNAL_STATE;
let mut internal_state = internal_state.lock();
- internal_state.hide = true;
+ internal_state.hide_count += 1;
Self::clear_and_stop_draw_thread(&mut internal_state);
}
@@ -122,9 +122,12 @@ impl DrawThread {
pub fn show() {
let internal_state = &*INTERNAL_STATE;
let mut internal_state = internal_state.lock();
- internal_state.hide = false;
-
- Self::maybe_start_draw_thread(&mut internal_state);
+ if internal_state.hide_count > 0 {
+ internal_state.hide_count -= 1;
+ if internal_state.hide_count == 0 {
+ Self::maybe_start_draw_thread(&mut internal_state);
+ }
+ }
}
fn finish_entry(entry_id: u16) {
@@ -153,7 +156,7 @@ impl DrawThread {
fn maybe_start_draw_thread(internal_state: &mut InternalState) {
if internal_state.has_draw_thread
- || internal_state.hide
+ || internal_state.hide_count > 0
|| internal_state.entries.is_empty()
|| !DrawThread::is_supported()
{
diff --git a/cli/util/logger.rs b/cli/util/logger.rs
index 4c185f6de..d64e9a707 100644
--- a/cli/util/logger.rs
+++ b/cli/util/logger.rs
@@ -2,6 +2,8 @@
use std::io::Write;
+use super::draw_thread::DrawThread;
+
struct CliLogger(env_logger::Logger);
impl CliLogger {
@@ -21,7 +23,13 @@ impl log::Log for CliLogger {
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
+ // it was considered to hold the draw thread's internal lock
+ // across logging, but if outputting to stderr blocks then that
+ // could potentially block other threads that access the draw
+ // thread's state
+ DrawThread::hide();
self.0.log(record);
+ DrawThread::show();
}
}