Skip to content

Commit

Permalink
Merge pull request #75 from ktsuench/master
Browse files Browse the repository at this point in the history
Feature: allow user to pick ASCII art with flag --ascii_language
  • Loading branch information
o2sh authored Oct 13, 2019
2 parents 983424d + bc7972e commit 79164fd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ tokei = "10.0"
license = "0.7.1"
bytecount = "0.5.1"
clap = "2.33.0"
strum = "0.16.0"
strum_macros = "0.16.0"
42 changes: 39 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ extern crate license;
extern crate tokei;
#[macro_use]
extern crate clap;
extern crate strum;
#[macro_use]
extern crate strum_macros;

use colored::Color;
use colored::*;
Expand Down Expand Up @@ -40,6 +43,7 @@ struct Info {
repo_size: String,
number_of_lines: usize,
license: String,
custom_logo: Language,
}

impl fmt::Display for Info {
Expand Down Expand Up @@ -268,7 +272,8 @@ impl fmt::Display for CommitInfo {
}
}

#[derive(PartialEq, Eq, Hash, Clone)]
#[derive(PartialEq, Eq, Hash, Clone, EnumString)]
#[strum(serialize_all = "lowercase")]
enum Language {
Assembly,
C,
Expand Down Expand Up @@ -305,6 +310,7 @@ enum Language {
Perl,
Php,
Zig,
Unknown
}

impl fmt::Display for Language {
Expand Down Expand Up @@ -345,6 +351,7 @@ impl fmt::Display for Language {
Language::Perl => write!(f, "Perl"),
Language::Php => write!(f, "Php"),
Language::Zig => write!(f, "Zig"),
Language::Unknown => write!(f, "Unknown"),
}
}
}
Expand All @@ -363,8 +370,20 @@ fn main() -> Result<()> {
.long("dir")
.takes_value(true)
.default_value("."))
.arg(Arg::with_name("ascii_language")
.short("a")
.long("ascii_language")
.takes_value(true)
.default_value("")
.help("Overrides showing the dominant language ascii logo"))
.get_matches();
let dir = String::from(matches.value_of("directory").unwrap());
let custom_logo: Language = Language::from_str(
&matches
.value_of("ascii_language")
.unwrap()
.to_lowercase())
.unwrap_or(Language::Unknown);

let tokei_langs = project_languages(&dir);
let languages_stat = get_languages_stat(&tokei_langs).ok_or(Error::SourceCodeNotFound)?;
Expand Down Expand Up @@ -395,6 +414,7 @@ fn main() -> Result<()> {
repo_size,
number_of_lines: get_total_loc(&tokei_langs),
license: project_license(&dir)?,
custom_logo,
};

println!("{}", info);
Expand Down Expand Up @@ -795,7 +815,14 @@ fn get_all_language_types() -> Vec<tokei::LanguageType> {

impl Info {
pub fn get_ascii(&self) -> &str {
match self.dominant_language {
let language =
if let Language::Unknown = self.custom_logo {
&self.dominant_language
} else {
&self.custom_logo
};

match language {
Language::Assembly => include_str!("../resources/assembly.ascii"),
Language::C => include_str!("../resources/c.ascii"),
Language::Clojure => include_str!("../resources/clojure.ascii"),
Expand Down Expand Up @@ -831,12 +858,20 @@ impl Info {
Language::Perl => include_str!("../resources/perl.ascii"),
Language::Php => include_str!("../resources/php.ascii"),
Language::Zig => include_str!("../resources/zig.ascii"),
Language::Unknown => include_str!("../resources/unknown.ascii"),
// _ => include_str!("../resources/unknown.ascii"),
}
}

fn colors(&self) -> Vec<Color> {
match self.dominant_language {
let language =
if let Language::Unknown = self.custom_logo {
&self.dominant_language
} else {
&self.custom_logo
};

match language {
Language::Assembly => vec![Color::Cyan],
Language::C => vec![Color::BrightBlue, Color::Blue],
Language::Clojure => vec![Color::BrightBlue, Color::BrightGreen],
Expand Down Expand Up @@ -872,6 +907,7 @@ impl Info {
Language::Perl => vec![Color::BrightBlue],
Language::Php => vec![Color::BrightWhite],
Language::Zig => vec![Color::Yellow],
Language::Unknown => vec![Color::White],
}
}
}
Expand Down

0 comments on commit 79164fd

Please sign in to comment.