Skip to content

Commit b98a26c

Browse files
authored
add language type (#513)
* add language type * change language type for xml, xaml, jupyter and vue
1 parent 34267d4 commit b98a26c

File tree

5 files changed

+159
-104
lines changed

5 files changed

+159
-104
lines changed

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Adding support for a new Language consists in adding a new entry to the `define_
1515

1616
**Example**:
1717

18-
`{ CSharp, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta] ), "c#" },`
18+
`{ CSharp, Programming, "csharp.ascii", define_colors!( [Color::Blue, Color::Magenta] ), "c#" },`
1919

20-
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.
20+
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.
2121

2222
#### Ascii logo
2323

src/cli.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::info::deps::package_manager::PackageManager;
22
use crate::info::info_field::{InfoField, InfoFieldOff};
3-
use crate::info::langs::language::Language;
3+
use crate::info::langs::language::{Language, LanguageType};
44
use crate::ui::image_backends;
55
use crate::ui::image_backends::ImageBackend;
66
use crate::ui::printer::SerializationFormat;
@@ -38,6 +38,7 @@ pub struct Config {
3838
pub iso_time: bool,
3939
pub show_email: bool,
4040
pub include_hidden: bool,
41+
pub language_types: Vec<LanguageType>,
4142
}
4243

4344
impl Config {
@@ -64,11 +65,13 @@ impl Config {
6465
Arg::with_name("output")
6566
.short("o")
6667
.long("output")
68+
.value_name("FORMAT")
6769
.help("Outputs Onefetch in a specific format (json, yaml).")
6870
.takes_value(true)
69-
.possible_values(&SerializationFormat::iter()
70-
.map(|format| format.into())
71-
.collect::<Vec<&str>>())
71+
.possible_values(
72+
&SerializationFormat::iter()
73+
.map(|format| format.into())
74+
.collect::<Vec<&str>>())
7275
)
7376
.arg(
7477
Arg::with_name("languages")
@@ -276,6 +279,20 @@ impl Config {
276279
.takes_value(true)
277280
.help("Ignore all files & directories matching EXCLUDE."),
278281
)
282+
.arg(
283+
Arg::with_name("type")
284+
.short("T")
285+
.long("type")
286+
.value_name("TYPE")
287+
.multiple(true)
288+
.takes_value(true)
289+
.case_insensitive(true)
290+
.help("Filters output by language type (*programming*, *markup*, prose, data).")
291+
.possible_values(
292+
&LanguageType::iter()
293+
.map(|t| t.into())
294+
.collect::<Vec<&str>>())
295+
)
279296
.get_matches();
280297

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

398+
let language_types: Vec<LanguageType> = if let Some(values) = matches.values_of("type") {
399+
values.map(|t| LanguageType::from_str(t).unwrap()).collect()
400+
} else {
401+
vec![LanguageType::Programming, LanguageType::Markup]
402+
};
403+
381404
Ok(Config {
382405
repo_path,
383406
ascii_input,
@@ -402,6 +425,7 @@ impl Config {
402425
iso_time,
403426
show_email,
404427
include_hidden,
428+
language_types,
405429
})
406430
}
407431
}

0 commit comments

Comments
 (0)