-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding a write example #226
Conversation
Codecov Report
@@ Coverage Diff @@
## master #226 +/- ##
=======================================
Coverage 61.17% 61.17%
=======================================
Files 40 40
Lines 2697 2697
=======================================
Hits 1650 1650
Misses 1047 1047 Continue to review full report at Codecov.
|
This is a very cool idea @JuanMarchetto! Great work! 😁 🎉 I'm glad you chose to submit this early, as big examples like this often need a lot of feedback, so discussing it earlier is always better than later. Lots of code to review! I won't have a chance to look at this in detail for a few days, but here's a couple of things I noticed from skimming through the code:
Argument Parsing Codeuse std::env;
use std::process;
fn main() {
let (text, font_size) = parse_args();
println!("{}", text);
println!("{}", font_size);
}
/// Parses the command line arguments or exits with a help message if there was
/// an error
fn parse_args() -> (String, f64) {
let mut args = env::args();
// Skip the first argument (the executable name)
args.next();
// First argument is the text to draw
let text = match args.next() {
Some(text) if text == "--help" => print_help(),
// This can produce any text, including the empty string
Some(text) => text,
// Default to `Hello, World!`
None => "Hello, World!".to_string(),
};
// Second argument is the font size
let font_size: f64 = match args.next() {
Some(text) if text == "--help" => print_help(),
Some(font_size) => match font_size.parse() {
Ok(font_size) => if font_size >= 1.0 {
font_size
} else {
println!("Font size argument must be at least 1.0");
println!();
print_help();
},
Err(err) => {
println!("Font size argument must be a valid number: {}", err);
println!();
print_help();
},
},
// Default to a font size of 20
None => 20.0,
};
// Not expecting any other arguments
if args.next().is_some() {
print_help()
}
(text, font_size)
}
/// Prints the help message and then exits
///
/// `!` is the "never type" and it means this function never returns
fn print_help() -> ! {
println!("Draws text on the screen using the turtle.");
println!();
println!("EXAMPLES:");
println!(" cargo run --example letters 'Wow! So cool!'");
println!(" Draw the text 'Wow! So cool!'");
println!();
println!(" cargo run --example letters 'Big text!' 50");
println!(" Draw the text 'Big text!' with font size 50");
println!();
println!(" cargo run --example letters -- --help");
println!(" Show this help information");
println!();
println!("FLAGS:");
println!(" --help show this help information");
process::exit(0)
} Overall, really great work with this PR! It might take a little longer than last time to review and get merged since there is much more code, but I'm really looking forward to working with you to get this finished. Thanks for taking the time to work on this! 🥳 🎉 |
d44c833
to
02f7aa7
Compare
Hey @JuanMarchetto I saw you pushed a new commit. Let me know when you're ready for a review. If you think this PR is ready, you can convert it from a draft PR to a regular PR. |
Hey @sunjay this is not ready yet, I've been busy this week, but the next one I'll will get back to this and let you know when is ready. Thanks! |
Sounds good! Take as much time as you need. Just wanted to make sure you weren't waiting on me. :) Happy to help out with anything if you run into any issues. Thanks for all your work! |
@sunjay i made some progress here, i don't know how to address the coverage failing status do. |
@JuanMarchetto Great! I will have a look over a few days. If I don't get back to you by next week please don't hesitate to ping me. (Hoping to have it done much sooner than that, but thought I'd mention it just in case.) Don't worry about the coverage status. Only the required statuses + an approval from me are needed to get this merged. :) |
Hi @sunjay, |
Hey @JuanMarchetto! Sorry for the delay. I saw that you were still pushing things and assumed that you were still working on it. I will take a look over the next few days. Thanks for all your effort! 😁 🎉 |
Hey! Really sorry for not getting to your PR yet. Going through some things and will try to find time soon. I usually try to be really quick with these things, but it unfortunately didn't work out this time. I will get to this! :) |
Hey sunjay, don't worry, i hope you are fine! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very cool example @JuanMarchetto! Great work! I really appreciate all the work you put into getting every letter/punctuation/special character working. You did an excellent job. 😁
Thanks for your patience with me! Just need to update from the master branch and this should be good to go. Glad to see this getting merged.
Hi, i'm creating this example that draw any text you want.
![Captura de pantalla de 2021-02-21 19-56-03](https://user-images.githubusercontent.com/6706152/108642943-f9c7e980-7486-11eb-8817-64a8f28193ee.png)
For example, if you run in console:
cargo run --example write hello
it will draw "Hello"
if you don't introduce any text:
cargo run --example write
it will draw "Hello, World!"
you can also pass a font size as a second parameter:
cargo run --example write "Hello, World!" 50
and all the letters will ajust to that size, if you don't pass that second parameter 20.0 will be the default.
I still need to implement some more letter but i like to show you the progress at this point.
At this point if you introduce a character that currently doesn't have an implemtations will we replaced with '?' and in the console it will trow the followinig message:
I hope you like it.