diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-06 01:34:54 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-06 19:56:12 -0700 |
commit | 735fd480e43d6037f3ae7890c2795fdf0e431fd7 (patch) | |
tree | 5c6992780a8cced58d4dac2775002df2416955c1 | |
parent | efb2e0908b7f71a3f6ee6678c423c72b105f99ab (diff) |
Improve alignment when printing sites
-rw-r--r-- | TODO.md | 2 | ||||
-rw-r--r-- | src/main.rs | 13 |
2 files changed, 12 insertions, 3 deletions
@@ -5,7 +5,7 @@ 0. Implement --update-sites command 3. Parse markdown (`pulldown_cmark`) 4. Maybe default --validate-sites off (parsing 30k file a big hit) -5. Print to stderr in style +5. Print to stderr in [style](https://github.com/BurntSushi/termcolor) ### resources for later 0. [Intro to async rust](http://jamesmcm.github.io/blog/2020/05/06/a-practical-introduction-to-async-programming-in-rust/) diff --git a/src/main.rs b/src/main.rs index d5568cf..e9f0d99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,8 +17,17 @@ fn main() { } if opts.list_sites { - for s in ls.sites() { - println!("{}: {}", s.api_site_parameter, s.site_url); + let sites = ls.sites(); + match sites.into_iter().map(|s| s.api_site_parameter.len()).max() { + Some(max_w) => { + for s in ls.sites() { + println!("{:>w$}: {}", s.api_site_parameter, s.site_url, w = max_w); + } + } + None => { + // TODO stderr + println!("The site list is empty. Try running `so --update-sites`."); + } } return; } |