#filetype #icons #glyph #file-format #nerd-fonts #rust

devicons

A Rust library that provides filetype glyphs (icons) for a wide range of common file formats

13 releases (4 breaking)

0.6.11 Oct 15, 2024
0.6.10 Oct 15, 2024
0.5.4 Sep 29, 2024
0.4.4 Sep 29, 2024
0.1.0 Sep 9, 2024

#181 in Filesystem

Download history 286/week @ 2024-09-09 63/week @ 2024-09-16 56/week @ 2024-09-23 424/week @ 2024-09-30 290/week @ 2024-10-07 481/week @ 2024-10-14 55/week @ 2024-10-21 37/week @ 2024-10-28 172/week @ 2024-11-04 331/week @ 2024-11-11 368/week @ 2024-11-18 220/week @ 2024-11-25 246/week @ 2024-12-02

1,239 downloads per month
Used in 7 crates (6 directly)

Apache-2.0

205KB
9K SLoC

docs.rs Crates.io Total Downloads GitHub License Crates.io Version Crates.io Size

πŸ¦€ rust-devicons

A Rust library inspired by vim-devicons, that provides filetype glyphs (icons) for a wide range of common file formats.

rust-devicons

Features

  • 🦞 Icon Retrieval: Get file or directory icons based on file name/extension.
  • 🦞 Icon Color: Retrieve the color associated with the icon depending on the specified theme.
  • 🦞 Filetype Support: Supports a wide range of filetypes and filename conventions (dockerfile, makefile, etc.).
  • 🦞 Customizable Themes: Supports both light and dark themes.
Screenshot 2024-09-21 at 16 54 16

Installation

cargo add devicons

NOTE: you'll need to use a NerdFont to properly display the icons.

Usage

Here’s a simple example of how to use devicons to retrieve a file icon with the dark theme:

use std::path::Path;
use devicons::{File, Theme, icon_for_file, FileIcon};

fn main() {
    // getting the icon from a path with a specified theme
    let path = Path::new("Cargo.toml");
    let icon = icon_for_file(path, Some(Theme::Dark));

    // getting the icon from a string with a specified theme
    let icon = icon_for_file("Cargo.toml", Some(Theme::Dark));

    // getting the icon from a path with the default theme
    let icon = FileIcon::from(path);

    // directly getting an icon from a filename
    let icon = FileIcon::from("Cargo.toml");

    println!("File: {}", path.to_string_lossy());
    println!("Icon: {}", icon.icon);
    println!("Color: {}", icon.color);
}

Running the Examples

You can find more usage examples in the examples directory. To run them, use:

cargo run --example <example_name>

License

This project is licensed under the Apache 2.0 License.

Dependencies