From 884fc44344e4c5a7f58bd4c87bf6360b1d2b1525 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Thu, 29 Feb 2024 21:35:27 +0100 Subject: [PATCH] feat(nvim-silicon.lua): add support for generating code images using Silicon feat(nvim-silicon.lua): create configuration to use Silicon for code image generation --- lua/absolute/after/nvim-silicon.lua | 69 +++++++++++++++++++++++++++ lua/absolute/plugins/nvim-silicon.lua | 6 +++ 2 files changed, 75 insertions(+) create mode 100644 lua/absolute/after/nvim-silicon.lua create mode 100644 lua/absolute/plugins/nvim-silicon.lua diff --git a/lua/absolute/after/nvim-silicon.lua b/lua/absolute/after/nvim-silicon.lua new file mode 100644 index 0000000..1135f98 --- /dev/null +++ b/lua/absolute/after/nvim-silicon.lua @@ -0,0 +1,69 @@ +local silicon = require("silicon") + +local home = os.getenv("HOME") + +local function generate_file_name() + -- Generate a file name + local file_name = os.date("!%Y-%m-%dT%H-%M-%S") .. "_code.png" + return "./" .. file_name +end + +silicon.setup({ + font = "JetBrains Mono=34;Noto Emoji", + output = generate_file_name, +}) + +-- { +-- -- the font settings with size and fallback font +-- -- the theme to use, depends on themes available to silicon +-- theme = "gruvbox-dark", +-- -- the background color outside the rendered os window +-- background = "#076678", +-- -- a path to a background image +-- background_image = nil, +-- -- the paddings to either side +-- pad_horiz = 100, +-- pad_vert = 80, +-- -- whether to have the os window rendered with rounded corners +-- no_round_corner = false, +-- -- whether to put the close, minimize, maximise traffic light controls on the border +-- no_window_controls = false, +-- -- whether to turn off the line numbers +-- no_line_number = false, +-- -- with which number the line numbering shall start, the default is 1, but here a +-- -- function is used to return the actual source code line number +-- line_offset = function(args) +-- return args.line1 +-- end, +-- -- the distance between lines of code +-- line_pad = 0, +-- -- the rendering of tab characters as so many space characters +-- tab_width = 4, +-- -- with which language the syntax highlighting shall be done, should be a function +-- -- that returns either a language name or an extension like ".js" +-- language = function() +-- return vim.bo.filetype +-- end, +-- -- if the shadow below the os window should have be blurred +-- shadow_blur_radius = 16, +-- -- the offset of the shadow in x and y directions +-- shadow_offset_x = 8, +-- shadow_offset_y = 8, +-- -- the color of the shadow +-- shadow_color = "#100808", +-- -- whether to strip of superfluous leading whitespace +-- gobble = true, +-- -- a string or function that defines the path to the output image +-- output = function() +-- return "./" .. os.date("!%Y-%m-%dT%H-%M-%S") .. "_code.png" +-- end, +-- -- whether to put the image onto the clipboard, may produce an error if run on WSL2 +-- to_clipboard = false, +-- -- the silicon command, put an absolute location here, if the command is not in your PATH +-- command = "silicon", +-- -- a string or function returning a string that defines the title showing in the image +-- -- only works in silicon versions greater than v0.5.1 +-- window_title = function() +-- return vim.fn.fnamemodify(vim.api.nvim_buf_get_name(vim.api.nvim_get_current_buf()), ":t") +-- end, +-- } diff --git a/lua/absolute/plugins/nvim-silicon.lua b/lua/absolute/plugins/nvim-silicon.lua new file mode 100644 index 0000000..358941e --- /dev/null +++ b/lua/absolute/plugins/nvim-silicon.lua @@ -0,0 +1,6 @@ +return { + "michaelrommel/nvim-silicon", + config = function() + require("absolute.after.nvim-silicon") + end, +}