diff options
| author | mo8it <mo8it@proton.me> | 2024-04-27 04:14:59 +0200 |
|---|---|---|
| committer | mo8it <mo8it@proton.me> | 2024-04-27 04:14:59 +0200 |
| commit | c82c3673245ca11d455b067c97fadda4a8406cb9 (patch) | |
| tree | 42b2a226714a5f5f97797f74611dd7d3fd3d183b /src/app_state.rs | |
| parent | dc5c72bc19951313e80f038961fb446bd6ea02f5 (diff) | |
Respect the target-dir config and show tests' output
Diffstat (limited to 'src/app_state.rs')
| -rw-r--r-- | src/app_state.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/app_state.rs b/src/app_state.rs index 476b5a9..b980bdb 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -7,7 +7,7 @@ use crossterm::{ use std::{ fs::{self, File}, io::{Read, StdoutLock, Write}, - path::Path, + path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -39,6 +39,7 @@ pub struct AppState { final_message: String, file_buf: Vec<u8>, official_exercises: bool, + target_dir: PathBuf, } impl AppState { @@ -90,6 +91,7 @@ impl AppState { pub fn new( exercise_infos: Vec<ExerciseInfo>, final_message: String, + target_dir: PathBuf, ) -> (Self, StateFileStatus) { let exercises = exercise_infos .into_iter() @@ -127,6 +129,7 @@ impl AppState { final_message, file_buf: Vec::with_capacity(2048), official_exercises: !Path::new("info.toml").exists(), + target_dir, }; let state_file_status = slf.update_from_file(); @@ -154,6 +157,11 @@ impl AppState { &self.exercises[self.current_exercise_ind] } + #[inline] + pub fn target_dir(&self) -> &Path { + &self.target_dir + } + pub fn set_current_exercise_ind(&mut self, ind: usize) -> Result<()> { if ind >= self.exercises.len() { bail!(BAD_INDEX_ERR); @@ -313,7 +321,7 @@ impl AppState { write!(writer, "Running {exercise} ... ")?; writer.flush()?; - let success = exercise.run(&mut output)?; + let success = exercise.run(&mut output, &self.target_dir)?; if !success { writeln!(writer, "{}\n", "FAILED".red())?; |
