icons.rs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. use ansi_term::Style;
  2. use crate::fs::File;
  3. use crate::info::filetype::FileExtensions;
  4. use crate::output::file_name::FileStyle;
  5. pub trait FileIcon {
  6. fn icon_file(&self, file: &File) -> Option<char>;
  7. }
  8. pub enum Icons {
  9. Audio,
  10. Image,
  11. Video,
  12. }
  13. impl Icons {
  14. pub fn value(&self) -> char {
  15. match *self {
  16. Icons::Audio => '\u{f001}',
  17. Icons::Image => '\u{f1c5}',
  18. Icons::Video => '\u{f03d}',
  19. }
  20. }
  21. }
  22. pub fn painted_icon(file: &File, style: &FileStyle) -> String {
  23. let file_icon = icon(&file).to_string();
  24. let painted = style.exts
  25. .colour_file(&file)
  26. .map_or(file_icon.to_string(), |c| {
  27. // Remove underline from icon
  28. if c.is_underline {
  29. match c.foreground {
  30. Some(color) => Style::from(color).paint(file_icon).to_string(),
  31. None => Style::default().paint(file_icon).to_string(),
  32. }
  33. } else {
  34. c.paint(file_icon).to_string()
  35. }
  36. });
  37. format!("{} ", painted)
  38. }
  39. fn icon(file: &File) -> char {
  40. let extensions = Box::new(FileExtensions);
  41. if file.is_directory() { '\u{f115}' }
  42. else if let Some(icon) = extensions.icon_file(file) { icon }
  43. else if let Some(ext) = file.ext.as_ref() {
  44. match ext.as_str() {
  45. "ai" => '\u{e7b4}',
  46. "android" => '\u{e70e}',
  47. "apple" => '\u{f179}',
  48. "avro" => '\u{e60b}',
  49. "clj" => '\u{e768}',
  50. "coffee" => '\u{f0f4}',
  51. "cpp" => '\u{e61d}',
  52. "hpp" => '\u{e61d}',
  53. "c" => '\u{e61e}',
  54. "h" => '\u{e61e}',
  55. "cs" => '\u{f81a}',
  56. "css" => '\u{e749}',
  57. "d" => '\u{e7af}',
  58. "dart" => '\u{e798}',
  59. "db" => '\u{f1c0}',
  60. "diff" => '\u{f440}',
  61. "patch" => '\u{f440}',
  62. "rtf" => '\u{f1c2}',
  63. "doc" => '\u{f1c2}',
  64. "docx" => '\u{f1c2}',
  65. "odt" => '\u{f1c2}',
  66. "ebook" => '\u{e28b}',
  67. "env" => '\u{f462}',
  68. "epub" => '\u{e28a}',
  69. "erl" => '\u{e7b1}',
  70. "font" => '\u{f031}',
  71. "gform" => '\u{f298}',
  72. "git" => '\u{f1d3}',
  73. "go" => '\u{e626}',
  74. "hs" => '\u{e777}',
  75. "htm" => '\u{f13b}',
  76. "html" => '\u{f13b}',
  77. "xhtml" => '\u{f13b}',
  78. "iml" => '\u{e7b5}',
  79. "java" => '\u{e204}',
  80. "js" => '\u{e74e}',
  81. "mjs" => '\u{e74e}',
  82. "json" => '\u{e60b}',
  83. "jsx" => '\u{e7ba}',
  84. "vue" => '\u{fd42}',
  85. "node" => '\u{f898}',
  86. "less" => '\u{e758}',
  87. "log" => '\u{f18d}',
  88. "lua" => '\u{e620}',
  89. "md" => '\u{f48a}',
  90. "markdown" => '\u{f48a}',
  91. "mustache" => '\u{e60f}',
  92. "npmignore" => '\u{e71e}',
  93. "pdf" => '\u{f1c1}',
  94. "djvu" => '\u{f02d}',
  95. "mobi" => '\u{f02d}',
  96. "php" => '\u{e73d}',
  97. "pl" => '\u{e769}',
  98. "ppt" => '\u{f1c4}',
  99. "pptx" => '\u{f1c4}',
  100. "odp" => '\u{f1c4}',
  101. "psd" => '\u{e7b8}',
  102. "py" => '\u{e606}',
  103. "r" => '\u{f25d}',
  104. "rb" => '\u{e21e}',
  105. "ru" => '\u{e21e}',
  106. "erb" => '\u{e21e}',
  107. "gem" => '\u{e21e}',
  108. "rdb" => '\u{e76d}',
  109. "rs" => '\u{e7a8}',
  110. "rss" => '\u{f09e}',
  111. "rubydoc" => '\u{e73b}',
  112. "sass" => '\u{e74b}',
  113. "stylus" => '\u{e759}',
  114. "scala" => '\u{e737}',
  115. "shell" => '\u{f489}',
  116. "sqlite3" => '\u{e7c4}',
  117. "styl" => '\u{e600}',
  118. "latex" => '\u{e600}',
  119. "tex" => '\u{e600}',
  120. "ts" => '\u{e628}',
  121. "tsx" => '\u{e628}',
  122. "twig" => '\u{e61c}',
  123. "txt" => '\u{f15c}',
  124. "video" => '\u{f03d}',
  125. "vim" => '\u{e62b}',
  126. "xml" => '\u{e619}',
  127. "yml" => '\u{f481}',
  128. "yaml" => '\u{f481}',
  129. "rar" => '\u{f410}',
  130. "zip" => '\u{f410}',
  131. "bz" => '\u{f410}',
  132. "bz2" => '\u{f410}',
  133. "xz" => '\u{f410}',
  134. "taz" => '\u{f410}',
  135. "tbz" => '\u{f410}',
  136. "tbz2" => '\u{f410}',
  137. "tz" => '\u{f410}',
  138. "tar" => '\u{f410}',
  139. "tzo" => '\u{f410}',
  140. "lz" => '\u{f410}',
  141. "lzh" => '\u{f410}',
  142. "lzma" => '\u{f410}',
  143. "lzo" => '\u{f410}',
  144. "gz" => '\u{f410}',
  145. "deb" => '\u{e77d}',
  146. "rpm" => '\u{e7bb}',
  147. "exe" => '\u{e70f}',
  148. "msi" => '\u{e70f}',
  149. "dll" => '\u{e70f}',
  150. "cab" => '\u{e70f}',
  151. "bat" => '\u{e70f}',
  152. "cmd" => '\u{e70f}',
  153. "sh" => '\u{f489}',
  154. "bash" => '\u{f489}',
  155. "zsh" => '\u{f489}',
  156. "fish" => '\u{f489}',
  157. "csh" => '\u{f489}',
  158. "ini" => '\u{e615}',
  159. "toml" => '\u{e615}',
  160. "cfg" => '\u{e615}',
  161. "conf" => '\u{e615}',
  162. "apk" => '\u{e70e}',
  163. "ttf" => '\u{f031}',
  164. "woff" => '\u{f031}',
  165. "woff2" => '\u{f031}',
  166. "otf" => '\u{f031}',
  167. "csv" => '\u{f1c3}',
  168. "tsv" => '\u{f1c3}',
  169. "xls" => '\u{f1c3}',
  170. "xlsx" => '\u{f1c3}',
  171. "ods" => '\u{f1c3}',
  172. "so" => '\u{f17c}',
  173. "sql" => '\u{f1c0}',
  174. "jar" => '\u{e256}',
  175. "jad" => '\u{e256}',
  176. "class" => '\u{e256}',
  177. "war" => '\u{e256}',
  178. "groovy" => '\u{e775}',
  179. "iso" => '\u{e271}',
  180. "lock" => '\u{f023}',
  181. "swift" => '\u{e755}',
  182. "nix" => '\u{f313}',
  183. _ => '\u{f016}'
  184. }
  185. } else {
  186. '\u{f016}'
  187. }
  188. }