mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-22 05:52:23 -05:00
Show the final message
This commit is contained in:
parent
757723a7e8
commit
24539666af
4 changed files with 24 additions and 15 deletions
|
@ -20,7 +20,8 @@ started, here's a couple of notes about how Rustlings operates:
|
||||||
and sometimes, other learners do too so you can help each other out!
|
and sometimes, other learners do too so you can help each other out!
|
||||||
|
|
||||||
Got all that? Great! To get started, run `rustlings watch` in order to get the first exercise.
|
Got all that? Great! To get started, run `rustlings watch` in order to get the first exercise.
|
||||||
Make sure to have your editor open in the `rustlings` directory!"""
|
Make sure to have your editor open in the `rustlings` directory!
|
||||||
|
"""
|
||||||
|
|
||||||
final_message = """We hope you enjoyed learning about the various aspects of Rust!
|
final_message = """We hope you enjoyed learning about the various aspects of Rust!
|
||||||
If you noticed any issues, please don't hesitate to report them to our repo.
|
If you noticed any issues, please don't hesitate to report them to our repo.
|
||||||
|
|
|
@ -51,24 +51,29 @@ impl StateFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
|
||||||
state_file: StateFile,
|
|
||||||
exercises: &'static [Exercise],
|
|
||||||
n_done: u16,
|
|
||||||
current_exercise: &'static Exercise,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub enum ExercisesProgress {
|
pub enum ExercisesProgress {
|
||||||
AllDone,
|
AllDone,
|
||||||
Pending,
|
Pending,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AppState {
|
||||||
|
state_file: StateFile,
|
||||||
|
exercises: &'static [Exercise],
|
||||||
|
n_done: u16,
|
||||||
|
current_exercise: &'static Exercise,
|
||||||
|
final_message: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn new(exercises: Vec<Exercise>) -> Self {
|
pub fn new(mut exercises: Vec<Exercise>, mut final_message: String) -> Self {
|
||||||
// Leaking for sending the exercises to the debounce event handler.
|
// Leaking especially for sending the exercises to the debounce event handler.
|
||||||
// Leaking is not a problem since the exercises' slice is used until the end of the program.
|
// Leaking is not a problem because the `AppState` instance lives until
|
||||||
|
// the end of the program.
|
||||||
|
exercises.shrink_to_fit();
|
||||||
let exercises = exercises.leak();
|
let exercises = exercises.leak();
|
||||||
|
final_message.shrink_to_fit();
|
||||||
|
let final_message = final_message.leak();
|
||||||
|
|
||||||
let state_file = StateFile::read_or_default(exercises);
|
let state_file = StateFile::read_or_default(exercises);
|
||||||
let n_done = state_file
|
let n_done = state_file
|
||||||
|
@ -82,6 +87,7 @@ impl AppState {
|
||||||
exercises,
|
exercises,
|
||||||
n_done,
|
n_done,
|
||||||
current_exercise,
|
current_exercise,
|
||||||
|
final_message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +216,8 @@ impl AppState {
|
||||||
|
|
||||||
writer.execute(Clear(ClearType::All))?;
|
writer.execute(Clear(ClearType::All))?;
|
||||||
writer.write_all(FENISH_LINE.as_bytes())?;
|
writer.write_all(FENISH_LINE.as_bytes())?;
|
||||||
// TODO: Show final message.
|
writer.write_all(self.final_message.as_bytes())?;
|
||||||
|
writer.write_all(b"\n")?;
|
||||||
|
|
||||||
return Ok(ExercisesProgress::AllDone);
|
return Ok(ExercisesProgress::AllDone);
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,6 @@ pub enum Mode {
|
||||||
pub struct InfoFile {
|
pub struct InfoFile {
|
||||||
// TODO
|
// TODO
|
||||||
pub welcome_message: Option<String>,
|
pub welcome_message: Option<String>,
|
||||||
// TODO
|
|
||||||
pub final_message: Option<String>,
|
pub final_message: Option<String>,
|
||||||
pub exercises: Vec<Exercise>,
|
pub exercises: Vec<Exercise>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ fn main() -> Result<()> {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut app_state = AppState::new(exercises);
|
let mut app_state = AppState::new(exercises, info_file.final_message.unwrap_or_default());
|
||||||
|
|
||||||
match args.command {
|
match args.command {
|
||||||
None => loop {
|
None => loop {
|
||||||
|
@ -144,4 +144,6 @@ const FENISH_LINE: &str = "+----------------------------------------------------
|
||||||
▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒
|
▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒
|
||||||
▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒
|
▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒
|
||||||
▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒
|
▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒
|
||||||
▒▒ ▒▒ ▒▒ ▒▒\x1b[0m";
|
▒▒ ▒▒ ▒▒ ▒▒\x1b[0m
|
||||||
|
|
||||||
|
";
|
||||||
|
|
Loading…
Reference in a new issue