mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-03 00:43:29 +02:00
Fix clearing the terminal
This commit is contained in:
+7
-7
@@ -1,12 +1,8 @@
|
||||
use anyhow::{bail, Context, Result};
|
||||
use app_state::StateFileStatus;
|
||||
use clap::{Parser, Subcommand};
|
||||
use crossterm::{
|
||||
terminal::{Clear, ClearType},
|
||||
ExecutableCommand,
|
||||
};
|
||||
use std::{
|
||||
io::{self, BufRead, Write},
|
||||
io::{self, BufRead, StdoutLock, Write},
|
||||
path::Path,
|
||||
process::exit,
|
||||
};
|
||||
@@ -45,6 +41,10 @@ fn in_official_repo() -> bool {
|
||||
Path::new("dev/rustlings-repo.txt").exists()
|
||||
}
|
||||
|
||||
fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> {
|
||||
stdout.write_all(b"\x1b[H\x1b[2J\x1b[3J")
|
||||
}
|
||||
|
||||
/// Rustlings is a collection of small exercises to get you used to writing and reading Rust code
|
||||
#[derive(Parser)]
|
||||
#[command(version)]
|
||||
@@ -129,7 +129,7 @@ fn main() -> Result<()> {
|
||||
match state_file_status {
|
||||
StateFileStatus::NotRead => {
|
||||
let mut stdout = io::stdout().lock();
|
||||
stdout.execute(Clear(ClearType::All))?;
|
||||
clear_terminal(&mut stdout)?;
|
||||
|
||||
let welcome_message = welcome_message.trim();
|
||||
write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?;
|
||||
@@ -137,7 +137,7 @@ fn main() -> Result<()> {
|
||||
|
||||
io::stdin().lock().read_until(b'\n', &mut Vec::new())?;
|
||||
|
||||
stdout.execute(Clear(ClearType::All))?;
|
||||
clear_terminal(&mut stdout)?;
|
||||
}
|
||||
StateFileStatus::Read => (),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user