mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-28 06:49:19 +00:00
Merge 085d91d9b7128e4a5836dd992d785fa987b1d88b into 7850a73d95c02840f4ab3bf8d9571b08410e5467
This commit is contained in:
commit
a5f4e2eb2d
@ -97,6 +97,9 @@ fn run_watch(
|
|||||||
|
|
||||||
while let Ok(event) = watch_event_receiver.recv() {
|
while let Ok(event) = watch_event_receiver.recv() {
|
||||||
match event {
|
match event {
|
||||||
|
WatchEvent::Input(InputEvent::Previous) => {
|
||||||
|
watch_state.previous_exercise(&mut stdout)?
|
||||||
|
}
|
||||||
WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? {
|
WatchEvent::Input(InputEvent::Next) => match watch_state.next_exercise(&mut stdout)? {
|
||||||
ExercisesProgress::AllDone => break,
|
ExercisesProgress::AllDone => break,
|
||||||
ExercisesProgress::NewPending => watch_state.run_current_exercise(&mut stdout)?,
|
ExercisesProgress::NewPending => watch_state.run_current_exercise(&mut stdout)?,
|
||||||
|
|||||||
@ -93,12 +93,7 @@ impl<'a> WatchState<'a> {
|
|||||||
.run_exercise(Some(&mut self.output), self.app_state.cmd_runner())?;
|
.run_exercise(Some(&mut self.output), self.app_state.cmd_runner())?;
|
||||||
self.output.push(b'\n');
|
self.output.push(b'\n');
|
||||||
if success {
|
if success {
|
||||||
self.done_status =
|
self.done_status = self.completed_exercise_status()?;
|
||||||
if let Some(solution_path) = self.app_state.current_solution_path()? {
|
|
||||||
DoneStatus::DoneWithSolution(solution_path)
|
|
||||||
} else {
|
|
||||||
DoneStatus::DoneWithoutSolution
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
self.app_state
|
self.app_state
|
||||||
.set_pending(self.app_state.current_exercise_ind())?;
|
.set_pending(self.app_state.current_exercise_ind())?;
|
||||||
@ -171,6 +166,17 @@ impl<'a> WatchState<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn show_prompt(&self, stdout: &mut StdoutLock) -> io::Result<()> {
|
fn show_prompt(&self, stdout: &mut StdoutLock) -> io::Result<()> {
|
||||||
|
if self.app_state.current_exercise_ind() != 0 {
|
||||||
|
stdout.queue(SetAttribute(Attribute::Bold))?;
|
||||||
|
stdout.write_all(b"p")?;
|
||||||
|
stdout.queue(ResetColor)?;
|
||||||
|
stdout.write_all(b":")?;
|
||||||
|
stdout.queue(SetAttribute(Attribute::Underlined))?;
|
||||||
|
stdout.write_all(b"previous")?;
|
||||||
|
stdout.queue(ResetColor)?;
|
||||||
|
stdout.write_all(b" / ")?;
|
||||||
|
}
|
||||||
|
|
||||||
if self.done_status != DoneStatus::Pending {
|
if self.done_status != DoneStatus::Pending {
|
||||||
stdout.queue(SetAttribute(Attribute::Bold))?;
|
stdout.queue(SetAttribute(Attribute::Bold))?;
|
||||||
stdout.write_all(b"n")?;
|
stdout.write_all(b"n")?;
|
||||||
@ -296,4 +302,31 @@ impl<'a> WatchState<'a> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn completed_exercise_status(&self) -> Result<DoneStatus> {
|
||||||
|
if let Some(solution_path) = self.app_state.current_solution_path()? {
|
||||||
|
Ok(DoneStatus::DoneWithSolution(solution_path))
|
||||||
|
} else {
|
||||||
|
Ok(DoneStatus::DoneWithoutSolution)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn previous_exercise(&mut self, stdout: &mut StdoutLock) -> Result<()> {
|
||||||
|
let current_exercise_ind = self.app_state.current_exercise_ind();
|
||||||
|
|
||||||
|
if current_exercise_ind == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.app_state
|
||||||
|
.set_current_exercise_ind(current_exercise_ind - 1)?;
|
||||||
|
self.done_status = if self.app_state.current_exercise().done {
|
||||||
|
self.completed_exercise_status()?
|
||||||
|
} else {
|
||||||
|
DoneStatus::Pending
|
||||||
|
};
|
||||||
|
self.render(stdout)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use std::sync::{
|
|||||||
use super::{EXERCISE_RUNNING, WatchEvent};
|
use super::{EXERCISE_RUNNING, WatchEvent};
|
||||||
|
|
||||||
pub enum InputEvent {
|
pub enum InputEvent {
|
||||||
|
Previous,
|
||||||
Next,
|
Next,
|
||||||
Run,
|
Run,
|
||||||
Hint,
|
Hint,
|
||||||
@ -34,6 +35,7 @@ pub fn terminal_event_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let input_event = match key.code {
|
let input_event = match key.code {
|
||||||
|
KeyCode::Char('p') => InputEvent::Previous,
|
||||||
KeyCode::Char('n') => InputEvent::Next,
|
KeyCode::Char('n') => InputEvent::Next,
|
||||||
KeyCode::Char('r') if manual_run => InputEvent::Run,
|
KeyCode::Char('r') if manual_run => InputEvent::Run,
|
||||||
KeyCode::Char('h') => InputEvent::Hint,
|
KeyCode::Char('h') => InputEvent::Hint,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user