From b98a26c684f02e08dcc66f948315320c7bd6f8b8 Mon Sep 17 00:00:00 2001 From: Ossama Hjaji Date: Wed, 20 Oct 2021 16:14:21 +0200 Subject: [PATCH] add language type (#513) * add language type * change language type for xml, xaml, jupyter and vue --- CONTRIBUTING.md | 4 +- src/cli.rs | 32 +++++- src/info/langs/language.rs | 203 ++++++++++++++++++++----------------- src/info/langs/mod.rs | 23 +++-- src/info/mod.rs | 1 + 5 files changed, 159 insertions(+), 104 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c8d4ace9..422eac644 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,9 +15,9 @@ Adding support for a new Language consists in adding a new entry to the `define_ **Example**: -`{ CSharp, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta] ), "c#" },` +`{ CSharp, Programming, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta] ), "c#" },` -The first item `CSharp` corresponds to the name of the language as defined in [tokei](https://github.com/XAMPPRocky/tokei). The second item `csharp.ascii` is the name of the file containing the ascii logo: this file has to be placed in the _./resources_ folder (more info below). Then we have the colors used to customize the look of the ascii logo when displayed to the screen. The last item `c#` is only required if the Enum name `CSharp` doesn't match the display name `C#` and is used as an input for `-a, --ascii-language ` - by default we take the Enum name in lowercase. +The first item `CSharp` corresponds to the name of the language as defined in [tokei](https://github.com/XAMPPRocky/tokei). The second item refers to the language type as specified by [linguist](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml), only four values are possible: Programming, Markup, Prose and Data. The third item `csharp.ascii` is the name of the file containing the ascii logo: this file has to be placed in the _./resources_ folder (more info below). Then we have the colors used to customize the look of the ascii logo when displayed to the screen. The last item `c#` is only required if the Enum name `CSharp` doesn't match the display name `C#` and is used as an input for `-a, --ascii-language ` - by default we take the Enum name in lowercase. #### Ascii logo diff --git a/src/cli.rs b/src/cli.rs index 22203113b..a11b33369 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,6 @@ use crate::info::deps::package_manager::PackageManager; use crate::info::info_field::{InfoField, InfoFieldOff}; -use crate::info::langs::language::Language; +use crate::info::langs::language::{Language, LanguageType}; use crate::ui::image_backends; use crate::ui::image_backends::ImageBackend; use crate::ui::printer::SerializationFormat; @@ -38,6 +38,7 @@ pub struct Config { pub iso_time: bool, pub show_email: bool, pub include_hidden: bool, + pub language_types: Vec, } impl Config { @@ -64,11 +65,13 @@ impl Config { Arg::with_name("output") .short("o") .long("output") + .value_name("FORMAT") .help("Outputs Onefetch in a specific format (json, yaml).") .takes_value(true) - .possible_values(&SerializationFormat::iter() - .map(|format| format.into()) - .collect::>()) + .possible_values( + &SerializationFormat::iter() + .map(|format| format.into()) + .collect::>()) ) .arg( Arg::with_name("languages") @@ -276,6 +279,20 @@ impl Config { .takes_value(true) .help("Ignore all files & directories matching EXCLUDE."), ) + .arg( + Arg::with_name("type") + .short("T") + .long("type") + .value_name("TYPE") + .multiple(true) + .takes_value(true) + .case_insensitive(true) + .help("Filters output by language type (*programming*, *markup*, prose, data).") + .possible_values( + &LanguageType::iter() + .map(|t| t.into()) + .collect::>()) + ) .get_matches(); let true_color = match matches.value_of("true-color") { @@ -378,6 +395,12 @@ impl Config { .map_or(Regex::from_str(r"\[bot\]").unwrap(), |s| Regex::from_str(s).unwrap()) }); + let language_types: Vec = if let Some(values) = matches.values_of("type") { + values.map(|t| LanguageType::from_str(t).unwrap()).collect() + } else { + vec![LanguageType::Programming, LanguageType::Markup] + }; + Ok(Config { repo_path, ascii_input, @@ -402,6 +425,7 @@ impl Config { iso_time, show_email, include_hidden, + language_types, }) } } diff --git a/src/info/langs/language.rs b/src/info/langs/language.rs index e30c19200..9edff0627 100644 --- a/src/info/langs/language.rs +++ b/src/info/langs/language.rs @@ -14,11 +14,21 @@ macro_rules! define_colors { ( $color:expr ) => { $color }; } +#[derive(PartialEq, EnumString, EnumIter, IntoStaticStr)] +#[strum(serialize_all = "lowercase")] +pub enum LanguageType { + Programming, + Markup, + Prose, + Data, +} + macro_rules! define_languages { - ($( { $name:ident, $ascii:literal, $colors:expr $(, $serialize:literal )? } ),* ,) => { + ($( { $name:ident, $type:ident, $ascii:literal, $colors:expr $(, $serialize:literal )? } ),* ,) => { #[derive(PartialEq, Eq, Hash, Clone, EnumString, EnumIter, IntoStaticStr, Serialize)] #[strum(serialize_all = "lowercase")] + #[allow(clippy::upper_case_acronyms)] pub enum Language { $( $( #[strum(serialize = $serialize)] )? @@ -45,6 +55,14 @@ macro_rules! define_languages { } } + impl From for tokei::LanguageType { + fn from(language: Language) -> Self { + match language { + $( Language::$name => tokei::LanguageType::$name, )* + } + } + } + impl Language { pub fn get_ascii_art(&self) -> &str { match *self { @@ -61,15 +79,16 @@ macro_rules! define_languages { _ => colors.basic_colors, } } - } - pub fn get_all_language_types() -> Vec { - vec![ $( tokei::LanguageType::$name ,)* ] + pub fn get_type(&self) -> LanguageType { + match *self { + $( Language::$name => LanguageType::$type, )* + } + } } #[cfg(test)] mod true_colors { - use std::fmt; use super::*; use paste::paste; @@ -154,70 +173,70 @@ macro_rules! define_languages { } define_languages! { - { Ada, "ada.ascii", define_colors!( [Color::White, Color::Cyan, Color::Blue] : [Color::TrueColor{r:255, g:255, b:255}, Color::TrueColor{r:0, g:24, b:201}, Color::TrueColor{r:12, g:10, b:124}] ) }, - { Assembly, "assembly.ascii", define_colors!( [Color::Cyan] ) }, - { AutoHotKey, "autohotkey.ascii", define_colors!( [Color::White, Color::Green] : [Color::TrueColor{r:255, g:255, b:255}, Color::TrueColor{r: 0x11, g: 0x98, b: 0x10}]) }, - { Bash, "bash.ascii", define_colors!( [Color::White] ), "bash" }, - { C, "c.ascii", define_colors!( [Color::Cyan, Color::Blue, Color::White] : [Color::TrueColor{r:93, g:108, b:191}, Color::TrueColor{r:41, g:54, b:147}, Color::TrueColor{r:255, g:255, b:255}] ) }, - { Clojure, "clojure.ascii", define_colors!( [Color::Cyan, Color::Green] ) }, - { CMake, "cmake.ascii", define_colors!( [Color::Blue, Color::Green, Color::Red, Color::Black] ) }, - { CoffeeScript, "coffeescript.ascii", define_colors!( [Color::Red] ) }, - { Cpp, "cpp.ascii", define_colors!( [Color::Cyan, Color::Blue, Color::White] : [Color::TrueColor{r:100, g:154, b:210}, Color::TrueColor{r:0, g:68, b:130}, Color::TrueColor{r:255, g:255, b:255}] ), "c++" }, - { Crystal, "crystal.ascii", define_colors!( [Color::White, Color::Black] ) }, - { CSharp, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta, Color::White] : [Color::TrueColor{r:154, g:73, b:147}, Color::TrueColor{r:106, g:21, b:119}, Color::TrueColor{r:255, g:255, b:255}] ), "c#" }, - { Css, "css.ascii", define_colors!( [Color::Blue, Color::White] ) }, - { D, "d.ascii", define_colors!( [Color::Red] ) }, - { Dart, "dart.ascii", define_colors!( [Color::Blue, Color::Cyan, Color::Blue ] : [Color::TrueColor{ r:0, g:163, b:231 }, Color::TrueColor{ r:66, g:223, b:205 }, Color::TrueColor{ r:1, g:89, b:125 }] ) }, - { Dockerfile, "dockerfile.ascii", define_colors!( [Color::Cyan, Color::White, Color::Cyan] ) }, - { Elisp, "emacslisp.ascii", define_colors!( [Color::Magenta, Color::White] ), "emacslisp" }, - { Elixir, "elixir.ascii", define_colors!( [Color::Magenta] ) }, - { Elm, "elm.ascii", define_colors!( [Color::Blue, Color::Green, Color::Yellow, Color::Cyan] ) }, - { Emojicode, "emojicode.ascii", define_colors!( [Color::Green, Color::Magenta, Color::Magenta, Color::Magenta] : [Color::TrueColor{r:119, g:178, b:85}, Color::TrueColor{r:146, g:102, b:204}, Color::TrueColor{r:170, g:141, b:216}, Color::TrueColor{r:116, g:78, b:170}] ) }, - { Erlang, "erlang.ascii", define_colors!( [Color::Red] ) }, - { Fish, "fish.ascii", define_colors!( [Color::Red, Color::Yellow] ) }, - { Forth, "forth.ascii", define_colors!( [Color::Red] ) }, - { FortranModern, "f90.ascii", define_colors!( [Color::White, Color::Green, Color::Cyan, Color::Yellow, Color::Red] ), "fortran" }, - { FSharp, "fsharp.ascii", define_colors!( [Color::Cyan, Color::Cyan] ), "f#" }, - { GdScript, "gdscript.ascii", define_colors!( [Color::Cyan, Color::White] : [Color::TrueColor{ r:69, g:141, b:192 }, Color::TrueColor{ r:255, g:255, b:255}] ) }, - { Go, "go.ascii", define_colors!( [Color::Cyan, Color::White, Color::Yellow] : [Color::TrueColor{ r:116, g:205, b:221 }, Color::TrueColor{ r:255, g:255, b:255 }, Color::TrueColor{ r:246, g:210, b:162 }] ) }, - { Graphql, "graphql.ascii", define_colors!( [Color::Magenta] ) }, - { Groovy, "groovy.ascii", define_colors!( [Color::Cyan, Color::White] ) }, - { Haskell, "haskell.ascii", define_colors!( [Color::Cyan, Color::Magenta, Color::Blue] : [Color::TrueColor{ r:69, g:58, b:98 }, Color::TrueColor{ r:94, g:80, b:134 }, Color::TrueColor{ r:143, g:78, b:139 }] ) }, - { Haxe, "haxe.ascii", define_colors!( [Color::Yellow, Color::Yellow, Color::Yellow] : [Color::TrueColor{ r: 250, g: 178, b: 11 }, Color::TrueColor{ r:246, g:153, b:18 }, Color::TrueColor{ r: 244, g: 114, b: 22 }] ) }, - { Hcl, "hcl.ascii", define_colors!( [Color::Magenta, Color::Magenta] : [Color::TrueColor{ r: 95, g: 67, b: 233 }, Color::TrueColor{ r: 64, g: 64, b: 178 }] ) }, - { HolyC, "holyc.ascii", define_colors!( [Color::Yellow, Color::Cyan, Color::White] : [Color::TrueColor{ r:251, g:254 ,b:103}, Color::TrueColor{ r:11, g:68 ,b:157}, Color::TrueColor{ r:255, g:255 ,b:255} ]) }, - { Html, "html.ascii", define_colors!( [Color::Red, Color::White] ) }, - { Idris, "idris.ascii", define_colors!( [Color::Red] ) }, - { Java, "java.ascii", define_colors!( [Color::Red, Color::Blue] : [Color::TrueColor{ r:244, g:67 ,b:54}, Color::TrueColor{ r:22, g:101 ,b:192} ] ) }, - { JavaScript, "javascript.ascii", define_colors!( [Color::Yellow] : [Color::TrueColor{ r:236, g:230 ,b:83} ]) }, - { Json, "json.ascii", define_colors!( [Color::White, Color::Black] ) }, - { Jsonnet, "jsonnet.ascii", define_colors!( [Color::White, Color::Black] ) }, - { Jsx, "jsx.ascii", define_colors!( [Color::Yellow] ) }, - { Julia, "julia.ascii", define_colors!( [Color::White, Color::Blue, Color::Green, Color::Red, Color::Magenta] ) }, - { Jupyter, "jupyter.ascii", define_colors!( [Color::White, Color::Yellow, Color::White] : [Color::TrueColor{ r:255, g:255 ,b:255}, Color::TrueColor{ r:255, g:112 ,b:15}, Color::TrueColor{ r:158, g:158 ,b:158} ] ), "jupyter-notebooks" }, - { Kotlin, "kotlin.ascii", define_colors!( [Color::Blue, Color::Yellow, Color::Magenta] ) }, - { Lisp, "lisp.ascii", define_colors!( [Color::White] ) }, - { Lua, "lua.ascii", define_colors!( [Color::Blue, Color::White, Color::White] : [Color::TrueColor{ r:46, g:0 ,b:127}, Color::TrueColor{ r:128, g:128 ,b:128}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, - { LLVM, "llvm.ascii", define_colors!( [Color::Red] : [Color::TrueColor{ r:152, g:1 ,b:46}] ) }, - { Markdown, "markdown.ascii", define_colors!( [Color::White, Color::Red] ) }, - { Nim, "nim.ascii", define_colors!( [Color::Yellow, Color::White] ) }, - { Nix, "nix.ascii", define_colors!( [Color::Cyan, Color::Blue] ) }, - { ObjectiveC, "objectivec.ascii", define_colors!( [Color::Cyan, Color::Blue] ), "objective-c" }, - { OCaml, "ocaml.ascii", define_colors!( [Color::Yellow] ) }, - { Org, "org.ascii", define_colors!( [Color::Green, Color::Red, Color::White] ) }, - { Perl, "perl.ascii", define_colors!( [Color::Cyan] ) }, - { Php, "php.ascii", define_colors!( [Color::Magenta, Color::Blue, Color::Cyan, Color::White] ) }, - { PowerShell, "powershell.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:49, g:108, b:185}, Color::TrueColor{ r:255, g:255, b:255} ] ) }, - { Processing, "processing.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:80, g:80 ,b:80}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, - { Prolog, "prolog.ascii", define_colors!( [Color::White] ) }, - { Protobuf, "protobuf.ascii", define_colors!( [Color::Red, Color::Blue, Color::Green, Color::Yellow] )}, - { PureScript, "purescript.ascii", define_colors!( [Color::White] ) }, - { Python, "python.ascii", define_colors!( [Color::Blue, Color::Yellow] : [Color::TrueColor{ r:47, g:105 ,b:162}, Color::TrueColor{ r:255, g:217 ,b:64} ] ) }, - { Qml, "qml.ascii", define_colors!( [Color::Green, Color::White, Color::Green] : [Color::TrueColor{ r:128, g:195 ,b:66}, Color::TrueColor{ r:255, g:255 ,b:255}, Color::TrueColor{ r:77, g:117 ,b:40} ] ) }, - { R, "r.ascii", define_colors!( [Color::White, Color::Blue] ) }, - { Racket, "racket.ascii", define_colors!( [Color::Red, Color::White, Color::Blue] ) }, + { Ada, Programming, "ada.ascii", define_colors!( [Color::White, Color::Cyan, Color::Blue] : [Color::TrueColor{r:255, g:255, b:255}, Color::TrueColor{r:0, g:24, b:201}, Color::TrueColor{r:12, g:10, b:124}] ) }, + { Assembly, Programming, "assembly.ascii", define_colors!( [Color::Cyan] ) }, + { AutoHotKey, Programming, "autohotkey.ascii", define_colors!( [Color::White, Color::Green] : [Color::TrueColor{r:255, g:255, b:255}, Color::TrueColor{r: 0x11, g: 0x98, b: 0x10}]) }, + { Bash, Programming, "bash.ascii", define_colors!( [Color::White] ), "bash" }, + { C, Programming, "c.ascii", define_colors!( [Color::Cyan, Color::Blue, Color::White] : [Color::TrueColor{r:93, g:108, b:191}, Color::TrueColor{r:41, g:54, b:147}, Color::TrueColor{r:255, g:255, b:255}] ) }, + { Clojure, Programming, "clojure.ascii", define_colors!( [Color::Cyan, Color::Green] ) }, + { CMake, Programming, "cmake.ascii", define_colors!( [Color::Blue, Color::Green, Color::Red, Color::Black] ) }, + { CoffeeScript, Programming, "coffeescript.ascii", define_colors!( [Color::Red] ) }, + { Cpp, Programming, "cpp.ascii", define_colors!( [Color::Cyan, Color::Blue, Color::White] : [Color::TrueColor{r:100, g:154, b:210}, Color::TrueColor{r:0, g:68, b:130}, Color::TrueColor{r:255, g:255, b:255}] ), "c++" }, + { Crystal, Programming, "crystal.ascii", define_colors!( [Color::White, Color::Black] ) }, + { CSharp, Programming, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta, Color::White] : [Color::TrueColor{r:154, g:73, b:147}, Color::TrueColor{r:106, g:21, b:119}, Color::TrueColor{r:255, g:255, b:255}] ), "c#" }, + { Css, Markup, "css.ascii", define_colors!( [Color::Blue, Color::White] ) }, + { D, Programming, "d.ascii", define_colors!( [Color::Red] ) }, + { Dart, Programming, "dart.ascii", define_colors!( [Color::Blue, Color::Cyan, Color::Blue ] : [Color::TrueColor{ r:0, g:163, b:231 }, Color::TrueColor{ r:66, g:223, b:205 }, Color::TrueColor{ r:1, g:89, b:125 }] ) }, + { Dockerfile, Programming, "dockerfile.ascii", define_colors!( [Color::Cyan, Color::White, Color::Cyan] ) }, + { Elisp, Programming, "emacslisp.ascii", define_colors!( [Color::Magenta, Color::White] ), "emacslisp" }, + { Elixir, Programming, "elixir.ascii", define_colors!( [Color::Magenta] ) }, + { Elm, Programming, "elm.ascii", define_colors!( [Color::Blue, Color::Green, Color::Yellow, Color::Cyan] ) }, + { Emojicode, Programming, "emojicode.ascii", define_colors!( [Color::Green, Color::Magenta, Color::Magenta, Color::Magenta] : [Color::TrueColor{r:119, g:178, b:85}, Color::TrueColor{r:146, g:102, b:204}, Color::TrueColor{r:170, g:141, b:216}, Color::TrueColor{r:116, g:78, b:170}] ) }, + { Erlang, Programming, "erlang.ascii", define_colors!( [Color::Red] ) }, + { Fish, Programming, "fish.ascii", define_colors!( [Color::Red, Color::Yellow] ) }, + { Forth, Programming, "forth.ascii", define_colors!( [Color::Red] ) }, + { FortranModern, Programming, "f90.ascii", define_colors!( [Color::White, Color::Green, Color::Cyan, Color::Yellow, Color::Red] ), "fortran" }, + { FSharp, Programming, "fsharp.ascii", define_colors!( [Color::Cyan, Color::Cyan] ), "f#" }, + { GdScript, Programming, "gdscript.ascii", define_colors!( [Color::Cyan, Color::White] : [Color::TrueColor{ r:69, g:141, b:192 }, Color::TrueColor{ r:255, g:255, b:255}] ) }, + { Go, Programming, "go.ascii", define_colors!( [Color::Cyan, Color::White, Color::Yellow] : [Color::TrueColor{ r:116, g:205, b:221 }, Color::TrueColor{ r:255, g:255, b:255 }, Color::TrueColor{ r:246, g:210, b:162 }] ) }, + { Graphql, Data, "graphql.ascii", define_colors!( [Color::Magenta] ) }, + { Groovy, Programming, "groovy.ascii", define_colors!( [Color::Cyan, Color::White] ) }, + { Haskell, Programming, "haskell.ascii", define_colors!( [Color::Cyan, Color::Magenta, Color::Blue] : [Color::TrueColor{ r:69, g:58, b:98 }, Color::TrueColor{ r:94, g:80, b:134 }, Color::TrueColor{ r:143, g:78, b:139 }] ) }, + { Haxe, Programming, "haxe.ascii", define_colors!( [Color::Yellow, Color::Yellow, Color::Yellow] : [Color::TrueColor{ r: 250, g: 178, b: 11 }, Color::TrueColor{ r:246, g:153, b:18 }, Color::TrueColor{ r: 244, g: 114, b: 22 }] ) }, + { Hcl, Programming, "hcl.ascii", define_colors!( [Color::Magenta, Color::Magenta] : [Color::TrueColor{ r: 95, g: 67, b: 233 }, Color::TrueColor{ r: 64, g: 64, b: 178 }] ) }, + { HolyC, Programming, "holyc.ascii", define_colors!( [Color::Yellow, Color::Cyan, Color::White] : [Color::TrueColor{ r:251, g:254 ,b:103}, Color::TrueColor{ r:11, g:68 ,b:157}, Color::TrueColor{ r:255, g:255 ,b:255} ]) }, + { Html, Markup, "html.ascii", define_colors!( [Color::Red, Color::White] ) }, + { Idris, Programming, "idris.ascii", define_colors!( [Color::Red] ) }, + { Java, Programming, "java.ascii", define_colors!( [Color::Red, Color::Blue] : [Color::TrueColor{ r:244, g:67 ,b:54}, Color::TrueColor{ r:22, g:101 ,b:192} ] ) }, + { JavaScript, Programming, "javascript.ascii", define_colors!( [Color::Yellow] : [Color::TrueColor{ r:236, g:230 ,b:83} ]) }, + { Json, Data, "json.ascii", define_colors!( [Color::White, Color::Black] ) }, + { Jsonnet, Programming, "jsonnet.ascii", define_colors!( [Color::White, Color::Black] ) }, + { Jsx, Programming, "jsx.ascii", define_colors!( [Color::Yellow] ) }, + { Julia, Programming, "julia.ascii", define_colors!( [Color::White, Color::Blue, Color::Green, Color::Red, Color::Magenta] ) }, + { Jupyter, Programming, "jupyter.ascii", define_colors!( [Color::White, Color::Yellow, Color::White] : [Color::TrueColor{ r:255, g:255 ,b:255}, Color::TrueColor{ r:255, g:112 ,b:15}, Color::TrueColor{ r:158, g:158 ,b:158} ] ), "jupyter-notebooks" }, + { Kotlin, Programming, "kotlin.ascii", define_colors!( [Color::Blue, Color::Yellow, Color::Magenta] ) }, + { Lisp, Programming, "lisp.ascii", define_colors!( [Color::White] ) }, + { Lua, Programming, "lua.ascii", define_colors!( [Color::Blue, Color::White, Color::White] : [Color::TrueColor{ r:46, g:0 ,b:127}, Color::TrueColor{ r:128, g:128 ,b:128}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, + { LLVM, Programming, "llvm.ascii", define_colors!( [Color::Red] : [Color::TrueColor{ r:152, g:1 ,b:46}] ) }, + { Markdown, Prose, "markdown.ascii", define_colors!( [Color::White, Color::Red] ) }, + { Nim, Programming, "nim.ascii", define_colors!( [Color::Yellow, Color::White] ) }, + { Nix, Programming, "nix.ascii", define_colors!( [Color::Cyan, Color::Blue] ) }, + { ObjectiveC, Programming, "objectivec.ascii", define_colors!( [Color::Cyan, Color::Blue] ), "objective-c" }, + { OCaml, Programming, "ocaml.ascii", define_colors!( [Color::Yellow] ) }, + { Org, Prose, "org.ascii", define_colors!( [Color::Green, Color::Red, Color::White] ) }, + { Perl, Programming, "perl.ascii", define_colors!( [Color::Cyan] ) }, + { Php, Programming, "php.ascii", define_colors!( [Color::Magenta, Color::Blue, Color::Cyan, Color::White] ) }, + { PowerShell, Programming, "powershell.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:49, g:108, b:185}, Color::TrueColor{ r:255, g:255, b:255} ] ) }, + { Processing, Programming, "processing.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:80, g:80 ,b:80}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, + { Prolog, Programming, "prolog.ascii", define_colors!( [Color::White] ) }, + { Protobuf, Programming, "protobuf.ascii", define_colors!( [Color::Red, Color::Blue, Color::Green, Color::Yellow] )}, + { PureScript, Programming, "purescript.ascii", define_colors!( [Color::White] ) }, + { Python, Programming, "python.ascii", define_colors!( [Color::Blue, Color::Yellow] : [Color::TrueColor{ r:47, g:105 ,b:162}, Color::TrueColor{ r:255, g:217 ,b:64} ] ) }, + { Qml, Programming, "qml.ascii", define_colors!( [Color::Green, Color::White, Color::Green] : [Color::TrueColor{ r:128, g:195 ,b:66}, Color::TrueColor{ r:255, g:255 ,b:255}, Color::TrueColor{ r:77, g:117 ,b:40} ] ) }, + { R, Programming, "r.ascii", define_colors!( [Color::White, Color::Blue] ) }, + { Racket, Programming, "racket.ascii", define_colors!( [Color::Red, Color::White, Color::Blue] ) }, { - Perl6, "raku.ascii", define_colors!( [ + Perl6, Programming, "raku.ascii", define_colors!( [ Color::Blue, Color::Red, Color::Yellow, @@ -232,17 +251,17 @@ define_languages! { ] ), "raku" }, - { Ruby, "ruby.ascii", define_colors!( [Color::Red] : [Color::TrueColor{ r: 204, g: 52, b: 45 }] ) }, - { Rust, "rust.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r:228, g:55 ,b:23}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, - { Sass, "sass.ascii", define_colors!( [Color::Magenta] : [Color::TrueColor{ r:205, g:103 ,b:153} ] ) }, - { Scala, "scala.ascii", define_colors!( [Color::Red, Color::Red] : [Color::TrueColor{ r:223, g:63 ,b:61}, Color::TrueColor{ r:127, g:12 ,b:29} ] ) }, - { Scheme, "scheme.ascii", define_colors!( [Color::White] : [Color::TrueColor{r: 85, g:85, b:85}] ) }, - { Sh, "shell.ascii", define_colors!( [Color::Green] ), "shell" }, - { Solidity, "solidity.ascii", define_colors!( [ Color::White, Color::Black, Color::Black, Color::Black, Color::Black] : [ Color::White, Color::TrueColor{ r: 46, g: 46, b: 46 }, Color::TrueColor{ r: 26, g: 26, b: 26 }, Color::TrueColor{ r: 51, g: 51, b: 51 }, Color::TrueColor{ r: 81, g: 81, b: 81 } ] ) }, - { Sql, "sql.ascii", define_colors!( [Color::Cyan, Color::Yellow] ) }, - { Svelte, "svelte.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r: 255, g: 60, b: 0 }, Color::TrueColor{ r: 255, g: 255, b: 255 }] ) }, + { Ruby, Programming, "ruby.ascii", define_colors!( [Color::Red] : [Color::TrueColor{ r: 204, g: 52, b: 45 }] ) }, + { Rust, Programming, "rust.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r:228, g:55 ,b:23}, Color::TrueColor{ r:255, g:255 ,b:255} ] ) }, + { Sass, Markup, "sass.ascii", define_colors!( [Color::Magenta] : [Color::TrueColor{ r:205, g:103 ,b:153} ] ) }, + { Scala, Programming, "scala.ascii", define_colors!( [Color::Red, Color::Red] : [Color::TrueColor{ r:223, g:63 ,b:61}, Color::TrueColor{ r:127, g:12 ,b:29} ] ) }, + { Scheme, Programming, "scheme.ascii", define_colors!( [Color::White] : [Color::TrueColor{r: 85, g:85, b:85}] ) }, + { Sh, Programming, "shell.ascii", define_colors!( [Color::Green] ), "shell" }, + { Solidity, Programming, "solidity.ascii", define_colors!( [ Color::White, Color::Black, Color::Black, Color::Black, Color::Black] : [ Color::White, Color::TrueColor{ r: 46, g: 46, b: 46 }, Color::TrueColor{ r: 26, g: 26, b: 26 }, Color::TrueColor{ r: 51, g: 51, b: 51 }, Color::TrueColor{ r: 81, g: 81, b: 81 } ] ) }, + { Sql, Data, "sql.ascii", define_colors!( [Color::Cyan, Color::Yellow] ) }, + { Svelte, Markup, "svelte.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r: 255, g: 60, b: 0 }, Color::TrueColor{ r: 255, g: 255, b: 255 }] ) }, { - Swift, "swift.ascii", define_colors!( [ + Swift, Programming, "swift.ascii", define_colors!( [ Color::Red, Color::Red, Color::Red, @@ -266,18 +285,18 @@ define_languages! { Color::TrueColor{ r:253, g:40, b:34 } ] ) }, - { Tcl, "tcl.ascii", define_colors!( [Color::Blue, Color::White, Color::Cyan] ) }, - { Tex, "tex.ascii", define_colors!( [Color::White, Color::Black] ) }, - { Toml, "toml.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r:156, g:66, b:33}, Color::TrueColor{ r:255, g:255, b:255} ]) }, - { Tsx, "tsx.ascii", define_colors!( [Color::Blue] ) }, - { TypeScript, "typescript.ascii", define_colors!( [Color::Cyan, Color::White] : [Color::TrueColor{ r:0, g:122, b:204}, Color::TrueColor{ r:255, g:255, b:255} ]) }, - { Vala, "vala.ascii", define_colors!( [Color::Magenta, Color::White] ) }, - { VimScript, "vimscript.ascii", define_colors!( [Color::Green, Color::Black, Color::White] ) }, - { Vue, "vue.ascii", define_colors!( [Color::Green, Color::Blue] ) }, - { WebAssembly, "webassembly.ascii", define_colors!( [Color::Magenta, Color::White] : [Color::TrueColor{ r:101, g:79, b:240}, Color::TrueColor{ r:255, g:255, b:255} ]) }, - { Xaml, "xaml.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:51, g:120, b:206}, Color::TrueColor{ r:255, g:255, b:255} ]) }, - { Xml, "xml.ascii", define_colors!( [Color::Yellow, Color::White, Color::Green] ) }, - { Yaml, "yaml.ascii", define_colors!( [Color::White] ) }, - { Zig, "zig.ascii", define_colors!( [Color::Yellow] ) }, - { Zsh, "zsh.ascii", define_colors!( [Color::White] ) }, + { Tcl, Programming, "tcl.ascii", define_colors!( [Color::Blue, Color::White, Color::Cyan] ) }, + { Tex, Markup, "tex.ascii", define_colors!( [Color::White, Color::Black] ) }, + { Toml, Data, "toml.ascii", define_colors!( [Color::Red, Color::White] : [Color::TrueColor{ r:156, g:66, b:33}, Color::TrueColor{ r:255, g:255, b:255} ]) }, + { Tsx, Programming, "tsx.ascii", define_colors!( [Color::Blue] ) }, + { TypeScript, Programming, "typescript.ascii", define_colors!( [Color::Cyan, Color::White] : [Color::TrueColor{ r:0, g:122, b:204}, Color::TrueColor{ r:255, g:255, b:255} ]) }, + { Vala, Programming, "vala.ascii", define_colors!( [Color::Magenta, Color::White] ) }, + { VimScript, Programming, "vimscript.ascii", define_colors!( [Color::Green, Color::Black, Color::White] ) }, + { Vue, Programming, "vue.ascii", define_colors!( [Color::Green, Color::Blue] ) }, + { WebAssembly, Programming, "webassembly.ascii", define_colors!( [Color::Magenta, Color::White] : [Color::TrueColor{ r:101, g:79, b:240}, Color::TrueColor{ r:255, g:255, b:255} ]) }, + { Xaml, Data, "xaml.ascii", define_colors!( [Color::Blue, Color::White] : [Color::TrueColor{ r:51, g:120, b:206}, Color::TrueColor{ r:255, g:255, b:255} ]) }, + { Xml, Data, "xml.ascii", define_colors!( [Color::Yellow, Color::White, Color::Green] ) }, + { Yaml, Programming, "yaml.ascii", define_colors!( [Color::White] ) }, + { Zig, Programming, "zig.ascii", define_colors!( [Color::Yellow] ) }, + { Zsh, Programming, "zsh.ascii", define_colors!( [Color::White] ) }, } diff --git a/src/info/langs/mod.rs b/src/info/langs/mod.rs index ce4bed1c0..742509fa0 100644 --- a/src/info/langs/mod.rs +++ b/src/info/langs/mod.rs @@ -1,7 +1,8 @@ use anyhow::{Context, Result}; -use language::{get_all_language_types, Language}; +use language::{Language, LanguageType}; use regex::Regex; use std::collections::HashMap; +use strum::IntoEnumIterator; pub mod language; @@ -12,9 +13,10 @@ pub fn get_dominant_language(languages_stat_vec: &[(Language, f64)]) -> Language pub fn get_language_statistics( dir: &str, ignored_directories: &[String], + language_types: &[LanguageType], include_hidden: bool, ) -> Result<(Vec<(Language, f64)>, usize)> { - let stats = get_statistics(dir, ignored_directories, include_hidden); + let stats = get_statistics(dir, ignored_directories, language_types, include_hidden); let language_distribution = get_language_distribution(&stats) .with_context(|| "Could not find any source code in this directory")?; let mut language_distribution_vec: Vec<(_, _)> = language_distribution.into_iter().collect(); @@ -26,7 +28,7 @@ pub fn get_language_statistics( fn get_language_distribution(languages: &tokei::Languages) -> Option> { let mut language_distribution = HashMap::new(); - for (language_type, language) in languages.iter() { + for (language_name, language) in languages.iter() { let mut code = language.code; let has_children = !language.children.is_empty(); @@ -43,7 +45,7 @@ fn get_language_distribution(languages: &tokei::Languages) -> Option usize { fn get_statistics( dir: &str, ignored_directories: &[String], + language_types: &[LanguageType], include_hidden: bool, ) -> tokei::Languages { let mut languages = tokei::Languages::new(); - let required_languages = get_all_language_types(); + let supported_languages = get_supported_languages(language_types); + let tokei_config = tokei::Config { - types: Some(required_languages), + types: Some(supported_languages), hidden: Some(include_hidden), ..tokei::Config::default() }; @@ -82,6 +86,13 @@ fn get_statistics( languages } +fn get_supported_languages(types: &[LanguageType]) -> Vec { + Language::iter() + .filter(|language| types.contains(&language.get_type())) + .map(|language| language.into()) + .collect() +} + fn get_ignored_directories(user_ignored_directories: &[String]) -> Vec { let mut ignored_directories = Vec::new(); if !user_ignored_directories.is_empty() { diff --git a/src/info/mod.rs b/src/info/mod.rs index c692b7469..08473b118 100644 --- a/src/info/mod.rs +++ b/src/info/mod.rs @@ -171,6 +171,7 @@ impl Info { let (languages, lines_of_code) = langs::get_language_statistics( &workdir, &config.ignored_directories, + &config.language_types, config.include_hidden, )?; let dominant_language = langs::get_dominant_language(&languages);