Allow initialization in a workspace

This commit is contained in:
mo8it
2024-08-08 02:45:18 +02:00
parent 39580381fa
commit 8df66f7991
3 changed files with 66 additions and 43 deletions
+4 -20
View File
@@ -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()?;