#[macro_use]
extern crate clap;
#[macro_use]
extern crate prettytable;
use clap::Arg;
use prettytable::format::TableFormat;
use prettytable::Table;
use unic::char::property::EnumeratedCharProperty;
use unic::ucd::{name_aliases_of, GeneralCategory, Name, NameAliasType};
fn main() {
let app = app_from_crate!()
.about(concat!(
env!("CARGO_PKG_DESCRIPTION"),
"\n\n",
"Inspect characters and their properties",
))
.arg(
Arg::with_name("STRINGS")
.help("Input strings (expected valid Unicode)")
.multiple(true),
);
let matches = app.get_matches();
let string: String = matches
.values_of("STRINGS")
.unwrap_or_default()
.collect::<Vec<&str>>()
.join(" ");
let mut table = Table::new();
let mut table_format = TableFormat::new();
table_format.padding(1, 1);
table_format.column_separator('|');
table.set_format(table_format);
string.chars().for_each(|chr| {
let display_name = Name::of(chr).map(|n| n.to_string()).unwrap_or_else(|| {
match name_aliases_of(chr, NameAliasType::NameAbbreviations) {
Some(abbrs) => abbrs[0].to_owned(),
None => "<none>".to_owned(),
}
});
table.add_row(row![
cb -> &format!("{}", chr),
rFr -> &format!("U+{:04X}", chr as u32),
l -> &display_name,
l -> &GeneralCategory::of(chr).long_name()
]);
});
table.printstd();
}