mirror of
https://github.com/typst/typst
synced 2025-05-16 18:15:29 +08:00
Display compilation time in status message (#1564)
This commit is contained in:
parent
529bac11b6
commit
48c25f4da0
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user