Skip to content

Commit e028804

Browse files
committedSep 20, 2018
switch colors
1 parent c7ec9f7 commit e028804

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed
 

Diff for: ‎src/main.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ struct Info {
1414
impl fmt::Display for Info {
1515
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1616
let mut s = String::from("\n");
17-
s.push_str(&("Project: ".blue().bold().to_string() + &format!("{}\n", self.project_name)));
18-
s.push_str(&("Language: ".blue().bold().to_string() + &format!("{}\n", self.language)));
19-
s.push_str(&("Author: ".blue().bold().to_string() + &format!("{}\n", self.author)));
20-
s.push_str(&("Repo: ".blue().bold().to_string() + &format!("{}\n", self.repo)));
21-
s.push_str(&("Number of lines: ".blue().bold().to_string() + &format!("{}\n", self.number_of_lines)));
22-
s.push_str(&("License: ".blue().bold().to_string() + &format!("{}\n", self.license)));
17+
let color = get_color(&self.language);
18+
s.push_str(&("Project: ".color(color).bold().to_string() + &format!("{}\n", self.project_name)));
19+
s.push_str(&("Language: ".color(color).bold().to_string() + &format!("{}\n", self.language)));
20+
s.push_str(&("Author: ".color(color).bold().to_string() + &format!("{}\n", self.author)));
21+
s.push_str(&("Repo: ".color(color).bold().to_string() + &format!("{}\n", self.repo)));
22+
s.push_str(&("Number of lines: ".color(color).bold().to_string() + &format!("{}\n", self.number_of_lines)));
23+
s.push_str(&("License: ".color(color).bold().to_string() + &format!("{}\n", self.license)));
2324

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

3637
write!(f, "{}", o)
@@ -52,6 +53,24 @@ enum Language {
5253
Ruby,
5354
}
5455

56+
fn get_color(l : &Language) -> &str {
57+
58+
match l {
59+
Language::Rust => "white",
60+
Language::Go => "blue",
61+
Language::Java => "green",
62+
Language::Cpp => "yellow",
63+
Language::C => "cyan",
64+
Language::Python => "magenta",
65+
Language::Csharp => "white",
66+
Language::Scala => "blue",
67+
Language::Shell => "green",
68+
Language::Lisp => "yellow",
69+
Language::Haskell => "cyan",
70+
Language::Ruby => "magenta",
71+
}
72+
}
73+
5574
impl fmt::Display for Language {
5675
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5776
match *self {
@@ -72,21 +91,17 @@ impl fmt::Display for Language {
7291
}
7392

7493
fn main() {
75-
let info = Info {
76-
project_name: String::from("onefetch"),
77-
language: Language::Java,
78-
author: String::from("Ossama Hjaji"),
79-
repo: String::from("https://github.com/02sh/onefetch"),
80-
number_of_lines: 15656,
81-
license: String::from("MIT"),
82-
};
94+
let info = Info {
95+
project_name: String::from("onefetch"),
96+
language: Language::Python,
97+
author: String::from("Ossama Hjaji"),
98+
repo: String::from("https://github.com/02sh/onefetch"),
99+
number_of_lines: 15656,
100+
license: String::from("MIT"),
101+
};
83102

84-
println!("{}", info);
103+
println!("{}", info);
85104

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

92107

0 commit comments

Comments
 (0)
Please sign in to comment.