Skip to content

Commit

Permalink
switch colors
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Sep 20, 2018
1 parent c7ec9f7 commit e028804
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ struct Info {
impl fmt::Display for Info {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut s = String::from("\n");
s.push_str(&("Project: ".blue().bold().to_string() + &format!("{}\n", self.project_name)));
s.push_str(&("Language: ".blue().bold().to_string() + &format!("{}\n", self.language)));
s.push_str(&("Author: ".blue().bold().to_string() + &format!("{}\n", self.author)));
s.push_str(&("Repo: ".blue().bold().to_string() + &format!("{}\n", self.repo)));
s.push_str(&("Number of lines: ".blue().bold().to_string() + &format!("{}\n", self.number_of_lines)));
s.push_str(&("License: ".blue().bold().to_string() + &format!("{}\n", self.license)));
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(&("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(&("License: ".color(color).bold().to_string() + &format!("{}\n", self.license)));

let logo= self.get_ascii();
let mut lines = s.lines();
Expand All @@ -30,7 +31,7 @@ impl fmt::Display for Info {
Some(line) => line,
None => "",
};
o.push_str(&format!("{:width$} {}\n", a.blue().bold(), b, width = left_pad));
o.push_str(&format!("{:width$} {}\n", a.color(color).bold(), b, width = left_pad));
}

write!(f, "{}", o)
Expand All @@ -52,6 +53,24 @@ enum Language {
Ruby,
}

fn get_color(l : &Language) -> &str {

match l {
Language::Rust => "white",
Language::Go => "blue",
Language::Java => "green",
Language::Cpp => "yellow",
Language::C => "cyan",
Language::Python => "magenta",
Language::Csharp => "white",
Language::Scala => "blue",
Language::Shell => "green",
Language::Lisp => "yellow",
Language::Haskell => "cyan",
Language::Ruby => "magenta",
}
}

impl fmt::Display for Language {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand All @@ -72,21 +91,17 @@ impl fmt::Display for Language {
}

fn main() {
let info = Info {
project_name: String::from("onefetch"),
language: Language::Java,
author: String::from("Ossama Hjaji"),
repo: String::from("https://github.com/02sh/onefetch"),
number_of_lines: 15656,
license: String::from("MIT"),
};
let info = Info {
project_name: String::from("onefetch"),
language: Language::Python,
author: String::from("Ossama Hjaji"),
repo: String::from("https://github.com/02sh/onefetch"),
number_of_lines: 15656,
license: String::from("MIT"),
};

println!("{}", info);
println!("{}", info);

//let left_pad = ascii.lines().map(|l| l.len()).max().unwrap_or(0) + 5;
//for (a,b) in ascii.lines().zip(info.lines()) {
// println!("{:width$} {}", a, b, width = left_pad);
//}
}


Expand Down

0 comments on commit e028804

Please sign in to comment.