Skip to content

Commit

Permalink
Implement Queue to store status updates
Browse files Browse the repository at this point in the history
  • Loading branch information
devanlooches committed Aug 12, 2022
1 parent f80311f commit ddbf53b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl Model {
}
Err(_) => String::from("Failed to fetch command output"),
};
status.clear_status();
status.update_status(&format!(
"Failed to compile model:\n{}",
output
Expand Down
24 changes: 17 additions & 7 deletions crates/fj-interop/src/status_report.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
//! Struct to store and update status messages
use std::collections::VecDeque;

/// Struct to store and update status messages
pub struct StatusReport {
status: Vec<String>,
status: VecDeque<String>,
}

impl StatusReport {
/// Create a new ``StatusReport`` instance with a blank status
pub fn new() -> Self {
Self { status: Vec::new() }
Self {
status: VecDeque::new(),
}
}

/// Update the status
pub fn update_status(&mut self, status: &str) {
if self.status.len() >= 5 {
self.clear_status();
let status = format!("\n{}", status.to_owned());
self.status.push_back(status);
if self.status.len() > 5 {
for _ in 0..(self.status.len() - 5) {
self.status.pop_front();
}
}
self.status.push(status.to_string());
}

/// Get current status
pub fn status(&self) -> String {
self.status.join("\n")
self.status
.iter()
.map(std::string::ToString::to_string)
.collect::<String>()
}

/// Reset status
fn clear_status(&mut self) {
pub fn clear_status(&mut self) {
self.status.clear();
}
}
Expand Down
7 changes: 2 additions & 5 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,8 @@ impl Renderer {
egui::Area::new("fj-status-message").show(&self.egui.context, |ui| {
ui.group(|ui| {
ui.add(egui::Label::new(
egui::RichText::new(format!(
"Status:\n{}",
status.status()
))
.color(egui::Color32::BLACK),
egui::RichText::new(format!("Status:{}", status.status()))
.color(egui::Color32::BLACK),
))
})
});
Expand Down

0 comments on commit ddbf53b

Please sign in to comment.