mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 07:20:30 +00:00
Fix clearing the terminal
This commit is contained in:
parent
fef66b80ad
commit
52c0f5b39e
3 changed files with 13 additions and 16 deletions
|
@ -1,9 +1,5 @@
|
|||
use anyhow::{bail, Context, Result};
|
||||
use crossterm::{
|
||||
style::Stylize,
|
||||
terminal::{Clear, ClearType},
|
||||
ExecutableCommand,
|
||||
};
|
||||
use crossterm::style::Stylize;
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
|
@ -13,6 +9,7 @@ use std::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
clear_terminal,
|
||||
embedded::EMBEDDED_FILES,
|
||||
exercise::{Exercise, OUTPUT_CAPACITY},
|
||||
info_file::ExerciseInfo,
|
||||
|
@ -387,7 +384,7 @@ impl AppState {
|
|||
writeln!(writer, "{}", "ok".green())?;
|
||||
}
|
||||
|
||||
writer.execute(Clear(ClearType::All))?;
|
||||
clear_terminal(writer)?;
|
||||
writer.write_all(FENISH_LINE.as_bytes())?;
|
||||
|
||||
let final_message = self.final_message.trim();
|
||||
|
|
14
src/main.rs
14
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 => (),
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use crossterm::{
|
||||
style::{style, Stylize},
|
||||
terminal::{size, Clear, ClearType},
|
||||
ExecutableCommand,
|
||||
terminal::size,
|
||||
};
|
||||
use std::io::{self, StdoutLock, Write};
|
||||
|
||||
use crate::{
|
||||
app_state::{AppState, ExercisesProgress},
|
||||
clear_terminal,
|
||||
exercise::OUTPUT_CAPACITY,
|
||||
progress_bar::progress_bar,
|
||||
terminal_link::TerminalFileLink,
|
||||
|
@ -111,7 +111,7 @@ impl<'a> WatchState<'a> {
|
|||
// Prevent having the first line shifted.
|
||||
self.writer.write_all(b"\n")?;
|
||||
|
||||
self.writer.execute(Clear(ClearType::All))?;
|
||||
clear_terminal(&mut self.writer)?;
|
||||
|
||||
self.writer.write_all(&self.output)?;
|
||||
self.writer.write_all(b"\n")?;
|
||||
|
|
Loading…
Reference in a new issue