| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- use ansi_term::Style;
- use crate::fs::File;
- use crate::info::filetype::FileExtensions;
- use lazy_static::lazy_static;
- use std::collections::HashMap;
- pub trait FileIcon {
- fn icon_file(&self, file: &File<'_>) -> Option<char>;
- }
- #[derive(Copy, Clone)]
- pub enum Icons {
- Audio,
- Image,
- Video,
- }
- impl Icons {
- pub fn value(self) -> char {
- match self {
- Self::Audio => '\u{f001}',
- Self::Image => '\u{f1c5}',
- Self::Video => '\u{f03d}',
- }
- }
- }
- /// Converts the style used to paint a file name into the style that should be
- /// used to paint an icon.
- ///
- /// - The background colour should be preferred to the foreground colour, as
- /// if one is set, itโs the more โobviousโ colour choice.
- /// - If neither is set, just use the default style.
- /// - Attributes such as bold or underline should not be used to paint the
- /// icon, as they can make it look weird.
- pub fn iconify_style(style: Style) -> Style {
- style.background.or(style.foreground)
- .map(Style::from)
- .unwrap_or_default()
- }
- lazy_static! {
- static ref MAP_BY_NAME: HashMap<&'static str, char> = {
- let mut m = HashMap::new();
- m.insert(".Trash", '\u{f1f8}'); // ๏ธ
- m.insert(".atom", '\u{e764}'); // ๎ค
- m.insert(".bashprofile", '\u{e615}'); // ๎
- m.insert(".bashrc", '\u{f489}'); // ๏
- m.insert(".git", '\u{f1d3}'); // ๏
- m.insert(".gitattributes", '\u{f1d3}'); // ๏
- m.insert(".gitconfig", '\u{f1d3}'); // ๏
- m.insert(".github", '\u{f408}'); // ๏
- m.insert(".gitignore", '\u{f1d3}'); // ๏
- m.insert(".gitmodules", '\u{f1d3}'); // ๏
- m.insert(".rvm", '\u{e21e}'); // ๎
- m.insert(".vimrc", '\u{e62b}'); // ๎ซ
- m.insert(".vscode", '\u{e70c}'); // ๎
- m.insert(".zshrc", '\u{f489}'); // ๏
- m.insert("Cargo.lock", '\u{e7a8}'); // ๎จ
- m.insert("bin", '\u{e5fc}'); // ๎ผ
- m.insert("config", '\u{e5fc}'); // ๎ผ
- m.insert("docker-compose.yml", '\u{f308}'); // ๏
- m.insert("Dockerfile", '\u{f308}'); // ๏
- m.insert("ds_store", '\u{f179}'); // ๏
น
- m.insert("gitignore_global", '\u{f1d3}'); // ๏
- m.insert("gradle", '\u{e70e}'); // ๎
- m.insert("gruntfile.coffee", '\u{e611}'); // ๎
- m.insert("gruntfile.js", '\u{e611}'); // ๎
- m.insert("gruntfile.ls", '\u{e611}'); // ๎
- m.insert("gulpfile.coffee", '\u{e610}'); // ๎
- m.insert("gulpfile.js", '\u{e610}'); // ๎
- m.insert("gulpfile.ls", '\u{e610}'); // ๎
- m.insert("hidden", '\u{f023}'); // ๏ฃ
- m.insert("include", '\u{e5fc}'); // ๎ผ
- m.insert("lib", '\u{f121}'); // ๏ก
- m.insert("localized", '\u{f179}'); // ๏
น
- m.insert("Makefile", '\u{f489}'); // ๏
- m.insert("node_modules", '\u{e718}'); // ๎
- m.insert("npmignore", '\u{e71e}'); // ๎
- m.insert("rubydoc", '\u{e73b}'); // ๎ป
- m.insert("yarn.lock", '\u{e718}'); // ๎
- m
- };
- }
- pub fn icon_for_file(file: &File<'_>) -> char {
- let extensions = Box::new(FileExtensions);
- if let Some(icon) = MAP_BY_NAME.get(file.name.as_str()) { *icon }
- else if file.points_to_directory() {
- match file.name.as_str() {
- "bin" => '\u{e5fc}', // ๎ผ
- ".git" => '\u{f1d3}', // ๏
- ".idea" => '\u{e7b5}', // ๎ต
- _ => '\u{f115}' // ๏
- }
- }
- else if let Some(icon) = extensions.icon_file(file) { icon }
- else if let Some(ext) = file.ext.as_ref() {
- match ext.as_str() {
- "ai" => '\u{e7b4}', // ๎ด
- "android" => '\u{e70e}', // ๎
- "apk" => '\u{e70e}', // ๎
- "apple" => '\u{f179}', // ๏
น
- "avi" => '\u{f03d}', // ๏ฝ
- "avro" => '\u{e60b}', // ๎
- "awk" => '\u{f489}', // ๏
- "bash" => '\u{f489}', // ๏
- "bash_history" => '\u{f489}', // ๏
- "bash_profile" => '\u{f489}', // ๏
- "bashrc" => '\u{f489}', // ๏
- "bat" => '\u{f17a}', // ๏
บ
- "bmp" => '\u{f1c5}', // ๏
- "bz" => '\u{f410}', // ๏
- "bz2" => '\u{f410}', // ๏
- "c" => '\u{e61e}', // ๎
- "c++" => '\u{e61d}', // ๎
- "cab" => '\u{e70f}', // ๎
- "cc" => '\u{e61d}', // ๎
- "cfg" => '\u{e615}', // ๎
- "class" => '\u{e256}', // ๎
- "clj" => '\u{e768}', // ๎จ
- "cljs" => '\u{e76a}', // ๎ช
- "cls" => '\u{f034}', // ๏ด
- "cmd" => '\u{e70f}', // ๎
- "coffee" => '\u{f0f4}', // ๏ด
- "conf" => '\u{e615}', // ๎
- "cp" => '\u{e61d}', // ๎
- "cpp" => '\u{e61d}', // ๎
- "cs" => '\u{f81a}', // ๏
- "csh" => '\u{f489}', // ๏
- "cshtml" => '\u{f1fa}', // ๏บ
- "csproj" => '\u{f81a}', // ๏
- "css" => '\u{e749}', // ๎
- "csv" => '\u{f1c3}', // ๏
- "csx" => '\u{f81a}', // ๏
- "cxx" => '\u{e61d}', // ๎
- "d" => '\u{e7af}', // ๎ฏ
- "dart" => '\u{e798}', // ๎
- "db" => '\u{f1c0}', // ๏
- "deb" => '\u{e77d}', // ๎ฝ
- "diff" => '\u{f440}', // ๏
- "djvu" => '\u{f02d}', // ๏ญ
- "dll" => '\u{e70f}', // ๎
- "doc" => '\u{f1c2}', // ๏
- "docx" => '\u{f1c2}', // ๏
- "ds_store" => '\u{f179}', // ๏
น
- "DS_store" => '\u{f179}', // ๏
น
- "dump" => '\u{f1c0}', // ๎
- "ebook" => '\u{e28b}', // ๎
- "editorconfig" => '\u{e615}', // ๎
- "ejs" => '\u{e618}', // ๎
- "elm" => '\u{e62c}', // ๎ฌ
- "env" => '\u{f462}', // ๏ข
- "eot" => '\u{f031}', // ๏ฑ
- "epub" => '\u{e28a}', // ๎
- "erb" => '\u{e73b}', // ๎ป
- "erl" => '\u{e7b1}', // ๎ฑ
- "ex" => '\u{e62d}', // ๎ญ
- "exe" => '\u{f17a}', // ๏
บ
- "exs" => '\u{e62d}', // ๎ญ
- "fish" => '\u{f489}', // ๏
- "flac" => '\u{f001}', // ๏
- "flv" => '\u{f03d}', // ๏ฝ
- "font" => '\u{f031}', // ๏ฑ
- "fs" => '\u{e7a7}', // ๎ง
- "fsi" => '\u{e7a7}', // ๎ง
- "fsx" => '\u{e7a7}', // ๎ง
- "gdoc" => '\u{f1c2}', // ๏
- "gem" => '\u{e21e}', // ๎
- "gemfile" => '\u{e21e}', // ๎
- "gemspec" => '\u{e21e}', // ๎
- "gform" => '\u{f298}', // ๏
- "gif" => '\u{f1c5}', // ๏
- "git" => '\u{f1d3}', // ๏
- "gitattributes" => '\u{f1d3}', // ๏
- "gitignore" => '\u{f1d3}', // ๏
- "gitmodules" => '\u{f1d3}', // ๏
- "go" => '\u{e626}', // ๎ฆ
- "gradle" => '\u{e70e}', // ๎
- "groovy" => '\u{e775}', // ๎ต
- "gsheet" => '\u{f1c3}', // ๏
- "gslides" => '\u{f1c4}', // ๏
- "guardfile" => '\u{e21e}', // ๎
- "gz" => '\u{f410}', // ๏
- "h" => '\u{f0fd}', // ๏ฝ
- "hbs" => '\u{e60f}', // ๎
- "hpp" => '\u{f0fd}', // ๏ฝ
- "hs" => '\u{e777}', // ๎ท
- "htm" => '\u{f13b}', // ๏ป
- "html" => '\u{f13b}', // ๏ป
- "hxx" => '\u{f0fd}', // ๏ฝ
- "ico" => '\u{f1c5}', // ๏
- "image" => '\u{f1c5}', // ๏
- "iml" => '\u{e7b5}', // ๎ต
- "ini" => '\u{f17a}', // ๏
บ
- "ipynb" => '\u{e606}', // ๎
- "iso" => '\u{e271}', // ๎ฑ
- "jad" => '\u{e256}', // ๎
- "jar" => '\u{e204}', // ๎
- "java" => '\u{e204}', // ๎
- "jfi" => '\u{f1c5}', // ๏
- "jfif" => '\u{f1c5}', // ๏
- "jif" => '\u{f1c5}', // ๏
- "jpe" => '\u{f1c5}', // ๏
- "jpeg" => '\u{f1c5}', // ๏
- "jpg" => '\u{f1c5}', // ๏
- "js" => '\u{e74e}', // ๎
- "json" => '\u{e60b}', // ๎
- "jsx" => '\u{e7ba}', // ๎บ
- "ksh" => '\u{f489}', // ๏
- "latex" => '\u{f034}', // ๏ด
- "less" => '\u{e758}', // ๎
- "lhs" => '\u{e777}', // ๎ท
- "license" => '\u{f718}', // ๏
- "localized" => '\u{f179}', // ๏
น
- "lock" => '\u{f023}', // ๏ฃ
- "log" => '\u{f18d}', // ๏
- "lua" => '\u{e620}', // ๎
- "lz" => '\u{f410}', // ๏
- "lzh" => '\u{f410}', // ๏
- "lzma" => '\u{f410}', // ๏
- "lzo" => '\u{f410}', // ๏
- "m" => '\u{e61e}', // ๎
- "mm" => '\u{e61d}', // ๎
- "m4a" => '\u{f001}', // ๏
- "markdown" => '\u{f48a}', // ๏
- "md" => '\u{f48a}', // ๏
- "mjs" => '\u{e74e}', // ๎
- "mk" => '\u{f489}', // ๏
- "mkd" => '\u{f48a}', // ๏
- "mkv" => '\u{f03d}', // ๏ฝ
- "mobi" => '\u{e28b}', // ๎
- "mov" => '\u{f03d}', // ๏ฝ
- "mp3" => '\u{f001}', // ๏
- "mp4" => '\u{f03d}', // ๏ฝ
- "msi" => '\u{e70f}', // ๎
- "mustache" => '\u{e60f}', // ๎
- "nix" => '\u{f313}', // ๏
- "node" => '\u{f898}', // ๏ข
- "npmignore" => '\u{e71e}', // ๎
- "odp" => '\u{f1c4}', // ๏
- "ods" => '\u{f1c3}', // ๏
- "odt" => '\u{f1c2}', // ๏
- "ogg" => '\u{f001}', // ๏
- "ogv" => '\u{f03d}', // ๏ฝ
- "otf" => '\u{f031}', // ๏ฑ
- "patch" => '\u{f440}', // ๏
- "pdf" => '\u{f1c1}', // ๏
- "php" => '\u{e73d}', // ๎ฝ
- "pl" => '\u{e769}', // ๎ฉ
- "png" => '\u{f1c5}', // ๏
- "ppt" => '\u{f1c4}', // ๏
- "pptx" => '\u{f1c4}', // ๏
- "procfile" => '\u{e21e}', // ๎
- "properties" => '\u{e60b}', // ๎
- "ps1" => '\u{f489}', // ๏
- "psd" => '\u{e7b8}', // ๎ธ
- "pxm" => '\u{f1c5}', // ๏
- "py" => '\u{e606}', // ๎
- "pyc" => '\u{e606}', // ๎
- "r" => '\u{f25d}', // ๏
- "rakefile" => '\u{e21e}', // ๎
- "rar" => '\u{f410}', // ๏
- "razor" => '\u{f1fa}', // ๏บ
- "rb" => '\u{e21e}', // ๎
- "rdata" => '\u{f25d}', // ๏
- "rdb" => '\u{e76d}', // ๎ญ
- "rdoc" => '\u{f48a}', // ๏
- "rds" => '\u{f25d}', // ๏
- "readme" => '\u{f48a}', // ๏
- "rlib" => '\u{e7a8}', // ๎จ
- "rmd" => '\u{f48a}', // ๏
- "rpm" => '\u{e7bb}', // ๎ป
- "rs" => '\u{e7a8}', // ๎จ
- "rspec" => '\u{e21e}', // ๎
- "rspec_parallel"=> '\u{e21e}', // ๎
- "rspec_status" => '\u{e21e}', // ๎
- "rss" => '\u{f09e}', // ๏
- "rtf" => '\u{f718}', // ๏
- "ru" => '\u{e21e}', // ๎
- "rubydoc" => '\u{e73b}', // ๎ป
- "sass" => '\u{e603}', // ๎
- "scala" => '\u{e737}', // ๎ท
- "scss" => '\u{e749}', // ๎
- "sh" => '\u{f489}', // ๏
- "shell" => '\u{f489}', // ๏
- "slim" => '\u{e73b}', // ๎ป
- "sln" => '\u{e70c}', // ๎
- "so" => '\u{f17c}', // ๏
ผ
- "sql" => '\u{f1c0}', // ๎
- "sqlite3" => '\u{e7c4}', // ๎
- "sty" => '\u{f034}', // ๏ด
- "styl" => '\u{e600}', // ๎
- "stylus" => '\u{e600}', // ๎
- "svg" => '\u{f1c5}', // ๏
- "swift" => '\u{e755}', // ๎
- "tar" => '\u{f410}', // ๏
- "taz" => '\u{f410}', // ๏
- "tbz" => '\u{f410}', // ๏
- "tbz2" => '\u{f410}', // ๏
- "tex" => '\u{f034}', // ๏ด
- "tgz" => '\u{f410}', // ๏
- "tiff" => '\u{f1c5}', // ๏
- "tlz" => '\u{f410}', // ๏
- "toml" => '\u{e615}', // ๎
- "ts" => '\u{e628}', // ๎จ
- "tsv" => '\u{f1c3}', // ๏
- "tsx" => '\u{e7ba}', // ๎บ
- "ttf" => '\u{f031}', // ๏ฑ
- "twig" => '\u{e61c}', // ๎
- "txt" => '\u{f15c}', // ๏
- "txz" => '\u{f410}', // ๏
- "tz" => '\u{f410}', // ๏
- "tzo" => '\u{f410}', // ๏
- "video" => '\u{f03d}', // ๏ฝ
- "vim" => '\u{e62b}', // ๎ซ
- "vue" => '\u{fd42}', // ๏ต
- "war" => '\u{e256}', // ๎
- "wav" => '\u{f001}', // ๏
- "webm" => '\u{f03d}', // ๏ฝ
- "webp" => '\u{f1c5}', // ๏
- "windows" => '\u{f17a}', // ๏
บ
- "woff" => '\u{f031}', // ๏ฑ
- "woff2" => '\u{f031}', // ๏ฑ
- "xhtml" => '\u{f13b}', // ๏ป
- "xls" => '\u{f1c3}', // ๏
- "xlsx" => '\u{f1c3}', // ๏
- "xml" => '\u{fabf}', // ๏ชฟ
- "xul" => '\u{fabf}', // ๏ชฟ
- "xz" => '\u{f410}', // ๏
- "yaml" => '\u{f481}', // ๏
- "yml" => '\u{f481}', // ๏
- "zip" => '\u{f410}', // ๏
- "zsh" => '\u{f489}', // ๏
- "zsh-theme" => '\u{f489}', // ๏
- "zshrc" => '\u{f489}', // ๏
- _ => '\u{f15b}' // ๏
- }
- }
- else {
- '\u{f016}'
- }
- }
|