mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 14:02:22 -05:00
Use write macros instead of write_fmt
This commit is contained in:
parent
67fa017742
commit
f92d45fa68
4 changed files with 28 additions and 25 deletions
|
@ -309,12 +309,12 @@ impl AppState {
|
||||||
|
|
||||||
let mut output = Vec::with_capacity(OUTPUT_CAPACITY);
|
let mut output = Vec::with_capacity(OUTPUT_CAPACITY);
|
||||||
for (exercise_ind, exercise) in self.exercises().iter().enumerate() {
|
for (exercise_ind, exercise) in self.exercises().iter().enumerate() {
|
||||||
writer.write_fmt(format_args!("Running {exercise} ... "))?;
|
write!(writer, "Running {exercise} ... ")?;
|
||||||
writer.flush()?;
|
writer.flush()?;
|
||||||
|
|
||||||
let success = exercise.run(&mut output)?;
|
let success = exercise.run(&mut output)?;
|
||||||
if !success {
|
if !success {
|
||||||
writer.write_fmt(format_args!("{}\n\n", "FAILED".red()))?;
|
writeln!(writer, "{}\n", "FAILED".red())?;
|
||||||
|
|
||||||
self.current_exercise_ind = exercise_ind;
|
self.current_exercise_ind = exercise_ind;
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ impl AppState {
|
||||||
return Ok(ExercisesProgress::Pending);
|
return Ok(ExercisesProgress::Pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.write_fmt(format_args!("{}\n", "ok".green()))?;
|
writeln!(writer, "{}", "ok".green())?;
|
||||||
|
|
||||||
output.clear();
|
output.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,8 +231,7 @@ impl<'a> UiState<'a> {
|
||||||
.context("Invalid selection index")?;
|
.context("Invalid selection index")?;
|
||||||
|
|
||||||
let exercise_path = self.app_state.reset_exercise_by_ind(ind)?;
|
let exercise_path = self.app_state.reset_exercise_by_ind(ind)?;
|
||||||
self.message
|
write!(self.message, "The exercise {exercise_path} has been reset")?;
|
||||||
.write_fmt(format_args!("The exercise {exercise_path} has been reset"))?;
|
|
||||||
|
|
||||||
Ok(self.with_updated_rows())
|
Ok(self.with_updated_rows())
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,12 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.write_fmt(format_args!(
|
writeln!(
|
||||||
"{}{}\n",
|
stdout,
|
||||||
|
"{}{}",
|
||||||
"✓ Successfully ran ".green(),
|
"✓ Successfully ran ".green(),
|
||||||
exercise.path.green(),
|
exercise.path.green(),
|
||||||
))?;
|
)?;
|
||||||
|
|
||||||
if let Some(solution_path) = app_state.current_solution_path()? {
|
if let Some(solution_path) = app_state.current_solution_path()? {
|
||||||
println!(
|
println!(
|
||||||
|
|
|
@ -88,19 +88,18 @@ impl<'a> WatchState<'a> {
|
||||||
self.writer.write_all(b"\n")?;
|
self.writer.write_all(b"\n")?;
|
||||||
|
|
||||||
if self.manual_run {
|
if self.manual_run {
|
||||||
self.writer.write_fmt(format_args!("{}un/", 'r'.bold()))?;
|
write!(self.writer, "{}un/", 'r'.bold())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches!(self.done_status, DoneStatus::Pending) {
|
if !matches!(self.done_status, DoneStatus::Pending) {
|
||||||
self.writer.write_fmt(format_args!("{}ext/", 'n'.bold()))?;
|
write!(self.writer, "{}ext/", 'n'.bold())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.show_hint {
|
if !self.show_hint {
|
||||||
self.writer.write_fmt(format_args!("{}int/", 'h'.bold()))?;
|
write!(self.writer, "{}int/", 'h'.bold())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.writer
|
write!(self.writer, "{}ist/{}uit? ", 'l'.bold(), 'q'.bold())?;
|
||||||
.write_fmt(format_args!("{}ist/{}uit? ", 'l'.bold(), 'q'.bold()))?;
|
|
||||||
|
|
||||||
self.writer.flush()
|
self.writer.flush()
|
||||||
}
|
}
|
||||||
|
@ -115,28 +114,31 @@ impl<'a> WatchState<'a> {
|
||||||
self.writer.write_all(b"\n")?;
|
self.writer.write_all(b"\n")?;
|
||||||
|
|
||||||
if self.show_hint {
|
if self.show_hint {
|
||||||
self.writer.write_fmt(format_args!(
|
writeln!(
|
||||||
"{}\n{}\n\n",
|
self.writer,
|
||||||
|
"{}\n{}\n",
|
||||||
"Hint".bold().cyan().underlined(),
|
"Hint".bold().cyan().underlined(),
|
||||||
self.app_state.current_exercise().hint,
|
self.app_state.current_exercise().hint,
|
||||||
))?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !matches!(self.done_status, DoneStatus::Pending) {
|
if !matches!(self.done_status, DoneStatus::Pending) {
|
||||||
self.writer.write_fmt(format_args!(
|
writeln!(
|
||||||
"{}\n\n",
|
self.writer,
|
||||||
|
"{}\n",
|
||||||
"Exercise done ✓
|
"Exercise done ✓
|
||||||
When you are done experimenting, enter `n` or `next` to go to the next exercise 🦀"
|
When you are done experimenting, enter `n` or `next` to go to the next exercise 🦀"
|
||||||
.bold()
|
.bold()
|
||||||
.green(),
|
.green(),
|
||||||
))?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let DoneStatus::DoneWithSolution(solution_path) = &self.done_status {
|
if let DoneStatus::DoneWithSolution(solution_path) = &self.done_status {
|
||||||
self.writer.write_fmt(format_args!(
|
writeln!(
|
||||||
"A solution file can be found at {}\n\n",
|
self.writer,
|
||||||
|
"A solution file can be found at {}\n",
|
||||||
style(TerminalFileLink(solution_path)).underlined().green()
|
style(TerminalFileLink(solution_path)).underlined().green()
|
||||||
))?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let line_width = size()?.0;
|
let line_width = size()?.0;
|
||||||
|
@ -145,10 +147,11 @@ When you are done experimenting, enter `n` or `next` to go to the next exercise
|
||||||
self.app_state.exercises().len() as u16,
|
self.app_state.exercises().len() as u16,
|
||||||
line_width,
|
line_width,
|
||||||
)?;
|
)?;
|
||||||
self.writer.write_fmt(format_args!(
|
writeln!(
|
||||||
"{progress_bar}Current exercise: {}\n",
|
self.writer,
|
||||||
|
"{progress_bar}Current exercise: {}",
|
||||||
self.app_state.current_exercise().terminal_link(),
|
self.app_state.current_exercise().terminal_link(),
|
||||||
))?;
|
)?;
|
||||||
|
|
||||||
self.show_prompt()?;
|
self.show_prompt()?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue