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.
--
-- 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
--
@ -348,9 +348,7 @@ xplr.config.general.sort_and_filter_ui.separator.format = " "
-- The style of the separator for the Sort & filter panel.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.sort_and_filter_ui.separator.style = {
add_modifiers = { "Dim" },
}
xplr.config.general.sort_and_filter_ui.separator.style = { add_modifiers = { "Dim" } }
-- 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.
--
-- Type: [Style](https://xplr.dev/en/style)
xplr.config.general.panel_ui.selection.border_style = {
fg = "Red",
}
xplr.config.general.panel_ui.selection.border_style = { fg = "Red" }
-- 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>> {
fn format_node(node: &Node) -> String {
format!(
"{}
{}
{}
{}:{}",
"• T: {}\n• P: {}\n• O: {}:{}\n• S: {}",
node.mime_essence,
node.permissions.to_string(),
node.human_size,
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 preview = if node.is_file {
let file = fs::File::open(&node.absolute_path)?;
let preview = if node
.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 mut lines = vec![];
for line in reader.lines() {
@ -883,16 +891,33 @@ pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
}
}
lines.join("\n")
} else if node.is_dir {
match fs::read_dir(node.absolute_path) {
Ok(nodes) => iter::once(node.relative_path)
} else if node
.canonical
.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(
nodes
.filter_map(|d| d.ok())
.map(|d| {
d.ok()
.map(|d| d.file_name().to_string_lossy().to_string())
.map(|n| format!(" {n}"))
.unwrap_or_else(|| "???".into())
if d.file_type()
.ok()
.map(|t| t.is_dir())
.unwrap_or(false)
{
format!(" ▷ {}/", d.file_name().to_string_lossy())
} else {
format!(" {}", d.file_name().to_string_lossy())
}
})
.take(size.height.into()),
)
@ -904,7 +929,7 @@ pub fn preview<'a>(util: Table<'a>, lua: &Lua) -> Result<Table<'a>> {
"-> ×".into()
} else if node.is_symlink {
node.symlink
.map(|s| format!(" -> {}", s.absolute_path))
.map(|s| format!("-> {}", s.absolute_path))
.unwrap_or_default()
} else {
format_node(&node)

@ -894,10 +894,10 @@ fn draw_preview(
String::new()
};
let preview =
Paragraph::new(string_to_text(preview)).block(block(config, " Preview ".into()));
f.render_widget(preview, layout_size);
let mut text = string_to_text(preview);
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(block, layout_size);
}
fn draw_selection(

Loading…
Cancel
Save