Anonymous user
Terminal control/Preserve screen: Difference between revisions
Add Rust version
(Add Rust version) |
|||
Line 430:
For those REXXes that don't have the '''scrsize''' BIF, the '''SCRSIZE.REX''' REXX program is included here ──► [[SCRSIZE.REX]]. <br><br>
=={{header|Rust}}==
{{trans|C}}
Uses xterm escape codes.
<lang rust>use std::io::{stdout, Write};
use std::time::Duration;
fn main() {
let mut output = stdout();
print!("\x1b[?1049h\x1b[H");
println!("Alternate screen buffer");
for i in (1..=5).rev() {
print!("\rgoing back in {}...", i);
output.flush().unwrap();
std::thread::sleep(Duration::from_secs(1));
}
print!("\x1b[?1049l");
}</lang>
The Rust [https://doc.rust-lang.org/std/ops/struct.RangeInclusive.html inclusive range operator] is used as an iterator from 1 to 5 (inclusive). It is then reversed to count down.
<code>\x1b</code> is used instead of the more usual <code>\033</code> because Rust string literals [https://doc.rust-lang.org/reference/tokens.html#character-escapes don't have octal escape codes].
=={{header|Scala}}==
|