style: apply rustfmt

This commit is contained in:
objz committed 2026-06-16 09:58:34 +02:00
1 parent 7723716e18
commit a58e6fb76d
20 files changed
+114 -83

No files matched your search

+4 -4
View File
@@ -6,11 +6,11 @@ pub mod resource_packs;
pub mod shaders; pub mod shaders;
pub mod worlds; pub mod worlds;
pub use mods::{ContentEntry, scan_mods, toggle_entry};
pub use mods::scan_one_mod; pub use mods::scan_one_mod;
pub use resource_packs::{scan_resource_packs, scan_one_resource_pack}; pub use mods::{ContentEntry, scan_mods, toggle_entry};
pub use shaders::{scan_shaders, scan_one_shader}; pub use resource_packs::{scan_one_resource_pack, scan_resource_packs};
pub use worlds::{scan_worlds, scan_one_world}; pub use shaders::{scan_one_shader, scan_shaders};
pub use worlds::{scan_one_world, scan_worlds};
use std::io::Read; use std::io::Read;
+2 -1
View File
@@ -742,7 +742,8 @@ description = "A neoforge mod"
fn scan_mods_prefers_neoforge_toml_over_forge_toml() { fn scan_mods_prefers_neoforge_toml_over_forge_toml() {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let dir = setup_mods_dir(tmp.path(), "inst"); let dir = setup_mods_dir(tmp.path(), "inst");
let neoforge = "[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n"; let neoforge =
"[[mods]]\ndisplayName = \"NeoForge Name\"\ndescription = \"neoforge desc\"\n";
let forge = "[[mods]]\ndisplayName = \"Forge Name\"\ndescription = \"forge desc\"\n"; let forge = "[[mods]]\ndisplayName = \"Forge Name\"\ndescription = \"forge desc\"\n";
make_jar( make_jar(
&dir, &dir,
-1
View File
@@ -89,4 +89,3 @@ fn read_shader_metadata_from_dir(dir: &Path) -> (String, Option<Vec<u8>>) {
(description, icon_bytes) (description, icon_bytes)
} }
-1
View File
@@ -134,4 +134,3 @@ fn format_size(bytes: u64) -> String {
format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0)) format!("{:.2} GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0))
} }
} }
+3 -14
View File
@@ -154,11 +154,7 @@ mod tests {
#[test] #[test]
fn detect_format_recognises_mrpack() { fn detect_format_recognises_mrpack() {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let path = make_pack_zip( let path = make_pack_zip(tmp.path(), "pack.mrpack", &[("modrinth.index.json", b"{}")]);
tmp.path(),
"pack.mrpack",
&[("modrinth.index.json", b"{}")],
);
assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack)); assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack));
} }
@@ -176,11 +172,7 @@ mod tests {
// mmc-pack.json one directory deep - the more common layout where // mmc-pack.json one directory deep - the more common layout where
// the archive wraps everything in a named directory. // the archive wraps everything in a named directory.
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let path = make_pack_zip( let path = make_pack_zip(tmp.path(), "pack.zip", &[("MyPack/mmc-pack.json", b"{}")]);
tmp.path(),
"pack.zip",
&[("MyPack/mmc-pack.json", b"{}")],
);
assert_eq!(detect_format(&path), Ok(PackFormat::Mmc)); assert_eq!(detect_format(&path), Ok(PackFormat::Mmc));
} }
@@ -192,10 +184,7 @@ mod tests {
let path = make_pack_zip( let path = make_pack_zip(
tmp.path(), tmp.path(),
"weird.zip", "weird.zip",
&[ &[("modrinth.index.json", b"{}"), ("mmc-pack.json", b"{}")],
("modrinth.index.json", b"{}"),
("mmc-pack.json", b"{}"),
],
); );
assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack)); assert_eq!(detect_format(&path), Ok(PackFormat::Mrpack));
} }
+7 -2
View File
@@ -383,8 +383,13 @@ mod tests {
#[test] #[test]
fn parse_add_opens_extracts_module_args() { fn parse_add_opens_extracts_module_args() {
let tmp = tempfile::tempdir().unwrap(); let tmp = tempfile::tempdir().unwrap();
let manifest = b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n"; let manifest =
let zip_path = make_zip(tmp.path(), "patches.zip", &[("META-INF/MANIFEST.MF", manifest)]); b"Manifest-Version: 1.0\nAdd-Opens: java.base/java.lang java.base/java.util\n";
let zip_path = make_zip(
tmp.path(),
"patches.zip",
&[("META-INF/MANIFEST.MF", manifest)],
);
let args = parse_add_opens(&zip_path).expect("parsed"); let args = parse_add_opens(&zip_path).expect("parsed");
assert_eq!( assert_eq!(
args, args,
+3 -1
View File
@@ -468,7 +468,9 @@ mod tests {
manager.touch_last_played("ticker").expect("touch"); manager.touch_last_played("ticker").expect("touch");
let reloaded = manager.load_one("ticker").unwrap(); let reloaded = manager.load_one("ticker").unwrap();
let stamp = reloaded.last_played.expect("last_played should be Some now"); let stamp = reloaded
.last_played
.expect("last_played should be Some now");
let age = chrono::Utc::now() - stamp; let age = chrono::Utc::now() - stamp;
assert!( assert!(
age.num_seconds().abs() < 5, age.num_seconds().abs() < 5,
+2 -5
View File
@@ -11,11 +11,8 @@ pub mod models;
pub mod screenshots; pub mod screenshots;
pub use content::{ pub use content::{
ContentEntry, toggle_entry, ContentEntry, scan_mods, scan_one_mod, scan_one_resource_pack, scan_one_shader, scan_one_world,
scan_mods, scan_one_mod, scan_resource_packs, scan_shaders, scan_worlds, toggle_entry,
scan_resource_packs, scan_one_resource_pack,
scan_shaders, scan_one_shader,
scan_worlds, scan_one_world,
}; };
pub use launch::LaunchError; pub use launch::LaunchError;
pub use loader::{GameVersion, ModLoaderInstaller, VanillaInstaller, get_installer}; pub use loader::{GameVersion, ModLoaderInstaller, VanillaInstaller, get_installer};
-1
View File
@@ -45,4 +45,3 @@ pub fn scan_screenshots(instances_dir: &Path, instance_name: &str) -> Vec<Screen
entries.sort_by(|a, b| b.name.cmp(&a.name)); entries.sort_by(|a, b| b.name.cmp(&a.name));
entries entries
} }
+4 -1
View File
@@ -113,7 +113,10 @@ fn os_version_matches(pattern: &str, host_version: &str) -> bool {
fn features_match(required: &FeatureSet, current: &FeatureSet) -> bool { fn features_match(required: &FeatureSet, current: &FeatureSet) -> bool {
let pairs = [ let pairs = [
(required.is_demo_user, current.is_demo_user), (required.is_demo_user, current.is_demo_user),
(required.has_custom_resolution, current.has_custom_resolution), (
required.has_custom_resolution,
current.has_custom_resolution,
),
( (
required.has_quick_plays_support, required.has_quick_plays_support,
current.has_quick_plays_support, current.has_quick_plays_support,
+8 -2
View File
@@ -165,7 +165,10 @@ mod tests {
#[case::unclosed_placeholder("--prefix ${unclosed", "--prefix ${unclosed")] #[case::unclosed_placeholder("--prefix ${unclosed", "--prefix ${unclosed")]
#[case::dollar_without_brace("$$ literal $5 $", "$$ literal $5 $")] #[case::dollar_without_brace("$$ literal $5 $", "$$ literal $5 $")]
#[case::multiple("${version_name}-${auth_player_name}", "1.20.1-Player")] #[case::multiple("${version_name}-${auth_player_name}", "1.20.1-Player")]
#[case::path("-DlibraryDirectory=${library_directory}", "-DlibraryDirectory=/m/libraries")] #[case::path(
"-DlibraryDirectory=${library_directory}",
"-DlibraryDirectory=/m/libraries"
)]
#[case::empty_input("", "")] #[case::empty_input("", "")]
fn substitute_handles(#[case] input: &str, #[case] expected: &str) { fn substitute_handles(#[case] input: &str, #[case] expected: &str) {
let fx = Fixture::unix(); let fx = Fixture::unix();
@@ -178,7 +181,10 @@ mod tests {
// pattern. it should NOT trigger another substitution pass. // pattern. it should NOT trigger another substitution pass.
let mut fx = Fixture::unix(); let mut fx = Fixture::unix();
fx.user_properties = "${version_name}".to_string(); fx.user_properties = "${version_name}".to_string();
assert_eq!(substitute("${user_properties}", &fx.ctx()), "${version_name}"); assert_eq!(
substitute("${user_properties}", &fx.ctx()),
"${version_name}"
);
} }
#[test] #[test]
+5 -1
View File
@@ -39,7 +39,11 @@ fn rename_top_level(old: &Path, new: &Path) {
return; return;
} }
match fs::rename(old, new) { match fs::rename(old, new) {
Ok(_) => eprintln!("rmcl migration: moved {} -> {}", old.display(), new.display()), Ok(_) => eprintln!(
"rmcl migration: moved {} -> {}",
old.display(),
new.display()
),
Err(e) if e.kind() == io::ErrorKind::CrossesDevices => { Err(e) if e.kind() == io::ErrorKind::CrossesDevices => {
if let Err(e2) = copy_dir_recursive(old, new) { if let Err(e2) = copy_dir_recursive(old, new) {
eprintln!( eprintln!(
+1 -2
View File
@@ -113,8 +113,7 @@ pub async fn fetch_fabric_profile_with_raw(
game_version: &str, game_version: &str,
loader_version: &str, loader_version: &str,
) -> Result<(FabricProfile, Vec<u8>), NetError> { ) -> Result<(FabricProfile, Vec<u8>), NetError> {
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version) fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version).await
.await
} }
pub async fn fetch_fabric_profile_with_raw_from( pub async fn fetch_fabric_profile_with_raw_from(
-1
View File
@@ -297,5 +297,4 @@ mod tests {
fn maven_empty_string() { fn maven_empty_string() {
assert_eq!(maven_coord_to_path(""), None); assert_eq!(maven_coord_to_path(""), None);
} }
} }
+14 -24
View File
@@ -92,9 +92,7 @@ impl ContentListState {
received = true; received = true;
let pos = self let pos = self
.entries .entries
.binary_search_by(|e| { .binary_search_by(|e| e.name.to_lowercase().cmp(&entry.name.to_lowercase()))
e.name.to_lowercase().cmp(&entry.name.to_lowercase())
})
.unwrap_or_else(|i| i); .unwrap_or_else(|i| i);
self.entries.insert(pos, entry); self.entries.insert(pos, entry);
} }
@@ -160,8 +158,7 @@ impl ContentListState {
if self.entries.is_empty() { if self.entries.is_empty() {
self.list_state.selected = None; self.list_state.selected = None;
} else { } else {
self.list_state.selected = self.list_state.selected = Some(sel.min(self.entries.len().saturating_sub(1)));
Some(sel.min(self.entries.len().saturating_sub(1)));
} }
} }
@@ -235,11 +232,7 @@ impl ContentListState {
for (stem, (old_path, old_enabled)) in known_map.iter() { for (stem, (old_path, old_enabled)) in known_map.iter() {
if let Some((disk_path, disk_enabled)) = on_disk.get(stem) { if let Some((disk_path, disk_enabled)) = on_disk.get(stem) {
if *disk_enabled != *old_enabled || *disk_path != *old_path { if *disk_enabled != *old_enabled || *disk_path != *old_path {
toggled.push(( toggled.push((stem.clone(), *disk_enabled, disk_path.clone()));
stem.clone(),
*disk_enabled,
disk_path.clone(),
));
} }
} else { } else {
removed.push(stem.clone()); removed.push(stem.clone());
@@ -366,16 +359,16 @@ impl ContentListState {
continue; continue;
}; };
let (enabled, file_stem) = let (enabled, file_stem) = if let Some(stem) = fname.strip_suffix(&disabled_ext)
if let Some(stem) = fname.strip_suffix(&disabled_ext) { {
(false, stem.to_owned()) (false, stem.to_owned())
} else if let Some(stem) = fname.strip_suffix(ext) { } else if let Some(stem) = fname.strip_suffix(ext) {
(true, stem.to_owned()) (true, stem.to_owned())
} else if path.is_dir() { } else if path.is_dir() {
crate::instance::content::parse_enabled_stem_dir(fname) crate::instance::content::parse_enabled_stem_dir(fname)
} else { } else {
continue; continue;
}; };
let entry = scan_one_fn(&path, &file_stem, enabled); let entry = scan_one_fn(&path, &file_stem, enabled);
if tx.send(entry).is_err() { if tx.send(entry).is_err() {
@@ -879,10 +872,7 @@ fn icon_spans(icon_pixels: Option<&Vec<Vec<IconCell>>>, row: usize) -> Vec<Span<
// used both by watch_dir to initialize known state and by the watcher // used both by watch_dir to initialize known state and by the watcher
// thread to detect changes. when ext is empty (worlds), only directories // thread to detect changes. when ext is empty (worlds), only directories
// are included. // are included.
fn read_dir_stems( fn read_dir_stems(dir: &std::path::Path, ext: &str) -> HashMap<String, (std::path::PathBuf, bool)> {
dir: &std::path::Path,
ext: &str,
) -> HashMap<String, (std::path::PathBuf, bool)> {
let mut map = HashMap::new(); let mut map = HashMap::new();
let Ok(read_dir) = std::fs::read_dir(dir) else { let Ok(read_dir) = std::fs::read_dir(dir) else {
return map; return map;
+40 -8
View File
@@ -215,8 +215,16 @@ pub fn render(
ContentTab::Mods => { ContentTab::Mods => {
if let Some(instance) = instance { if let Some(instance) = instance {
if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) { if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("mods"); let content_dir = instances_dir
mods_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_mod, ".jar"); .join(&instance.name)
.join(".minecraft")
.join("mods");
mods_state.start_load(
&content_dir,
&instance.name,
crate::instance::scan_one_mod,
".jar",
);
mods_state.watch_dir(content_dir); mods_state.watch_dir(content_dir);
} }
super::list::render( super::list::render(
@@ -238,8 +246,16 @@ pub fn render(
ContentTab::ResourcePacks => { ContentTab::ResourcePacks => {
if let Some(instance) = instance { if let Some(instance) = instance {
if resource_packs_state.loaded_for.as_deref() != Some(instance.name.as_str()) { if resource_packs_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("resourcepacks"); let content_dir = instances_dir
resource_packs_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_resource_pack, ".zip"); .join(&instance.name)
.join(".minecraft")
.join("resourcepacks");
resource_packs_state.start_load(
&content_dir,
&instance.name,
crate::instance::scan_one_resource_pack,
".zip",
);
resource_packs_state.watch_dir(content_dir); resource_packs_state.watch_dir(content_dir);
} }
super::list::render( super::list::render(
@@ -261,8 +277,16 @@ pub fn render(
ContentTab::Shaders => { ContentTab::Shaders => {
if let Some(instance) = instance { if let Some(instance) = instance {
if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) { if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("shaderpacks"); let content_dir = instances_dir
shaders_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_shader, ".zip"); .join(&instance.name)
.join(".minecraft")
.join("shaderpacks");
shaders_state.start_load(
&content_dir,
&instance.name,
crate::instance::scan_one_shader,
".zip",
);
shaders_state.watch_dir(content_dir); shaders_state.watch_dir(content_dir);
} }
super::list::render( super::list::render(
@@ -322,8 +346,16 @@ pub fn render(
ContentTab::Worlds => { ContentTab::Worlds => {
if let Some(instance) = instance { if let Some(instance) = instance {
if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) { if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("saves"); let content_dir = instances_dir
worlds_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_world, ""); .join(&instance.name)
.join(".minecraft")
.join("saves");
worlds_state.start_load(
&content_dir,
&instance.name,
crate::instance::scan_one_world,
"",
);
worlds_state.watch_dir(content_dir); worlds_state.watch_dir(content_dir);
} }
super::list::render( super::list::render(
+1 -1
View File
@@ -9,12 +9,12 @@ use ratatui::{
pub mod account; pub mod account;
pub mod content; pub mod content;
pub mod settings;
pub mod instances; pub mod instances;
pub mod logs_viewer; pub mod logs_viewer;
pub mod popups; pub mod popups;
pub mod screenshots_grid; pub mod screenshots_grid;
pub mod search; pub mod search;
pub mod settings;
pub mod status; pub mod status;
// highlight the first character of a title with the accent color, // highlight the first character of a title with the accent color,
@@ -426,11 +426,8 @@ mod tests {
id: "1.20.1".into(), id: "1.20.1".into(),
stable: true, stable: true,
}]); }]);
guard.loader_versions = LoadState::Loaded(vec![ guard.loader_versions =
"47.2.0".into(), LoadState::Loaded(vec!["47.2.0".into(), "47.1.0".into(), "47.0.50".into()]);
"47.1.0".into(),
"47.0.50".into(),
]);
} }
let backend = TestBackend::new(60, 14); let backend = TestBackend::new(60, 14);
+12 -3
View File
@@ -9,7 +9,10 @@ use ratatui::{
widgets::{Block, Borders, Paragraph}, widgets::{Block, Borders, Paragraph},
}; };
use crate::config::{SETTINGS, theme::{BORDER_STYLE, THEME}}; use crate::config::{
SETTINGS,
theme::{BORDER_STYLE, THEME},
};
use crate::instance::models::InstanceConfig; use crate::instance::models::InstanceConfig;
use crate::tui::app::FocusedArea; use crate::tui::app::FocusedArea;
@@ -66,8 +69,14 @@ pub fn render(
.add_modifier(Modifier::BOLD); .add_modifier(Modifier::BOLD);
let dim_style = Style::default().fg(theme.text_dim()); let dim_style = Style::default().fg(theme.text_dim());
let memory_min = inst.memory_min.as_deref().unwrap_or(&SETTINGS.defaults.memory_min); let memory_min = inst
let memory_max = inst.memory_max.as_deref().unwrap_or(&SETTINGS.defaults.memory_max); .memory_min
.as_deref()
.unwrap_or(&SETTINGS.defaults.memory_min);
let memory_max = inst
.memory_max
.as_deref()
.unwrap_or(&SETTINGS.defaults.memory_max);
let java_path = inst let java_path = inst
.java_path .java_path
.as_deref() .as_deref()
+6 -5
View File
@@ -10,7 +10,7 @@ use wiremock::{Mock, MockServer, ResponseTemplate};
use rmcl::net::HttpClient; use rmcl::net::HttpClient;
use rmcl::net::mojang::{ use rmcl::net::mojang::{
AssetIndex, Artifact, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads, Artifact, AssetIndex, Download, JavaVersion, Library, LibraryDownloads, VersionDownloads,
VersionEntry, VersionMeta, download_assets, download_assets_from, download_libraries, VersionEntry, VersionMeta, download_assets, download_assets_from, download_libraries,
fetch_version_manifest_from, fetch_version_meta_with_raw, fetch_version_manifest_from, fetch_version_meta_with_raw,
}; };
@@ -226,9 +226,7 @@ async fn download_assets_from_writes_index_and_assets() {
.await; .await;
// asset hash starts with "ab" so the per-asset URL is /<base>/ab/<hash>. // asset hash starts with "ab" so the per-asset URL is /<base>/ab/<hash>.
Mock::given(method("GET")) Mock::given(method("GET"))
.and(path( .and(path("/cdn/ab/ab1234567890abcdef1234567890abcdef123456"))
"/cdn/ab/ab1234567890abcdef1234567890abcdef123456",
))
.respond_with(ResponseTemplate::new(200).set_body_bytes(b"asset-bytes".to_vec())) .respond_with(ResponseTemplate::new(200).set_body_bytes(b"asset-bytes".to_vec()))
.expect(1) .expect(1)
.mount(&server) .mount(&server)
@@ -272,7 +270,10 @@ async fn download_assets_writes_index_when_objects_is_empty() {
.expect("download_assets index-only"); .expect("download_assets index-only");
let index_path = tmp.path().join("assets/indexes/5.json"); let index_path = tmp.path().join("assets/indexes/5.json");
assert!(index_path.exists(), "expected asset index at {index_path:?}"); assert!(
index_path.exists(),
"expected asset index at {index_path:?}"
);
let body: serde_json::Value = let body: serde_json::Value =
serde_json::from_slice(&std::fs::read(&index_path).unwrap()).unwrap(); serde_json::from_slice(&std::fs::read(&index_path).unwrap()).unwrap();
assert!(body.get("objects").is_some()); assert!(body.get("objects").is_some());