Implement going to the next exercise

This commit is contained in:
mo8it
2024-04-12 15:27:29 +02:00
parent 98c5088a39
commit a534de0312
3 changed files with 31 additions and 5 deletions
+22 -1
View File
@@ -6,7 +6,10 @@ use crossterm::{
};
use std::io::{self, StdoutLock, Write};
use crate::{app_state::AppState, progress_bar::progress_bar};
use crate::{
app_state::{AppState, ExercisesProgress},
progress_bar::progress_bar,
};
pub struct WatchState<'a> {
writer: StdoutLock<'a>,
@@ -58,9 +61,27 @@ impl<'a> WatchState<'a> {
self.run_current_exercise()
}
pub fn next_exercise(&mut self) -> Result<()> {
if !self.show_done {
self.writer
.write_all(b"The current exercise isn't done yet\n")?;
self.show_prompt()?;
return Ok(());
}
match self.app_state.done_current_exercise()? {
ExercisesProgress::AllDone => todo!(),
ExercisesProgress::Pending => self.run_current_exercise(),
}
}
fn show_prompt(&mut self) -> io::Result<()> {
self.writer.write_all(b"\n")?;
if self.show_done {
self.writer.write_fmt(format_args!("{}ext/", 'n'.bold()))?;
}
if !self.show_hint {
self.writer.write_fmt(format_args!("{}int/", 'h'.bold()))?;
}