summaryrefslogtreecommitdiff
path: root/crates/typst-cli
diff options
context:
space:
mode:
authorY.D.X. <73375426+YDX-2147483647@users.noreply.github.com>2025-06-11 22:21:05 +0800
committerGitHub <noreply@github.com>2025-06-11 14:21:05 +0000
commit19325d5027cf8b318cb1d829f18ef2d3b2fea707 (patch)
treed198603d7c8ecc473a45c2b40e61f5c85bab524d /crates/typst-cli
parent1f5846ce246672701fbec918db9b1d05c8920895 (diff)
Warning when watching stdin (#6381)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'crates/typst-cli')
-rw-r--r--crates/typst-cli/src/watch.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/typst-cli/src/watch.rs b/crates/typst-cli/src/watch.rs
index 0813d8ff..630d340b 100644
--- a/crates/typst-cli/src/watch.rs
+++ b/crates/typst-cli/src/watch.rs
@@ -10,11 +10,12 @@ use codespan_reporting::term::{self, termcolor};
use ecow::eco_format;
use notify::{Event, RecommendedWatcher, RecursiveMode, Watcher as _};
use same_file::is_same_file;
-use typst::diag::{bail, StrResult};
+use typst::diag::{bail, warning, StrResult};
+use typst::syntax::Span;
use typst::utils::format_duration;
use crate::args::{Input, Output, WatchCommand};
-use crate::compile::{compile_once, CompileConfig};
+use crate::compile::{compile_once, print_diagnostics, CompileConfig};
use crate::timings::Timer;
use crate::world::{SystemWorld, WorldCreationError};
use crate::{print_error, terminal};
@@ -55,6 +56,11 @@ pub fn watch(timer: &mut Timer, command: &WatchCommand) -> StrResult<()> {
// Perform initial compilation.
timer.record(&mut world, |world| compile_once(world, &mut config))??;
+ // Print warning when trying to watch stdin.
+ if matches!(&config.input, Input::Stdin) {
+ warn_watching_std(&world, &config)?;
+ }
+
// Recompile whenever something relevant happens.
loop {
// Watch all dependencies of the most recent compilation.
@@ -332,3 +338,15 @@ impl Status {
}
}
}
+
+/// Emits a warning when trying to watch stdin.
+fn warn_watching_std(world: &SystemWorld, config: &CompileConfig) -> StrResult<()> {
+ let warning = warning!(
+ Span::detached(),
+ "cannot watch changes for stdin";
+ hint: "to recompile on changes, watch a regular file instead";
+ hint: "to compile once and exit, please use `typst compile` instead"
+ );
+ print_diagnostics(world, &[], &[warning], config.diagnostic_format)
+ .map_err(|err| eco_format!("failed to print diagnostics ({err})"))
+}