diff options
| author | Joseph Wilson <jo.alex.w@gmail.com> | 2023-06-25 00:32:38 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-24 14:32:38 +0200 |
| commit | 48c25f4da01aa5cbd5e49145f591c85b676e8a54 (patch) | |
| tree | 28c6cf29fe5c435a9b182529adc0ec27a4728246 /cli/src/main.rs | |
| parent | 529bac11b64d658460ae53364559e5fa6eb4fb67 (diff) | |
Display compilation time in status message (#1564)
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index 19edd6d7..026b11ed 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -303,18 +303,21 @@ fn compile(mut command: CompileSettings) -> StrResult<()> { #[tracing::instrument(skip_all)] fn compile_once(world: &mut SystemWorld, command: &CompileSettings) -> StrResult<bool> { tracing::info!("Starting compilation"); + let start_time = std::time::Instant::now(); status(command, Status::Compiling).unwrap(); world.reset(); world.main = world.resolve(&command.input).map_err(|err| err.to_string())?; - match typst::compile(world) { + let result = typst::compile(world); + let duration = start_time.elapsed(); + match result { // Export the PDF / PNG. Ok(document) => { export(&document, command)?; - status(command, Status::Success).unwrap(); - tracing::info!("Compilation succeeded"); + status(command, Status::Success(duration)).unwrap(); + tracing::info!("Compilation succeeded in {duration:?}"); Ok(true) } @@ -324,7 +327,7 @@ fn compile_once(world: &mut SystemWorld, command: &CompileSettings) -> StrResult status(command, Status::Error).unwrap(); print_diagnostics(world, *errors, command.diagnostic_format) .map_err(|_| "failed to print diagnostics")?; - tracing::info!("Compilation failed"); + tracing::info!("Compilation failed after {duration:?}"); Ok(false) } } @@ -417,16 +420,16 @@ fn color_stream() -> termcolor::StandardStream { /// The status in which the watcher can be. enum Status { Compiling, - Success, + Success(std::time::Duration), Error, } impl Status { - fn message(&self) -> &str { + fn message(&self) -> String { match self { - Self::Compiling => "compiling ...", - Self::Success => "compiled successfully", - Self::Error => "compiled with errors", + Self::Compiling => "compiling ...".to_string(), + Self::Success(duration) => format!("compiled successfully in {duration:.2?}"), + Self::Error => "compiled with errors".to_string(), } } |
