Add an option to drop you into shell for fixing a step
This commit is contained in:
@@ -3,12 +3,24 @@ use console::{style, Term};
|
|||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
|
use std::process::Command;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TERMINAL: Mutex<Terminal> = Mutex::new(Terminal::new());
|
static ref TERMINAL: Mutex<Terminal> = Mutex::new(Terminal::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn shell() -> String {
|
||||||
|
use std::env;
|
||||||
|
env::var("SHELL").unwrap_or_else(|_| "sh".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn shell() -> &'static str {
|
||||||
|
"powershell"
|
||||||
|
}
|
||||||
|
|
||||||
struct Terminal {
|
struct Terminal {
|
||||||
width: Option<u16>,
|
width: Option<u16>,
|
||||||
term: Term,
|
term: Term,
|
||||||
@@ -92,7 +104,7 @@ impl Terminal {
|
|||||||
.write_fmt(format_args!(
|
.write_fmt(format_args!(
|
||||||
"\n{}",
|
"\n{}",
|
||||||
style(format!(
|
style(format!(
|
||||||
"Retry? [y/N] {}",
|
"Retry? (Y)es/(N)o/(S)hell {}",
|
||||||
if interrupted {
|
if interrupted {
|
||||||
"(Press Ctrl+C again to stop Topgrade) "
|
"(Press Ctrl+C again to stop Topgrade) "
|
||||||
} else {
|
} else {
|
||||||
@@ -107,7 +119,12 @@ impl Terminal {
|
|||||||
let answer = loop {
|
let answer = loop {
|
||||||
match self.term.read_char()? {
|
match self.term.read_char()? {
|
||||||
'y' | 'Y' => break Ok(true),
|
'y' | 'Y' => break Ok(true),
|
||||||
'n' | 'N' | '\r' | '\n' => break Ok(false),
|
's' | 'S' => {
|
||||||
|
println!("\n\nDropping you to shell. Fix what you need and then exit the shell.\n");
|
||||||
|
Command::new(shell()).spawn().unwrap().wait().unwrap();
|
||||||
|
break Ok(true);
|
||||||
|
}
|
||||||
|
'n' | 'N' => break Ok(false),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user