From 52c0f5b39efd7c71e63a3a680a1d91f3efc8eda5 Mon Sep 17 00:00:00 2001 From: mo8it Date: Tue, 30 Apr 2024 01:41:08 +0200 Subject: Fix clearing the terminal --- src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index c51f63c..3e37ce2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 => (), } -- cgit v1.2.3