Better preview

preview
Arijit Basu 4 months ago
parent 19df482b4d
commit bb7053baa9
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

@ -264,7 +264,7 @@ xplr.config.general.preview.renderer.format = "builtin.fmt_general_preview_rende
-- Style for preview panel. -- Style for preview panel.
-- --
-- Type: [Style](https://xplr.dev/en/style) -- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.preview.renderer.style = {} xplr.config.general.preview.renderer.style = { add_modifiers = { "Dim" } }
-- The default search algorithm -- The default search algorithm
-- --
@ -348,9 +348,7 @@ xplr.config.general.sort_and_filter_ui.separator.format = " "
-- The style of the separator for the Sort & filter panel. -- The style of the separator for the Sort & filter panel.
-- --
-- Type: [Style](https://xplr.dev/en/style) -- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.sort_and_filter_ui.separator.style = { xplr.config.general.sort_and_filter_ui.separator.style = { add_modifiers = { "Dim" } }
add_modifiers = { "Dim" },
}
-- The content of the default identifier in Sort & filter panel. -- The content of the default identifier in Sort & filter panel.
-- --
@ -649,9 +647,7 @@ xplr.config.general.panel_ui.selection.border_type = "Double"
-- Style of the selection panel borders. -- Style of the selection panel borders.
-- --
-- Type: [Style](https://xplr.dev/en/style) -- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.selection.border_style = { xplr.config.general.panel_ui.selection.border_style = { fg = "Red" }
fg = "Red",
}
-- The content for the preview panel title. -- The content for the preview panel title.
-- --

@ -848,15 +848,12 @@ pub fn permissions_octal<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> { pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
fn format_node(node: &Node) -> String { fn format_node(node: &Node) -> String {
format!( format!(
"{} "• T: {}\n• P: {}\n• O: {}:{}\n• S: {}",
{}
{}
{}:{}",
node.mime_essence, node.mime_essence,
node.permissions.to_string(), node.permissions.to_string(),
node.human_size,
node.uid, node.uid,
node.gid node.gid,
node.human_size,
) )
} }
@ -868,8 +865,19 @@ pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
let size = args.layout_size; let size = args.layout_size;
let preview = if node.is_file { let preview = if node
let file = fs::File::open(&node.absolute_path)?; .canonical
.as_ref()
.map(|c| c.is_file)
.unwrap_or(node.is_file)
{
let path = node
.canonical
.as_ref()
.map(|c| &c.absolute_path)
.unwrap_or(&node.absolute_path);
let file = fs::File::open(path)?;
let reader = io::BufReader::new(file); let reader = io::BufReader::new(file);
let mut lines = vec![]; let mut lines = vec![];
for line in reader.lines() { for line in reader.lines() {
@ -883,16 +891,33 @@ pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
} }
} }
lines.join("\n") lines.join("\n")
} else if node.is_dir { } else if node
match fs::read_dir(node.absolute_path) { .canonical
Ok(nodes) => iter::once(node.relative_path) .as_ref()
.map(|c| c.is_dir)
.unwrap_or(node.is_dir)
{
let path = node
.symlink
.as_ref()
.map(|c| &c.absolute_path)
.unwrap_or(&node.relative_path);
match fs::read_dir(path) {
Ok(nodes) => iter::once(format!("▼ {}/", path))
.chain( .chain(
nodes nodes
.filter_map(|d| d.ok())
.map(|d| { .map(|d| {
d.ok() if d.file_type()
.map(|d| d.file_name().to_string_lossy().to_string()) .ok()
.map(|n| format!(" {n}")) .map(|t| t.is_dir())
.unwrap_or_else(|| "???".into()) .unwrap_or(false)
{
format!(" ▷ {}/", d.file_name().to_string_lossy())
} else {
format!(" {}", d.file_name().to_string_lossy())
}
}) })
.take(size.height.into()), .take(size.height.into()),
) )
@ -904,7 +929,7 @@ pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
"-> ×".into() "-> ×".into()
} else if node.is_symlink { } else if node.is_symlink {
node.symlink node.symlink
.map(|s| format!(" -> {}", s.absolute_path)) .map(|s| format!("-> {}", s.absolute_path))
.unwrap_or_default() .unwrap_or_default()
} else { } else {
format_node(&node) format_node(&node)

@ -894,10 +894,10 @@ fn draw_preview(
String::new() String::new()
}; };
let preview = let mut text = string_to_text(preview);
Paragraph::new(string_to_text(preview)).block(block(config, " Preview ".into())); text.patch_style(app.config.general.preview.renderer.style.to_owned().into());
let block = Paragraph::new(text).block(block(config, " Preview ".into()));
f.render_widget(preview, layout_size); f.render_widget(block, layout_size);
} }
fn draw_selection( fn draw_selection(

Loading…
Cancel
Save