Arijit Basu 3 years ago committed by Arijit Basu
parent 9b02ef3429
commit b4247a7d03

6
Cargo.lock generated

@ -4,9 +4,9 @@ version = 3
[[package]] [[package]]
name = "ansi-to-tui" name = "ansi-to-tui"
version = "0.1.9" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5091b918c2bf8daa9031e1cef129eafc45272352b885f114fb36a9aec512fcf2" checksum = "bc671d766fb75259578ba58f2e492333693c5b028e6b345cc1ac49dfd4d71b95"
dependencies = [ dependencies = [
"tui", "tui",
] ]
@ -1108,7 +1108,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "xplr" name = "xplr"
version = "0.11.1" version = "0.12.0"
dependencies = [ dependencies = [
"ansi-to-tui", "ansi-to-tui",
"anyhow", "anyhow",

@ -1,6 +1,6 @@
[package] [package]
name = "xplr" name = "xplr"
version = "0.11.1" # Update lua.rs version = "0.12.0" # Update lua.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"] authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018" edition = "2018"
description = "A hackable, minimal, fast TUI file explorer" description = "A hackable, minimal, fast TUI file explorer"
@ -29,7 +29,7 @@ indexmap = { version = "1.6.2", features = ["serde"] }
natord = "1.0.9" natord = "1.0.9"
humansize = "1.1.0" humansize = "1.1.0"
mlua = { version = "0.5.4", features = ["luajit", "vendored", "serialize", "send"] } mlua = { version = "0.5.4", features = ["luajit", "vendored", "serialize", "send"] }
ansi-to-tui = "0.1.9" ansi-to-tui = "0.2.0"
libc = "0.2.94" libc = "0.2.94"
[dev-dependencies] [dev-dependencies]

@ -1139,15 +1139,19 @@ pub enum ExternalMsg {
/// **Example:** `CallSilently: {command: tput, args: ["bell"]}` /// **Example:** `CallSilently: {command: tput, args: ["bell"]}`
CallSilently(Command), CallSilently(Command),
/// Call a Lua function /// Call a Lua function.
/// The complete app state (exportable using `PrintAppStateAndQuit` or `Debug`)
/// will be passed to the function as argument.
/// The function can optionally return a list of messages for xplr to handle
/// after the executing the function.
/// ///
/// **Example:** `CallLua: custom.foo_funtion` /// **Example:** `CallLua: custom.some_custom_funtion`
CallLua(String), CallLua(String),
/// Like `CallLua` but without the flicker. The stdin, stdout /// Like `CallLua` but without the flicker. The stdin, stdout
/// stderr will be piped to null. So it's non-interactive. /// stderr will be piped to null. So it's non-interactive.
/// ///
/// **Example:** `CallLuaSilently: custom.bar_function` /// **Example:** `CallLuaSilently: custom.some_custom_function`
CallLuaSilently(String), CallLuaSilently(String),
/// An alias to `Call: {command: bash, args: ["-c", "${command}"], silent: false}` /// An alias to `Call: {command: bash, args: ["-c", "${command}"], silent: false}`

@ -84,7 +84,7 @@ pub struct NodeTypesConfig {
pub symlink: NodeTypeConfig, pub symlink: NodeTypeConfig,
#[serde(default)] #[serde(default)]
pub mime_essence: HashMap<String, NodeTypeConfig>, pub mime_essence: HashMap<String, HashMap<String, NodeTypeConfig>>,
#[serde(default)] #[serde(default)]
pub extension: HashMap<String, NodeTypeConfig>, pub extension: HashMap<String, NodeTypeConfig>,
@ -110,7 +110,7 @@ impl NodeTypesConfig {
} }
/// Get a reference to the node types config's mime essence. /// Get a reference to the node types config's mime essence.
pub fn mime_essence(&self) -> &HashMap<String, NodeTypeConfig> { pub fn mime_essence(&self) -> &HashMap<String, HashMap<String, NodeTypeConfig>> {
&self.mime_essence &self.mime_essence
} }

@ -279,7 +279,7 @@ xplr.config.general.table.col_widths = {
xplr.config.general.table.header.cols = { xplr.config.general.table.header.cols = {
{ format = " index", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } }, { format = " index", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } },
{ format = "╭──── path", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } }, { format = "╭──── path", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } },
{ format = "permissions", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } }, { format = " permissions", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } },
{ format = "size", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } }, { format = "size", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } },
{ format = "type", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } }, { format = "type", style = { add_modifiers = nil, bg = nil, fg = nil, sub_modifiers = nil } },
} }
@ -2083,21 +2083,52 @@ xplr.fn.builtin.fmt_general_table_row_cols_2 = function(m)
end end
end end
local r = "" local p = m.permissions
-- TODO: Track https://github.com/uttarayan21/ansi-to-tui/issues/3
local r = " "
-- User -- User
r = r .. bit("r", green, m.permissions.user_read) r = r .. bit("r", green, p.user_read)
r = r .. bit("w", yellow, m.permissions.user_write) r = r .. bit("w", yellow, p.user_write)
r = r .. bit("x", red, m.permissions.user_execute)
if p.user_execute == false and p.setuid == false then
r = r .. bit("-", red, p.user_execute)
elseif p.user_execute == true and p.setuid == false then
r = r .. bit("x", red, p.user_execute)
elseif p.user_execute == false and p.setuid == true then
r = r .. bit("S", red, p.user_execute)
else
r = r .. bit("s", red, p.user_execute)
end
-- Group -- Group
r = r .. bit("r", green, m.permissions.group_read) r = r .. bit("r", green, p.group_read)
r = r .. bit("w", yellow, m.permissions.group_write) r = r .. bit("w", yellow, p.group_write)
r = r .. bit("x", red, m.permissions.group_execute)
if p.group_execute == false and p.setuid == false then
r = r .. bit("-", red, p.group_execute)
elseif p.group_execute == true and p.setuid == false then
r = r .. bit("x", red, p.group_execute)
elseif p.group_execute == false and p.setuid == true then
r = r .. bit("S", red, p.group_execute)
else
r = r .. bit("s", red, p.group_execute)
end
-- Other -- Other
r = r .. bit("r", green, m.permissions.other_read) r = r .. bit("r", green, p.other_read)
r = r .. bit("w", yellow, m.permissions.other_write) r = r .. bit("w", yellow, p.other_write)
r = r .. bit("x", red, m.permissions.other_execute)
if p.other_execute == false and p.setuid == false then
r = r .. bit("-", red, p.other_execute)
elseif p.other_execute == true and p.setuid == false then
r = r .. bit("x", red, p.other_execute)
elseif p.other_execute == false and p.setuid == true then
r = r .. bit("S", red, p.other_execute)
else
r = r .. bit("s", red, p.other_execute)
end
return r return r
end end

