mirror of
https://git.aramjonghu.dev/AramJonghu/rustlings.git
synced 2026-09-02 16:33:30 +02:00
Add the manual-run option
This commit is contained in:
+7
-1
@@ -18,10 +18,11 @@ pub struct WatchState<'a> {
|
||||
stderr: Option<Vec<u8>>,
|
||||
show_hint: bool,
|
||||
show_done: bool,
|
||||
manual_run: bool,
|
||||
}
|
||||
|
||||
impl<'a> WatchState<'a> {
|
||||
pub fn new(app_state: &'a mut AppState) -> Self {
|
||||
pub fn new(app_state: &'a mut AppState, manual_run: bool) -> Self {
|
||||
let writer = io::stdout().lock();
|
||||
|
||||
Self {
|
||||
@@ -31,6 +32,7 @@ impl<'a> WatchState<'a> {
|
||||
stderr: None,
|
||||
show_hint: false,
|
||||
show_done: false,
|
||||
manual_run,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +80,10 @@ impl<'a> WatchState<'a> {
|
||||
fn show_prompt(&mut self) -> io::Result<()> {
|
||||
self.writer.write_all(b"\n")?;
|
||||
|
||||
if self.manual_run {
|
||||
self.writer.write_fmt(format_args!("{}un/", 'r'.bold()))?;
|
||||
}
|
||||
|
||||
if self.show_done {
|
||||
self.writer.write_fmt(format_args!("{}ext/", 'n'.bold()))?;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::sync::mpsc::Sender;
|
||||
use super::WatchEvent;
|
||||
|
||||
pub enum InputEvent {
|
||||
Run,
|
||||
Next,
|
||||
Hint,
|
||||
List,
|
||||
@@ -11,7 +12,7 @@ pub enum InputEvent {
|
||||
Unrecognized(String),
|
||||
}
|
||||
|
||||
pub fn terminal_event_handler(tx: Sender<WatchEvent>) {
|
||||
pub fn terminal_event_handler(tx: Sender<WatchEvent>, manual_run: bool) {
|
||||
let mut input = String::with_capacity(8);
|
||||
|
||||
let last_input_event = loop {
|
||||
@@ -43,6 +44,7 @@ pub fn terminal_event_handler(tx: Sender<WatchEvent>) {
|
||||
"h" | "hint" => InputEvent::Hint,
|
||||
"l" | "list" => break InputEvent::List,
|
||||
"q" | "quit" => break InputEvent::Quit,
|
||||
"r" | "run" if manual_run => InputEvent::Run,
|
||||
_ => InputEvent::Unrecognized(input.clone()),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user