rustlings/src/term.rs

23 lines
553 B
Rust
Raw Normal View History

2024-08-07 20:45:18 -04:00
use std::io::{self, BufRead, StdoutLock, Write};
2024-08-23 18:14:12 -04:00
use crossterm::{
cursor::MoveTo,
terminal::{Clear, ClearType},
QueueableCommand,
};
2024-08-07 20:45:18 -04:00
pub fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> {
2024-08-23 18:14:12 -04:00
stdout
.queue(MoveTo(0, 0))?
.queue(Clear(ClearType::All))?
.queue(Clear(ClearType::Purge))
.map(|_| ())
2024-08-07 20:45:18 -04:00
}
pub fn press_enter_prompt(stdout: &mut StdoutLock) -> io::Result<()> {
stdout.flush()?;
io::stdin().lock().read_until(b'\n', &mut Vec::new())?;
stdout.write_all(b"\n")?;
Ok(())
}