style: apply cargo fmt across workspace

This commit is contained in:
Karim Jerbi committed 2026-10-11 03:14:29 +01:00
1 parent 85710e5454
commit 9cf9ff2c5c
531 files changed
+57740 -33906

No files matched your search

+148 -80
View File
@@ -28,8 +28,9 @@ impl OpenCADStudio {
// Tabs without a path (never saved) are skipped with a note.
"SAVEALL" => {
if self.read_only {
self.command_line
.push_error(crate::t!("Read-only session (--read-only): saving is disabled.").as_ref());
self.command_line.push_error(
crate::t!("Read-only session (--read-only): saving is disabled.").as_ref(),
);
return Some(Task::none());
}
#[cfg(not(target_arch = "wasm32"))]
@@ -41,47 +42,47 @@ impl OpenCADStudio {
continue;
}
if let Some(path) = self.tabs[t].current_path.clone() {
if self
.active_save_jobs
.contains_key(&self.tabs[t].id)
{
self.command_line.push_info(crate::tf!(
"SAVEALL: {} already has a save running",
path.display()
).as_ref());
if self.active_save_jobs.contains_key(&self.tabs[t].id) {
self.command_line.push_info(
crate::tf!(
"SAVEALL: {} already has a save running",
path.display()
)
.as_ref(),
);
skipped += 1;
continue;
}
match self.save_tab_synchronously_protected(
t,
path.clone(),
false,
) {
match self.save_tab_synchronously_protected(t, path.clone(), false) {
Ok(()) => {
saved += 1;
}
Err(e) => self.command_line.push_error(crate::tf!(
"SAVEALL: {} failed: {e}",
path.display()
).as_ref()),
Err(e) => self.command_line.push_error(
crate::tf!("SAVEALL: {} failed: {e}", path.display()).as_ref(),
),
}
} else {
skipped += 1;
}
}
self.command_line.push_output(crate::tf!(
"SAVEALL: saved {saved} drawing(s){}.",
if skipped > 0 {
crate::tf!("; {skipped} need SAVEAS (no file path yet)").into_owned()
} else {
String::new()
}
).as_ref());
self.command_line.push_output(
crate::tf!(
"SAVEALL: saved {saved} drawing(s){}.",
if skipped > 0 {
crate::tf!("; {skipped} need SAVEAS (no file path yet)")
.into_owned()
} else {
String::new()
}
)
.as_ref(),
);
}
#[cfg(target_arch = "wasm32")]
{
self.command_line
.push_info(crate::t!("SAVEALL: save each tab individually in the web build.").as_ref());
self.command_line.push_info(
crate::t!("SAVEALL: save each tab individually in the web build.").as_ref(),
);
}
return Some(Task::none());
}
@@ -105,7 +106,8 @@ impl OpenCADStudio {
// without undoing any work done since.
"OOPS" => {
if self.oops_cache.is_empty() {
self.command_line.push_info(crate::t!("OOPS: nothing to restore.").as_ref());
self.command_line
.push_info(crate::t!("OOPS: nothing to restore.").as_ref());
} else {
let restored = std::mem::take(&mut self.oops_cache);
let pending = self.begin_undo(i, "OOPS", restored.len(), true);
@@ -202,7 +204,11 @@ impl OpenCADStudio {
}
for d in deps {
let dp = PathBuf::from(&d);
let resolved = if dp.is_absolute() { dp } else { parent.join(&dp) };
let resolved = if dp.is_absolute() {
dp
} else {
parent.join(&dp)
};
if resolved.exists() {
if let Some(fname) = resolved.file_name() {
if std::fs::copy(&resolved, folder.join(fname)).is_ok() {
@@ -211,18 +217,23 @@ impl OpenCADStudio {
}
}
}
self.command_line.push_output(crate::tf!(
"{cmd}: packaged {copied} file(s) into {}",
folder.display()
).as_ref());
self.command_line.push_output(
crate::tf!(
"{cmd}: packaged {copied} file(s) into {}",
folder.display()
)
.as_ref(),
);
}
Err(e) => self
.command_line
.push_error(crate::tf!("{cmd}: cannot create folder ({e}).").as_ref()),
}
} else {
self.command_line
.push_error(crate::t!("ARCHIVE: save the drawing first (it has no file path yet).").as_ref());
self.command_line.push_error(
crate::t!("ARCHIVE: save the drawing first (it has no file path yet).")
.as_ref(),
);
}
}
@@ -241,11 +252,14 @@ impl OpenCADStudio {
"PERF" => {
self.perf_hud = !self.perf_hud;
crate::perf::set_ui_enabled(self.perf_hud);
self.command_line.push_info(crate::t!(if self.perf_hud {
"PERF panel on — tracing render and interaction costs"
} else {
"PERF panel off"
}).as_ref());
self.command_line.push_info(
crate::t!(if self.perf_hud {
"PERF panel on — tracing render and interaction costs"
} else {
"PERF panel off"
})
.as_ref(),
);
return Some(Task::none());
}
@@ -277,14 +291,16 @@ impl OpenCADStudio {
self.model_space.mode = crate::app::config::ModelSpaceMode::MatchTheme;
self.sync_model_space_theme(true);
self.persist_settings_if_changed();
self.command_line
.push_output(crate::t!("Model space background set to Match Theme.").as_ref());
self.command_line.push_output(
crate::t!("Model space background set to Match Theme.").as_ref(),
);
} else if first_arg == "CLASSIC" {
self.model_space.mode = crate::app::config::ModelSpaceMode::ClassicDark;
self.sync_model_space_theme(true);
self.persist_settings_if_changed();
self.command_line
.push_output(crate::t!("Model space background set to Classic CAD Dark.").as_ref());
self.command_line.push_output(
crate::t!("Model space background set to Classic CAD Dark.").as_ref(),
);
} else if first_arg == "DEFAULT" || first_arg == "RESET" {
if is_paper {
self.model_space.custom_paper_bg = None;
@@ -300,31 +316,48 @@ impl OpenCADStudio {
.push_output(crate::t!("Background reset to default.").as_ref());
} else if first_arg == "DESK" {
let sub_args = &args[1..];
let sub_first = sub_args.first().map(|s| s.to_uppercase()).unwrap_or_default();
let sub_first = sub_args
.first()
.map(|s| s.to_uppercase())
.unwrap_or_default();
if sub_first == "DEFAULT" || sub_first == "RESET" {
self.model_space.custom_desk_bg = None;
self.sync_model_space_theme(false);
self.persist_settings_if_changed();
self.command_line
.push_output(crate::t!("Paper desk surround background reset to default.").as_ref());
self.command_line.push_output(
crate::t!("Paper desk surround background reset to default.").as_ref(),
);
} else if let Some(rgba) = parse_background_color(sub_args) {
let [r, g, b, _] = rgba;
let rgb = [(r * 255.0).round() as u8, (g * 255.0).round() as u8, (b * 255.0).round() as u8];
let rgb = [
(r * 255.0).round() as u8,
(g * 255.0).round() as u8,
(b * 255.0).round() as u8,
];
self.model_space.custom_desk_bg = Some(rgb);
self.sync_model_space_theme(false);
self.persist_settings_if_changed();
self.command_line.push_output(crate::tf!(
"Desk surround background: rgb({}, {}, {})",
rgb[0],
rgb[1],
rgb[2]
).as_ref());
self.command_line.push_output(
crate::tf!(
"Desk surround background: rgb({}, {}, {})",
rgb[0],
rgb[1],
rgb[2]
)
.as_ref(),
);
} else {
self.command_line.push_info(crate::t!("Usage: BACKGROUND DESK <r> <g> <b> | DEFAULT").as_ref());
self.command_line.push_info(
crate::t!("Usage: BACKGROUND DESK <r> <g> <b> | DEFAULT").as_ref(),
);
}
} else if let Some(rgba) = parse_background_color(&args) {
let [r, g, b, _] = rgba;
let rgb = [(r * 255.0).round() as u8, (g * 255.0).round() as u8, (b * 255.0).round() as u8];
let rgb = [
(r * 255.0).round() as u8,
(g * 255.0).round() as u8,
(b * 255.0).round() as u8,
];
if is_paper {
self.model_space.custom_paper_bg = Some(rgb);
self.paper_bg_input = crate::app::config::rgb_to_hex(rgb);
@@ -335,12 +368,9 @@ impl OpenCADStudio {
}
self.sync_model_space_theme(true);
self.persist_settings_if_changed();
self.command_line.push_output(crate::tf!(
"Background: rgb({}, {}, {})",
rgb[0],
rgb[1],
rgb[2]
).as_ref());
self.command_line.push_output(
crate::tf!("Background: rgb({}, {}, {})", rgb[0], rgb[1], rgb[2]).as_ref(),
);
} else {
self.command_line.push_info(
crate::t!("Usage: BACKGROUND <r> <g> <b> (0–255) | THEME|CLASSIC|DEFAULT|DESK|BLACK|DARKGRAY|GRAY|LIGHTGRAY|WHITE").as_ref(),
@@ -397,15 +427,19 @@ impl OpenCADStudio {
.filter(|l| !l.starts_with('#') && !l.starts_with(';'))
.map(|l| Task::done(Message::ScriptLine(l.to_string())))
.collect();
self.command_line.push_output(crate::tf!(
"SCRIPT: running {} command(s) from {clean_path}.",
cmds.len()
).as_ref());
self.command_line.push_output(
crate::tf!(
"SCRIPT: running {} command(s) from {clean_path}.",
cmds.len()
)
.as_ref(),
);
return Some(Task::batch(cmds));
}
Err(e) => {
self.command_line
.push_error(crate::tf!("SCRIPT: cannot read {clean_path}: {e}").as_ref());
self.command_line.push_error(
crate::tf!("SCRIPT: cannot read {clean_path}: {e}").as_ref(),
);
}
}
}
@@ -480,17 +514,30 @@ mod tests {
// Feed standard multi-line CAD script sequence
let _ = app.update(Message::ScriptLine("LINE".into()));
assert!(app.tabs[i].active_cmd.is_some(), "LINE command should be active");
assert!(
app.tabs[i].active_cmd.is_some(),
"LINE command should be active"
);
let _ = app.update(Message::ScriptLine("0,0".into()));
assert!(app.tabs[i].active_cmd.is_some(), "LINE command should stay active after first point");
assert!(
app.tabs[i].active_cmd.is_some(),
"LINE command should stay active after first point"
);
let _ = app.update(Message::ScriptLine("10,10".into()));
let _ = app.update(Message::ScriptLine("".into())); // Enter to finish
let after_count = app.tabs[i].scene.document.entities().count();
assert_eq!(after_count, before_count + 1, "Line entity should have been created");
assert!(app.tabs[i].active_cmd.is_none(), "LINE command should be finished");
assert_eq!(
after_count,
before_count + 1,
"Line entity should have been created"
);
assert!(
app.tabs[i].active_cmd.is_none(),
"LINE command should be finished"
);
}
#[test]
@@ -502,8 +549,15 @@ mod tests {
let _ = app.update(Message::ScriptLine("CIRCLE 5,5 2".into()));
let after_count = app.tabs[i].scene.document.entities().count();
assert_eq!(after_count, before_count + 1, "Circle entity should have been created");
assert!(app.tabs[i].active_cmd.is_none(), "CIRCLE command should be finished");
assert_eq!(
after_count,
before_count + 1,
"Circle entity should have been created"
);
assert!(
app.tabs[i].active_cmd.is_none(),
"CIRCLE command should be finished"
);
}
#[test]
@@ -515,7 +569,11 @@ mod tests {
let _ = app.update(Message::ScriptLine("_CIRCLE 10,10 3".into()));
let after_count = app.tabs[i].scene.document.entities().count();
assert_eq!(after_count, before_count + 1, "_CIRCLE should resolve to CIRCLE and create entity");
assert_eq!(
after_count,
before_count + 1,
"_CIRCLE should resolve to CIRCLE and create entity"
);
}
#[test]
@@ -546,7 +604,11 @@ CIRCLE 50,50 15
ZOOM EXTENTS
"#;
for line in SCRIPT.lines().map(str::trim).filter(|l| !l.starts_with('#') && !l.starts_with(';')) {
for line in SCRIPT
.lines()
.map(str::trim)
.filter(|l| !l.starts_with('#') && !l.starts_with(';'))
{
let _ = app.update(Message::ScriptLine(line.to_string()));
}
// 4 square edges + 2 diagonal lines + 2 circles = 8 entities
@@ -572,7 +634,10 @@ ZOOM EXTENTS
// 2. Blank line when idle repeats LINE
let _ = app.update(Message::ScriptLine("".into()));
assert!(app.tabs[i].active_cmd.is_some(), "Blank line should repeat LINE");
assert!(
app.tabs[i].active_cmd.is_some(),
"Blank line should repeat LINE"
);
let _ = app.update(Message::ScriptLine("20,20".into()));
let _ = app.update(Message::ScriptLine("30,30".into()));
let _ = app.update(Message::ScriptLine("".into())); // finishes second LINE
@@ -586,7 +651,10 @@ ZOOM EXTENTS
// Blank line repeats CIRCLE
let _ = app.update(Message::ScriptLine("".into()));
assert!(app.tabs[i].active_cmd.is_some(), "Blank line should repeat CIRCLE");
assert!(
app.tabs[i].active_cmd.is_some(),
"Blank line should repeat CIRCLE"
);
let _ = app.update(Message::ScriptLine("15,15".into()));
let _ = app.update(Message::ScriptLine("3".into()));
assert_eq!(app.tabs[i].scene.document.entities().count(), 4);