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 worlds;
pub use mods::{ContentEntry, scan_mods, toggle_entry};
pub use mods::scan_one_mod;
pub use resource_packs::{scan_resource_packs, scan_one_resource_pack};
pub use shaders::{scan_shaders, scan_one_shader};
pub use worlds::{scan_worlds, scan_one_world};
pub use mods::{ContentEntry, scan_mods, toggle_entry};
pub use resource_packs::{scan_one_resource_pack, scan_resource_packs};
pub use shaders::{scan_one_shader, scan_shaders};
pub use worlds::{scan_one_world, scan_worlds};
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() {
let tmp = tempfile::tempdir().unwrap();
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";
make_jar(
&dir,
-1
View File
@@ -89,4 +89,3 @@ fn read_shader_metadata_from_dir(dir: &Path) -> (String, Option<Vec<u8>>) {
(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))
}
}
+3 -14
View File
@@ -154,11 +154,7 @@ mod tests {
#[test]
fn detect_format_recognises_mrpack() {
let tmp = tempfile::tempdir().unwrap();
let path = make_pack_zip(
tmp.path(),
"pack.mrpack",
&[("modrinth.index.json", b"{}")],
);
let path = make_pack_zip(tmp.path(), "pack.mrpack", &[("modrinth.index.json", b"{}")]);
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
// the archive wraps everything in a named directory.
let tmp = tempfile::tempdir().unwrap();
let path = make_pack_zip(
tmp.path(),
"pack.zip",
&[("MyPack/mmc-pack.json", b"{}")],
);
let path = make_pack_zip(tmp.path(), "pack.zip", &[("MyPack/mmc-pack.json", b"{}")]);
assert_eq!(detect_format(&path), Ok(PackFormat::Mmc));
}
@@ -192,10 +184,7 @@ mod tests {
let path = make_pack_zip(
tmp.path(),
"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));
}
+7 -2
View File
@@ -383,8 +383,13 @@ mod tests {
#[test]
fn parse_add_opens_extracts_module_args() {
let tmp = tempfile::tempdir().unwrap();
let 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 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");
assert_eq!(
args,
+3 -1
View File
@@ -468,7 +468,9 @@ mod tests {
manager.touch_last_played("ticker").expect("touch");
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;
assert!(
age.num_seconds().abs() < 5,
+2 -5
View File
@@ -11,11 +11,8 @@ pub mod models;
pub mod screenshots;
pub use content::{
ContentEntry, toggle_entry,
scan_mods, scan_one_mod,
scan_resource_packs, scan_one_resource_pack,
scan_shaders, scan_one_shader,
scan_worlds, scan_one_world,
ContentEntry, scan_mods, scan_one_mod, scan_one_resource_pack, scan_one_shader, scan_one_world,
scan_resource_packs, scan_shaders, scan_worlds, toggle_entry,
};
pub use launch::LaunchError;
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
}
+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 {
let pairs = [
(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,
current.has_quick_plays_support,
+8 -2
View File
@@ -165,7 +165,10 @@ mod tests {
#[case::unclosed_placeholder("--prefix ${unclosed", "--prefix ${unclosed")]
#[case::dollar_without_brace("$$ literal $5 $", "$$ literal $5 $")]
#[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("", "")]
fn substitute_handles(#[case] input: &str, #[case] expected: &str) {
let fx = Fixture::unix();
@@ -178,7 +181,10 @@ mod tests {
// pattern. it should NOT trigger another substitution pass.
let mut fx = Fixture::unix();
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]
+5 -1
View File
@@ -39,7 +39,11 @@ fn rename_top_level(old: &Path, new: &Path) {
return;
}
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 => {
if let Err(e2) = copy_dir_recursive(old, new) {
eprintln!(
+1 -2
View File
@@ -113,8 +113,7 @@ pub async fn fetch_fabric_profile_with_raw(
game_version: &str,
loader_version: &str,
) -> Result<(FabricProfile, Vec<u8>), NetError> {
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version)
.await
fetch_fabric_profile_with_raw_from(client, FABRIC_META_BASE, game_version, loader_version).await
}
pub async fn fetch_fabric_profile_with_raw_from(
-1
View File
@@ -297,5 +297,4 @@ mod tests {
fn maven_empty_string() {
assert_eq!(maven_coord_to_path(""), None);
}
}
+14 -24
View File
@@ -92,9 +92,7 @@ impl ContentListState {
received = true;
let pos = self
.entries
.binary_search_by(|e| {
e.name.to_lowercase().cmp(&entry.name.to_lowercase())
})
.binary_search_by(|e| e.name.to_lowercase().cmp(&entry.name.to_lowercase()))
.unwrap_or_else(|i| i);
self.entries.insert(pos, entry);
}
@@ -160,8 +158,7 @@ impl ContentListState {
if self.entries.is_empty() {
self.list_state.selected = None;
} else {
self.list_state.selected =
Some(sel.min(self.entries.len().saturating_sub(1)));
self.list_state.selected = 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() {
if let Some((disk_path, disk_enabled)) = on_disk.get(stem) {
if *disk_enabled != *old_enabled || *disk_path != *old_path {
toggled.push((
stem.clone(),
*disk_enabled,
disk_path.clone(),
));
toggled.push((stem.clone(), *disk_enabled, disk_path.clone()));
}
} else {
removed.push(stem.clone());
@@ -366,16 +359,16 @@ impl ContentListState {
continue;
};
let (enabled, file_stem) =
if let Some(stem) = fname.strip_suffix(&disabled_ext) {
(false, stem.to_owned())
} else if let Some(stem) = fname.strip_suffix(ext) {
(true, stem.to_owned())
} else if path.is_dir() {
crate::instance::content::parse_enabled_stem_dir(fname)
} else {
continue;
};
let (enabled, file_stem) = if let Some(stem) = fname.strip_suffix(&disabled_ext)
{
(false, stem.to_owned())
} else if let Some(stem) = fname.strip_suffix(ext) {
(true, stem.to_owned())
} else if path.is_dir() {
crate::instance::content::parse_enabled_stem_dir(fname)
} else {
continue;
};
let entry = scan_one_fn(&path, &file_stem, enabled);
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
// thread to detect changes. when ext is empty (worlds), only directories
// are included.
fn read_dir_stems(
dir: &std::path::Path,
ext: &str,
) -> HashMap<String, (std::path::PathBuf, bool)> {
fn read_dir_stems(dir: &std::path::Path, ext: &str) -> HashMap<String, (std::path::PathBuf, bool)> {
let mut map = HashMap::new();
let Ok(read_dir) = std::fs::read_dir(dir) else {
return map;
+40 -8
View File
@@ -215,8 +215,16 @@ pub fn render(
ContentTab::Mods => {
if let Some(instance) = instance {
if mods_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("mods");
mods_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_mod, ".jar");
let content_dir = instances_dir
.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);
}
super::list::render(
@@ -238,8 +246,16 @@ pub fn render(
ContentTab::ResourcePacks => {
if let Some(instance) = instance {
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");
resource_packs_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_resource_pack, ".zip");
let content_dir = instances_dir
.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);
}
super::list::render(
@@ -261,8 +277,16 @@ pub fn render(
ContentTab::Shaders => {
if let Some(instance) = instance {
if shaders_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("shaderpacks");
shaders_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_shader, ".zip");
let content_dir = instances_dir
.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);
}
super::list::render(
@@ -322,8 +346,16 @@ pub fn render(
ContentTab::Worlds => {
if let Some(instance) = instance {
if worlds_state.loaded_for.as_deref() != Some(instance.name.as_str()) {
let content_dir = instances_dir.join(&instance.name).join(".minecraft").join("saves");
worlds_state.start_load(&content_dir, &instance.name, crate::instance::scan_one_world, "");
let content_dir = instances_dir
.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);
}
super::list::render(
+1 -1
View File
@@ -9,12 +9,12 @@ use ratatui::{
pub mod account;
pub mod content;
pub mod settings;
pub mod instances;
pub mod logs_viewer;
pub mod popups;
pub mod screenshots_grid;
pub mod search;
pub mod settings;
pub mod status;
// highlight the first character of a title with the accent color,
@@ -426,11 +426,8 @@ mod tests {
id: "1.20.1".into(),
stable: true,
}]);
guard.loader_versions = LoadState::Loaded(vec![
"47.2.0".into(),
"47.1.0".into(),
"47.0.50".into(),
]);
guard.loader_versions =
LoadState::Loaded(vec!["47.2.0".into(), "47.1.0".into(), "47.0.50".into()]);
}
let backend = TestBackend::new(60, 14);
+12 -3
View File
@@ -9,7 +9,10 @@ use ratatui::{
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::tui::app::FocusedArea;
@@ -66,8 +69,14 @@ pub fn render(
.add_modifier(Modifier::BOLD);
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_max = inst.memory_max.as_deref().unwrap_or(&SETTINGS.defaults.memory_max);
let memory_min = inst
.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
.java_path
.as_deref()