Skip to content

Commit

Permalink
refactor: Move main up in main.rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
zedseven committed Jan 13, 2024
1 parent 0fe4f88 commit 49873c3
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ const DEFAULT_TITLE: &str = "`breeze` Presentation";
/// [Emulsion]: https://github.com/ArturKovacs/emulsion/blob/db5992432ca9f3e0044b967713316ce267e64837/src/widgets/picture_widget.rs#L35
const IMAGE_SAMPLING_NEAREST_NEIGHBOUR_SCALING_FACTOR_MINIMUM: f32 = 4.0;

// Entry Point
fn main() -> AnyhowResult<()> {
// Read the file path from the command line
let args = args().collect::<Vec<_>>();
if args.len() != 2 {
return Err(anyhow!("exactly one argument, the file path, is required"));
}
let file_path = PathBuf::from(&args[1]);

// Load the presentation
let presentation = Presentation::load_from_path(file_path.clone())
.with_context(|| "unable to load the presentation")?;

// Load all images into memory
let base_path = file_path.parent();
let image_cache = load_images_from_presentation(&presentation, base_path)
.with_context(|| "unable to load a presentation image")?;

// Run the presentation
run_presentation(&presentation, image_cache)
}

fn load_images_from_presentation<'a>(
presentation: &'a Presentation,
base_path: Option<&Path>,
Expand Down Expand Up @@ -125,28 +147,6 @@ fn load_images_from_presentation<'a>(
Ok(image_cache)
}

// Entry Point
fn main() -> AnyhowResult<()> {
// Read the file path from the command line
let args = args().collect::<Vec<_>>();
if args.len() != 2 {
return Err(anyhow!("exactly one argument, the file path, is required"));
}
let file_path = PathBuf::from(&args[1]);

// Load the presentation
let presentation = Presentation::load_from_path(file_path.clone())
.with_context(|| "unable to load the presentation")?;

// Load all images into memory
let base_path = file_path.parent();
let image_cache = load_images_from_presentation(&presentation, base_path)
.with_context(|| "unable to load a presentation image")?;

// Run the presentation
run_presentation(&presentation, image_cache)
}

fn run_presentation(
presentation: &Presentation,
image_cache: HashMap<&String, DynamicImage>,
Expand Down

0 comments on commit 49873c3

Please sign in to comment.