summaryrefslogtreecommitdiff
path: root/src/run.rs
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-08-25 23:53:50 +0200
committermo8it <mo8it@proton.me>2024-08-25 23:53:50 +0200
commitb1898f6d8b2c2ae45279ca4c67fa1b1a94acb936 (patch)
tree25022e8fc2bc6254fc819d98ea278f04dd5d6bab /src/run.rs
parentd29e9e7e07a16adda35aea9ce9dd120b6ecc9dfc (diff)
Use queue instead of Stylize
Diffstat (limited to 'src/run.rs')
-rw-r--r--src/run.rs54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/run.rs b/src/run.rs
index 09e53ec..929b475 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,11 +1,17 @@
-use anyhow::{bail, Result};
-use crossterm::style::{style, Stylize};
-use std::io::{self, Write};
+use anyhow::Result;
+use crossterm::{
+ style::{Color, ResetColor, SetForegroundColor},
+ QueueableCommand,
+};
+use std::{
+ io::{self, Write},
+ process::exit,
+};
use crate::{
app_state::{AppState, ExercisesProgress},
- exercise::{RunnableExercise, OUTPUT_CAPACITY},
- terminal_link::TerminalFileLink,
+ exercise::{solution_link_line, RunnableExercise, OUTPUT_CAPACITY},
+ term::terminal_file_link,
};
pub fn run(app_state: &mut AppState) -> Result<()> {
@@ -19,35 +25,31 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
if !success {
app_state.set_pending(app_state.current_exercise_ind())?;
- bail!(
- "Ran {} with errors",
- app_state.current_exercise().terminal_link(),
- );
+ stdout.write_all(b"Ran ")?;
+ terminal_file_link(&mut stdout, app_state.current_exercise().path, Color::Blue)?;
+ stdout.write_all(b" with errors\n")?;
+ exit(1);
}
- writeln!(
- stdout,
- "{}{}",
- "✓ Successfully ran ".green(),
- exercise.path.green(),
- )?;
+ stdout.queue(SetForegroundColor(Color::Green))?;
+ stdout.write_all("✓ Successfully ran ".as_bytes())?;
+ stdout.write_all(exercise.path.as_bytes())?;
+ stdout.queue(ResetColor)?;
+ stdout.write_all(b"\n")?;
if let Some(solution_path) = app_state.current_solution_path()? {
- writeln!(
- stdout,
- "\n{} for comparison: {}\n",
- "Solution".bold(),
- style(TerminalFileLink(&solution_path)).underlined().cyan(),
- )?;
+ stdout.write_all(b"\n")?;
+ solution_link_line(&mut stdout, &solution_path)?;
+ stdout.write_all(b"\n")?;
}
match app_state.done_current_exercise(&mut stdout)? {
+ ExercisesProgress::CurrentPending | ExercisesProgress::NewPending => {
+ stdout.write_all(b"Next exercise: ")?;
+ terminal_file_link(&mut stdout, app_state.current_exercise().path, Color::Blue)?;
+ stdout.write_all(b"\n")?;
+ }
ExercisesProgress::AllDone => (),
- ExercisesProgress::CurrentPending | ExercisesProgress::NewPending => writeln!(
- stdout,
- "Next exercise: {}",
- app_state.current_exercise().terminal_link(),
- )?,
}
Ok(())