Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rtroxler committed Oct 5, 2018
1 parent dc5c4fc commit 1779fb3
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ impl fmt::Display for Info {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut s = String::from("\n");
let color = get_color(&self.language);
s.push_str(&("Project: ".color(color).bold().to_string() + &format!("{}\n", self.project_name)));
s.push_str(&("Language: ".color(color).bold().to_string() + &format!("{}\n", self.language)));
s.push_str(
&("Project: ".color(color).bold().to_string() + &format!("{}\n", self.project_name)),
);
s.push_str(
&("Language: ".color(color).bold().to_string() + &format!("{}\n", self.language)),
);
s.push_str(&("Author: ".color(color).bold().to_string() + &format!("{}\n", self.author)));
s.push_str(&("Repo: ".color(color).bold().to_string() + &format!("{}\n", self.repo)));
s.push_str(&("Number of lines: ".color(color).bold().to_string() + &format!("{}\n", self.number_of_lines)));
s.push_str(
&("Number of lines: ".color(color).bold().to_string()
+ &format!("{}\n", self.number_of_lines)),
);
s.push_str(&("License: ".color(color).bold().to_string() + &format!("{}\n", self.license)));

let logo= self.get_ascii();
let logo = self.get_ascii();
let mut lines = s.lines();
let left_pad = logo.lines().map(|l| l.len()).max().unwrap_or(0);
let mut o = String::new();
Expand All @@ -33,7 +40,12 @@ impl fmt::Display for Info {
Some(line) => line,
None => "",
};
o.push_str(&format!("{:width$} {}\n", a.color(color).bold(), b, width = left_pad));
o.push_str(&format!(
"{:width$} {}\n",
a.color(color).bold(),
b,
width = left_pad
));
}

write!(f, "{}", o)
Expand All @@ -58,7 +70,7 @@ enum Language {
TypeScript,
}

fn get_color(l : &Language) -> &str {
fn get_color(l: &Language) -> &str {
match l {
Language::C => "cyan",
Language::Clojure => "cyan",
Expand Down Expand Up @@ -101,7 +113,6 @@ impl fmt::Display for Language {
}

fn main() {

let language = match get_dominant_language() {
Some(language) => language,
None => {
Expand All @@ -121,19 +132,20 @@ fn main() {
};

println!("{}", info);

}

/// Traverse current directory and search for dominant
/// language using tokei.
fn get_dominant_language() -> Option<Language> {
let mut languages = tokei::Languages::new();
let required_languages = get_all_language_types();
languages.get_statistics( &["."], vec![".git", "target"], Some(required_languages));
languages.get_statistics(&["."], vec![".git", "target"], Some(required_languages));

languages.remove_empty().iter()
.max_by_key(|(_, v)| v.code)
.map(|(k, _)| Language::from(**k))
languages
.remove_empty()
.iter()
.max_by_key(|(_, v)| v.code)
.map(|(k, _)| Language::from(**k))
}

/// Convert from tokei LanguageType to known Language type .
Expand Down

0 comments on commit 1779fb3

Please sign in to comment.