diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 12786d0..edb3e14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,11 @@ use anyhow::{bail, Context, Result}; use app_state::StateFileStatus; use clap::{Parser, Subcommand}; use std::{ - io::{self, BufRead, IsTerminal, StdoutLock, Write}, + io::{self, IsTerminal, Write}, path::Path, process::exit, }; +use term::{clear_terminal, press_enter_prompt}; use self::{app_state::AppState, dev::DevCommands, info_file::InfoFile, watch::WatchExit}; @@ -20,20 +21,12 @@ mod init; mod list; mod progress_bar; mod run; +mod term; mod terminal_link; mod watch; const CURRENT_FORMAT_VERSION: u8 = 1; -fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> { - stdout.write_all(b"\x1b[H\x1b[2J\x1b[3J") -} - -fn press_enter_prompt() -> io::Result<()> { - io::stdin().lock().read_until(b'\n', &mut Vec::new())?; - Ok(()) -} - /// Rustlings is a collection of small exercises to get you used to writing and reading Rust code #[derive(Parser)] #[command(version)] @@ -79,14 +72,6 @@ fn main() -> Result<()> { match args.command { Some(Subcommands::Init) => { - { - let mut stdout = io::stdout().lock(); - stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\nPress ENTER to continue ")?; - stdout.flush()?; - press_enter_prompt()?; - stdout.write_all(b"\n")?; - } - return init::init().context("Initialization failed"); } Some(Subcommands::Dev(dev_command)) => return dev_command.run(), @@ -118,8 +103,7 @@ fn main() -> Result<()> { let welcome_message = welcome_message.trim_ascii(); write!(stdout, "{welcome_message}\n\nPress ENTER to continue ")?; - stdout.flush()?; - press_enter_prompt()?; + press_enter_prompt(&mut stdout)?; clear_terminal(&mut stdout)?; // Flush to be able to show errors occuring before printing a newline to stdout. stdout.flush()?; |
