Files
texrra-engine/vendor/texlang-stdlib/src/sleep.rs
T
gloamxun bb1d9e0561 Initial texrra engine
Rename the crate, binary, core crate, font families, env vars, and internal commands from texcraft/tex-engine to texrra. Serve the separately versioned texrra-web frontend from TEXRRA_WEB_DIR, ../web, or ./web instead of embedding index.html. Add starred section heading support and an arXiv template conformance fixture.
2026-10-19 11:41:46 +08:00

27 lines
878 B
Rust

//! Primitive that pauses execution for a duration of time
use std::thread;
use std::time;
use texlang::prelude as txl;
use texlang::traits::*;
use texlang::*;
use texlang_common as common;
pub const SLEEP_DOC: &str = "Sleep for a number of milliseconds";
/// Get the `\sleep` expansion primitive.
pub fn get_sleep<S: TexlangState + common::HasLogging>() -> command::BuiltIn<S> {
command::BuiltIn::new_execution(
|_: token::Token, input: &mut vm::ExecutionInput<S>| -> txl::Result<()> {
let milliseconds = parse::Uint::<{ parse::Uint::MAX }>::parse(input)?.0;
writeln![
input.state().terminal_out().borrow_mut(),
"\\sleep: sleeping for {milliseconds}ms",
]
.unwrap();
thread::sleep(time::Duration::from_millis(milliseconds as u64));
Ok(())
},
)
}