Skip to content

Commit 74895df

Browse files
authored
Merge pull request #738 from apogeeoak/text
fix(cli): Move long text strings into constants.
2 parents 0bd7a06 + c1f35e4 commit 74895df

File tree

2 files changed

+78
-102
lines changed

2 files changed

+78
-102
lines changed

default_out.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/main.rs

Lines changed: 78 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,7 @@ fn main() {
108108
}
109109

110110
if args.nested.is_none() {
111-
println!();
112-
println!(r#" welcome to... "#);
113-
println!(r#" _ _ _ "#);
114-
println!(r#" _ __ _ _ ___| |_| (_)_ __ __ _ ___ "#);
115-
println!(r#" | '__| | | / __| __| | | '_ \ / _` / __| "#);
116-
println!(r#" | | | |_| \__ \ |_| | | | | | (_| \__ \ "#);
117-
println!(r#" |_| \__,_|___/\__|_|_|_| |_|\__, |___/ "#);
118-
println!(r#" |___/ "#);
119-
println!();
111+
println!("\n{}\n", WELCOME);
120112
}
121113

122114
if !Path::new("info.toml").exists() {
@@ -140,8 +132,7 @@ fn main() {
140132
let verbose = args.nocapture;
141133

142134
let command = args.nested.unwrap_or_else(|| {
143-
let text = fs::read_to_string("default_out.txt").unwrap();
144-
println!("{}", text);
135+
println!("{}\n", DEFAULT_OUT);
145136
std::process::exit(0);
146137
});
147138
match command {
@@ -164,9 +155,7 @@ fn main() {
164155
"Pending"
165156
};
166157
let solve_cond = {
167-
(e.looks_done() && subargs.solved)
168-
|| (!e.looks_done() && subargs.unsolved)
169-
|| (!subargs.solved && !subargs.unsolved)
158+
(e.looks_done() && subargs.solved) || (!e.looks_done() && subargs.unsolved) || (!subargs.solved && !subargs.unsolved)
170159
};
171160
if solve_cond && (filter_cond || subargs.filter.is_none()) {
172161
let line = if subargs.paths {
@@ -219,49 +208,13 @@ fn main() {
219208

220209
Subcommands::Watch(_subargs) => match watch(&exercises, verbose) {
221210
Err(e) => {
222-
println!(
223-
"Error: Could not watch your progress. Error message was {:?}.",
224-
e
225-
);
211+
println!("Error: Could not watch your progress. Error message was {:?}.", e);
226212
println!("Most likely you've run out of disk space or your 'inotify limit' has been reached.");
227213
std::process::exit(1);
228214
}
229215
Ok(WatchStatus::Finished) => {
230-
println!(
231-
"{emoji} All exercises completed! {emoji}",
232-
emoji = Emoji("🎉", "★")
233-
);
234-
println!();
235-
println!("+----------------------------------------------------+");
236-
println!("| You made it to the Fe-nish line! |");
237-
println!("+-------------------------- ------------------------+");
238-
println!(" \\/ ");
239-
println!(" ▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒ ");
240-
println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ");
241-
println!(" ▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒ ");
242-
println!(" ░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒ ");
243-
println!(" ▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓ ");
244-
println!(" ▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒ ");
245-
println!(" ▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒ ");
246-
println!(" ▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒ ");
247-
println!(" ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ");
248-
println!(" ▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒ ");
249-
println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒ ");
250-
println!(" ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ");
251-
println!(" ▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒ ");
252-
println!(" ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ");
253-
println!(" ▒▒ ▒▒ ▒▒ ▒▒ ");
254-
println!();
255-
println!("We hope you enjoyed learning about the various aspects of Rust!");
256-
println!(
257-
"If you noticed any issues, please don't hesitate to report them to our repo."
258-
);
259-
println!(
260-
"You can also contribute your own exercises to help the greater community!"
261-
);
262-
println!();
263-
println!("Before reporting an issue or contributing, please read our guidelines:");
264-
println!("https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md");
216+
println!("{emoji} All exercises completed! {emoji}", emoji = Emoji("🎉", "★"));
217+
println!("\n{}\n", FENISH_LINE);
265218
}
266219
Ok(WatchStatus::Unfinished) => {
267220
println!("We hope you're enjoying learning about Rust!");
@@ -271,10 +224,7 @@ fn main() {
271224
}
272225
}
273226

274-
fn spawn_watch_shell(
275-
failed_exercise_hint: &Arc<Mutex<Option<String>>>,
276-
should_quit: Arc<AtomicBool>,
277-
) {
227+
fn spawn_watch_shell(failed_exercise_hint: &Arc<Mutex<Option<String>>>, should_quit: Arc<AtomicBool>) {
278228
let failed_exercise_hint = Arc::clone(failed_exercise_hint);
279229
println!("Welcome to watch mode! You can type 'help' to get an overview of the commands you can use here.");
280230
thread::spawn(move || loop {
@@ -311,22 +261,16 @@ fn spawn_watch_shell(
311261

312262
fn find_exercise<'a>(name: &str, exercises: &'a [Exercise]) -> &'a Exercise {
313263
if name.eq("next") {
314-
exercises
315-
.iter()
316-
.find(|e| !e.looks_done())
317-
.unwrap_or_else(|| {
318-
println!("🎉 Congratulations! You have done all the exercises!");
319-
println!("🔚 There are no more exercises to do next!");
320-
std::process::exit(1)
321-
})
264+
exercises.iter().find(|e| !e.looks_done()).unwrap_or_else(|| {
265+
println!("🎉 Congratulations! You have done all the exercises!");
266+
println!("🔚 There are no more exercises to do next!");
267+
std::process::exit(1)
268+
})
322269
} else {
323-
exercises
324-
.iter()
325-
.find(|e| e.name == name)
326-
.unwrap_or_else(|| {
327-
println!("No exercise found for '{}'!", name);
328-
std::process::exit(1)
329-
})
270+
exercises.iter().find(|e| e.name == name).unwrap_or_else(|| {
271+
println!("No exercise found for '{}'!", name);
272+
std::process::exit(1)
273+
})
330274
}
331275
}
332276

@@ -366,11 +310,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
366310
.iter()
367311
.skip_while(|e| !filepath.ends_with(&e.path))
368312
// .filter(|e| filepath.ends_with(&e.path))
369-
.chain(
370-
exercises
371-
.iter()
372-
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
373-
);
313+
.chain(exercises.iter().filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)));
374314
clear_screen();
375315
match verify(pending_exercises, verbose) {
376316
Ok(_) => return Ok(WatchStatus::Finished),
@@ -404,3 +344,64 @@ fn rustc_exists() -> bool {
404344
.map(|status| status.success())
405345
.unwrap_or(false)
406346
}
347+
348+
const DEFAULT_OUT: &str = r#"Thanks for installing Rustlings!
349+
350+
Is this your first time? Don't worry, Rustlings was made for beginners! We are
351+
going to teach you a lot of things about Rust, but before we can get
352+
started, here's a couple of notes about how Rustlings operates:
353+
354+
1. The central concept behind Rustlings is that you solve exercises. These
355+
exercises usually have some sort of syntax error in them, which will cause
356+
them to fail compilation or testing. Sometimes there's a logic error instead
357+
of a syntax error. No matter what error, it's your job to find it and fix it!
358+
You'll know when you fixed it because then, the exercise will compile and
359+
Rustlings will be able to move on to the next exercise.
360+
2. If you run Rustlings in watch mode (which we recommend), it'll automatically
361+
start with the first exercise. Don't get confused by an error message popping
362+
up as soon as you run Rustlings! This is part of the exercise that you're
363+
supposed to solve, so open the exercise file in an editor and start your
364+
detective work!
365+
3. If you're stuck on an exercise, there is a helpful hint you can view by typing
366+
'hint' (in watch mode), or running `rustlings hint exercise_name`.
367+
4. If an exercise doesn't make sense to you, feel free to open an issue on GitHub!
368+
(https://github.com/rust-lang/rustlings/issues/new). We look at every issue,
369+
and sometimes, other learners do too so you can help each other out!
370+
371+
Got all that? Great! To get started, run `rustlings watch` in order to get the first
372+
exercise. Make sure to have your editor open!"#;
373+
374+
const FENISH_LINE: &str = r#"+----------------------------------------------------+
375+
| You made it to the Fe-nish line! |
376+
+-------------------------- ------------------------+
377+
\\/
378+
▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒
379+
▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒
380+
▒▒▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒▒▒
381+
░░▒▒▒▒░░▒▒ ▒▒ ▒▒ ▒▒ ▒▒░░▒▒▒▒
382+
▓▓▓▓▓▓▓▓ ▓▓ ▓▓██ ▓▓ ▓▓██ ▓▓ ▓▓▓▓▓▓▓▓
383+
▒▒▒▒ ▒▒ ████ ▒▒ ████ ▒▒░░ ▒▒▒▒
384+
▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒▒▒▒▒ ▒▒
385+
▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▒▒▒▒▒▒▒▒▓▓▒▒▓▓▒▒▒▒▒▒▒▒
386+
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
387+
▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒
388+
▒▒ ▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒▒▒▒▒▒ ▒▒
389+
▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒
390+
▒▒ ▒▒ ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒▒ ▒▒
391+
▒▒ ▒▒ ▒▒ ▒▒ ▒▒ ▒▒
392+
▒▒ ▒▒ ▒▒ ▒▒
393+
394+
We hope you enjoyed learning about the various aspects of Rust!
395+
If you noticed any issues, please don't hesitate to report them to our repo.
396+
You can also contribute your own exercises to help the greater community!
397+
398+
Before reporting an issue or contributing, please read our guidelines:
399+
https://github.com/rust-lang/rustlings/blob/main/CONTRIBUTING.md"#;
400+
401+
const WELCOME: &str = r#" welcome to...
402+
_ _ _
403+
_ __ _ _ ___| |_| (_)_ __ __ _ ___
404+
| '__| | | / __| __| | | '_ \ / _` / __|
405+
| | | |_| \__ \ |_| | | | | | (_| \__ \
406+
|_| \__,_|___/\__|_|_|_| |_|\__, |___/
407+
|___/"#;

0 commit comments

Comments
 (0)