1
0
Fork 0
mirror of https://github.com/rust-lang/rustlings.git synced 2024-05-24 17:16:12 +02:00

Use write macros instead of write_fmt

This commit is contained in:
mo8it 2024-04-25 02:03:26 +02:00
parent 67fa017742
commit f92d45fa68
4 changed files with 28 additions and 25 deletions

View File

@ -309,12 +309,12 @@ impl AppState {
let mut output = Vec::with_capacity(OUTPUT_CAPACITY);
for (exercise_ind, exercise) in self.exercises().iter().enumerate() {
writer.write_fmt(format_args!("Running {exercise} ... "))?;
write!(writer, "Running {exercise} ... ")?;
writer.flush()?;
let success = exercise.run(&mut output)?;
if !success {
writer.write_fmt(format_args!("{}\n\n", "FAILED".red()))?;
writeln!(writer, "{}\n", "FAILED".red())?;
self.current_exercise_ind = exercise_ind;
@ -328,7 +328,7 @@ impl AppState {
return Ok(ExercisesProgress::Pending);
}
writer.write_fmt(format_args!("{}\n", "ok".green()))?;
writeln!(writer, "{}", "ok".green())?;
output.clear();
}

View File

@ -231,8 +231,7 @@ impl<'a> UiState<'a> {
.context("Invalid selection index")?;
let exercise_path = self.app_state.reset_exercise_by_ind(ind)?;
self.message
.write_fmt(format_args!("The exercise {exercise_path} has been reset"))?;
write!(self.message, "The exercise {exercise_path} has been reset")?;
Ok(self.with_updated_rows())
}

View File

@ -25,11 +25,12 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
);
}
stdout.write_fmt(format_args!(
"{}{}\n",
writeln!(
stdout,
"{}{}",
"✓ Successfully ran ".green(),
exercise.path.green(),
))?;
)?;
if let Some(solution_path) = app_state.current_solution_path()? {
println!(

View File

@ -88,19 +88,18 @@ impl<'a> WatchState<'a> {
self.writer.write_all(b"\n")?;
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) {
self.writer.write_fmt(format_args!("{}ext/", 'n'.bold()))?;
write!(self.writer, "{}ext/", 'n'.bold())?;
}
if !self.show_hint {
self.writer.write_fmt(format_args!("{}int/", 'h'.bold()))?;
write!(self.writer, "{}int/", 'h'.bold())?;
}
self.writer
.write_fmt(format_args!("{}ist/{}uit? ", 'l'.bold(), 'q'.bold()))?;
write!(self.writer, "{}ist/{}uit? ", 'l'.bold(), 'q'.bold())?;
self.writer.flush()
}
@ -115,28 +114,31 @@ impl<'a> WatchState<'a> {
self.writer.write_all(b"\n")?;
if self.show_hint {
self.writer.write_fmt(format_args!(
"{}\n{}\n\n",
writeln!(
self.writer,
"{}\n{}\n",
"Hint".bold().cyan().underlined(),
self.app_state.current_exercise().hint,
))?;
)?;
}
if !matches!(self.done_status, DoneStatus::Pending) {
self.writer.write_fmt(format_args!(
"{}\n\n",
writeln!(
self.writer,
"{}\n",
"Exercise done ✓
When you are done experimenting, enter `n` or `next` to go to the next exercise 🦀"
.bold()
.green(),
))?;
)?;
}
if let DoneStatus::DoneWithSolution(solution_path) = &self.done_status {
self.writer.write_fmt(format_args!(
"A solution file can be found at {}\n\n",
writeln!(
self.writer,
"A solution file can be found at {}\n",
style(TerminalFileLink(solution_path)).underlined().green()
))?;
)?;
}
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,
line_width,
)?;
self.writer.write_fmt(format_args!(
"{progress_bar}Current exercise: {}\n",
writeln!(
self.writer,
"{progress_bar}Current exercise: {}",
self.app_state.current_exercise().terminal_link(),
))?;
)?;
self.show_prompt()?;