@ -120,9 +120,9 @@ pub fn call<'lua, A: Serialize, R: Deserialize<'lua>>(
) -> Result<R> { ) -> Result<R> {
let func = resolve_fn(&lua.globals(), func)?; let func = resolve_fn(&lua.globals(), func)?;
let args = lua.to_value(args)?; let args = lua.to_value(args)?;
let msgs: mlua::Value = func.call(args)?; let res: mlua::Value = func.call(args)?;
let msgs: R = lua.from_value(msgs)?; let res: R = lua.from_value(res)?;
Ok(msgs) Ok(res)
} }
#[cfg(test)] #[cfg(test)]
@ -133,11 +133,10 @@ mod test {
#[test] #[test]
fn test_compatibility() { fn test_compatibility() {
assert!(check_version(VERSION, "foo path").is_ok()); assert!(check_version(VERSION, "foo path").is_ok());
assert!(check_version("0.11.0", "foo path").is_ok()); assert!(check_version("0.12.0", "foo path").is_ok());
assert!(check_version("0.11.1", "foo path").is_ok());
assert!(check_version("0.11.2", "foo path").is_err()); assert!(check_version("0.12.1", "foo path").is_err());
assert!(check_version("0.10.1", "foo path").is_err()); assert!(check_version("0.10.0", "foo path").is_err());
assert!(check_version("1.12.1", "foo path").is_err()); assert!(check_version("1.12.0", "foo path").is_err());
} }
} }

