Skip to content

Commit

Permalink
add language type (#513)
Browse files Browse the repository at this point in the history
* add language type

* change language type for xml, xaml, jupyter and vue
  • Loading branch information
o2sh authored Oct 20, 2021
1 parent 34267d4 commit b98a26c
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 104 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <LANGUAGE>` - by default we take the Enum name in lowercase.

#### Ascii logo

Expand Down
32 changes: 28 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,6 +38,7 @@ pub struct Config {
pub iso_time: bool,
pub show_email: bool,
pub include_hidden: bool,
pub language_types: Vec<LanguageType>,
}

impl Config {
Expand All @@ -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::<Vec<&str>>())
.possible_values(
&SerializationFormat::iter()
.map(|format| format.into())
.collect::<Vec<&str>>())
)
.arg(
Arg::with_name("languages")
Expand Down Expand Up @@ -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::<Vec<&str>>())
)
.get_matches();

let true_color = match matches.value_of("true-color") {
Expand Down Expand Up @@ -378,6 +395,12 @@ impl Config {
.map_or(Regex::from_str(r"\[bot\]").unwrap(), |s| Regex::from_str(s).unwrap())
});

let language_types: Vec<LanguageType> = 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,
Expand All @@ -402,6 +425,7 @@ impl Config {
iso_time,
show_email,
include_hidden,
language_types,
})
}
}
Expand Down
Loading

0 comments on commit b98a26c

Please sign in to comment.