From 3eabbd4ed63050bc425a71bdc6fabc3cf035579e Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Thu, 26 May 2022 16:17:44 +0530 Subject: [PATCH] Update awesome-hacks.md --- docs/en/src/awesome-hacks.md | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/docs/en/src/awesome-hacks.md b/docs/en/src/awesome-hacks.md index f3604a9..e45ef9a 100644 --- a/docs/en/src/awesome-hacks.md +++ b/docs/en/src/awesome-hacks.md @@ -384,6 +384,84 @@ imv-msg "$IMV_PID" quit +### Text preview pane + +Preview text files in a native xplr pane (should be fast enough). + +
+Expand for details + +- Author: [@sayanarijit][8] +- Requires: none +- Tested on: Linux + +```lua +local function stat(node) + return node.mime_essence +end + +local function read(path, lines) + local out = "" + local p = io.open(path) + + if p == nil then + return stat(path) + end + + local i = 0 + for line in p:lines() do + out = out .. line .. "\n" + if i == lines then + break + end + i = i + 1 + end + p:close() + + return out +end + +xplr.config.layouts.builtin.default = { + Horizontal = { + config = { + constraints = { + { Percentage = 60 }, + { Percentage = 40 }, + }, + }, + splits = { + "Table", + { + CustomContent = { + title = "preview", + body = { DynamicParagraph = { render = "custom.render_layout" } }, + }, + }, + }, + }, +} + +xplr.fn.custom.render_layout = function(ctx) + local n = ctx.app.focused_node + + if n.canonical then + n = n.canonical + end + + if n then + if n.is_file and not n.is_symlink then + return read(n.absolute_path, ctx.layout_size.height) + else + return stat(n) + end + else + return "" + end +end +``` +
+ + ## Also See: - [Awesome Plugins][15]