@ -26,7 +26,7 @@ fn call_lua(
lua: &mlua::Lua, lua: &mlua::Lua,
func: &str, func: &str,
silent: bool, silent: bool,
) -> Result<Vec<app::ExternalMsg>> { ) -> Result<Option<Vec<app::ExternalMsg>>> {
let _focus_index = app let _focus_index = app
.directory_buffer() .directory_buffer()
.map(|d| d.focus()) .map(|d| d.focus())
@ -195,7 +195,7 @@ pub fn run(
tx_event_reader.send(true)?; tx_event_reader.send(true)?;
match call_lua(&app, &lua, &func, false) { match call_lua(&app, &lua, &func, false) {
Ok(msgs) => { Ok(Some(msgs)) => {
for msg in msgs { for msg in msgs {
app = app.handle_task(app::Task::new( app = app.handle_task(app::Task::new(
app::MsgIn::External(msg), app::MsgIn::External(msg),
@ -203,6 +203,7 @@ pub fn run(
))?; ))?;
} }
} }
Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error(err.to_string())?; app = app.log_error(err.to_string())?;
} }
@ -260,7 +261,7 @@ pub fn run(
terminal.show_cursor()?; terminal.show_cursor()?;
match call_lua(&app, &lua, &func, false) { match call_lua(&app, &lua, &func, false) {
Ok(msgs) => { Ok(Some(msgs)) => {
for msg in msgs { for msg in msgs {
app = app.handle_task(app::Task::new( app = app.handle_task(app::Task::new(
app::MsgIn::External(msg), app::MsgIn::External(msg),
@ -268,6 +269,7 @@ pub fn run(
))?; ))?;
} }
} }
Ok(None) => {}
Err(err) => { Err(err) => {
app = app.log_error(err.to_string())?; app = app.log_error(err.to_string())?;
} }

@ -475,6 +475,9 @@ fn draw_table<B: Backend>(
}) })
.unwrap_or_default(); .unwrap_or_default();
let (mimetype, mimesub) =
node.mime_essence().split_once("/").unwrap_or_default();
let node_type = app_config let node_type = app_config
.node_types() .node_types()
.special() .special()
@ -484,7 +487,8 @@ fn draw_table<B: Backend>(
app_config app_config
.node_types() .node_types()
.mime_essence() .mime_essence()
.get(node.mime_essence()) .get(mimetype)
.and_then(|t| t.get(mimesub).or_else(|| t.get("*")))
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
if node.is_symlink() { if node.is_symlink() {
@ -556,20 +560,8 @@ fn draw_table<B: Backend>(
c.format().as_ref().map(|f| { c.format().as_ref().map(|f| {
let out: Result<String> = lua::call(lua, f, &v); let out: Result<String> = lua::call(lua, f, &v);
match out { match out {
Ok(o) => { Ok(o) => ansi_to_text(o.bytes())
let text = .unwrap_or_else(|e| Text::raw(format!("{:?}", e))),
ansi_to_text(o.bytes()).unwrap_or_else(|e| {
Text::raw(format!("{:?}", e))
});
// TODO: Track https://github.com/uttarayan21/ansi-to-tui/issues/2
// And https://github.com/fdehau/tui-rs/issues/304
if text.lines.is_empty() {
Text::raw(o.to_string())
} else {
text
}
}
Err(e) => Text::raw(e.to_string()), Err(e) => Text::raw(e.to_string()),
} }
}) })

Loading…
Cancel
Save