fancy_tree/config/icons/
mod.rs1use super::ConfigFile;
3use crate::lua::interop;
4use crate::tree::Entry;
5use mlua::{FromLua, Lua};
6use std::path::Path;
7
8#[derive(Debug)]
10pub struct Icons {
11 get_icon: mlua::Function,
13}
14
15impl Icons {
16 pub fn get_icon<P>(
18 &self,
19 entry: &Entry<P>,
20 default_choice: &str,
21 ) -> mlua::Result<Option<String>>
22 where
23 P: AsRef<Path>,
24 {
25 let path = entry.path();
26 let attributes = interop::FileAttributes::from(entry);
27
28 self.get_icon.call((path, attributes, default_choice))
29 }
30}
31
32impl ConfigFile for Icons {
33 const FILENAME: &'static str = "icons.lua";
34 const DEFAULT_MODULE: &'static str = include_str!("./icons.lua");
35}
36
37impl FromLua for Icons {
38 fn from_lua(value: mlua::Value, lua: &Lua) -> mlua::Result<Self> {
39 mlua::Function::from_lua(value, lua).map(|get_icon| Self { get_icon })
40 }
41}