From 01ce04f92783da64bd7d55f641bc49f19f818d5a Mon Sep 17 00:00:00 2001 From: Jaby Date: Thu, 17 Nov 2022 03:13:12 +0100 Subject: [PATCH] Improve output design --- src/Tools/psxcdgen_ex/src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Tools/psxcdgen_ex/src/lib.rs b/src/Tools/psxcdgen_ex/src/lib.rs index 134be4d8..6cddfae2 100644 --- a/src/Tools/psxcdgen_ex/src/lib.rs +++ b/src/Tools/psxcdgen_ex/src/lib.rs @@ -17,14 +17,16 @@ pub fn process(config: config_reader::Configuration, calculate_lba: CalculateLBA Ok(cd_desc) } -pub fn dump_content(cd_desc: &CDDesc, out: Output) -> Result<(), Error> { - fn dump_dir(dir: &Directory, mut out: Output) -> Result<(), Error> { +pub fn dump_content(cd_desc: &CDDesc, mut out: Output) -> Result<(), Error> { + fn dump_dir(dir: &Directory, out: &mut Output, indent: usize) -> Result<(), Error> { + const INDENT_STEP:usize = 4; + for file in dir.file_iter() { let file = file.borrow(); let file_name = file.name.as_string().unwrap_or("".to_owned()); let file_lba = file.get_track_rel_lba(); - writeln!(out, "File: {} @{}", file_name, file_lba)?; + writeln!(out, "{:indent$}File: {} @{}", " ", file_name, file_lba, indent=indent)?; } for dir in dir.dir_iter() { @@ -32,13 +34,14 @@ pub fn dump_content(cd_desc: &CDDesc, out: Output) -> Result<(), Error> { let dir_name = dir.name.as_str().unwrap_or(""); let dir_lba = dir.get_track_rel_lba(); - writeln!(out, "Dir: {} @{}", dir_name, dir_lba)?; + writeln!(out, "{:indent$}Dir: {} @{}", " ", dir_name, dir_lba, indent=indent)?; + dump_dir(&dir, out, indent + INDENT_STEP)?; } Ok(()) } - format_if_error!(dump_dir(&cd_desc.root.borrow(), out), "Creating content dump failed with: {error_text}") + format_if_error!(dump_dir(&cd_desc.root.borrow(), &mut out, 0), "Creating content dump failed with: {error_text}") } fn parse_configuration(config: config_reader::Configuration) -> Result {