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)]
|
#[tracing::instrument(skip_all)]
|
||||||
fn compile_once(world: &mut SystemWorld, command: &CompileSettings) -> StrResult<bool> {
|
fn compile_once(world: &mut SystemWorld, command: &CompileSettings) -> StrResult<bool> {
|
||||||
tracing::info!("Starting compilation");
|
tracing::info!("Starting compilation");
|
||||||
|
let start_time = std::time::Instant::now();
|
||||||
|
|
||||||
status(command, Status::Compiling).unwrap();
|
status(command, Status::Compiling).unwrap();
|
||||||
|
|
||||||
world.reset();
|
world.reset();
|
||||||
world.main = world.resolve(&command.input).map_err(|err| err.to_string())?;
|
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.
|
// Export the PDF / PNG.
|
||||||
Ok(document) => {
|
Ok(document) => {
|
||||||
export(&document, command)?;
|
export(&document, command)?;
|
||||||
status(command, Status::Success).unwrap();
|
status(command, Status::Success(duration)).unwrap();
|
||||||
tracing::info!("Compilation succeeded");
|
tracing::info!("Compilation succeeded in {duration:?}");
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +327,7 @@ fn compile_once(world: &mut SystemWorld, command: &CompileSettings) -> StrResult
|
|||||||
status(command, Status::Error).unwrap();
|
status(command, Status::Error).unwrap();
|
||||||
print_diagnostics(world, *errors, command.diagnostic_format)
|
print_diagnostics(world, *errors, command.diagnostic_format)
|
||||||
.map_err(|_| "failed to print diagnostics")?;
|
.map_err(|_| "failed to print diagnostics")?;
|
||||||
tracing::info!("Compilation failed");
|
tracing::info!("Compilation failed after {duration:?}");
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -417,16 +420,16 @@ fn color_stream() -> termcolor::StandardStream {
|
|||||||
/// The status in which the watcher can be.
|
/// The status in which the watcher can be.
|
||||||
enum Status {
|
enum Status {
|
||||||
Compiling,
|
Compiling,
|
||||||
Success,
|
Success(std::time::Duration),
|
||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
fn message(&self) -> &str {
|
fn message(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Compiling => "compiling ...",
|
Self::Compiling => "compiling ...".to_string(),
|
||||||
Self::Success => "compiled successfully",
|
Self::Success(duration) => format!("compiled successfully in {duration:.2?}"),
|
||||||
Self::Error => "compiled with errors",
|
Self::Error => "compiled with errors".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user