Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0oAstro/silicon.lua
Beautiful code snippet images right in the most epic editor :chef_kiss:
https://github.com/0oAstro/silicon.lua
Last synced: 12 days ago
JSON representation
Beautiful code snippet images right in the most epic editor :chef_kiss:
- Host: GitHub
- URL: https://github.com/0oAstro/silicon.lua
- Owner: 0oAstro
- License: unlicense
- Archived: true
- Created: 2021-12-24T16:17:44.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-01T21:41:19.000Z (9 months ago)
- Last Synced: 2024-08-01T22:54:08.885Z (3 months ago)
- Language: Lua
- Size: 372 KB
- Stars: 149
- Watchers: 4
- Forks: 9
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# silicon.lua
**silicon** is a lua plugin for neovim to generate beautiful images of code snippet using [silicon](https://github.com/aloxaf/silicon)
## ✨ Features
- **beautiful** images of source code, saved to preferred place.
- **copy** to clipboard## ⚡️ Requirements
- Neovim >= 0.6.0
- [silicon](https://github.com/aloxaf/silicon)## 📦 Installation
Install the plugin with your preferred package manager:
### [packer](https://github.com/wbthomason/packer.nvim)
```lua
-- Lua
use {
"narutoxy/silicon.lua",
requires = { "nvim-lua/plenary.nvim" },
config = function()
require('silicon').setup({})
end
}
```### [vim-plug](https://github.com/junegunn/vim-plug)
```vim
" Vim Script
Plug 'nvim-lua/plenary.nvim'
Plug 'narutoxy/silicon.lua'lua require('silicon').setup({})
```## ⚙️ Configuratioon
silicon comes with the following defaults:
```lua
{
theme = "auto",
output = "SILICON_${year}-${month}-${date}_${time}.png", -- auto generate file name based on time (absolute or relative to cwd)
bgColor = vim.g.terminal_color_5,
bgImage = "", -- path to image, must be png
roundCorner = true,
windowControls = true,
lineNumber = true,
font = "monospace",
lineOffset = 1, -- from where to start line number
linePad = 2, -- padding between lines
padHoriz = 80, -- Horizontal padding
padVert = 100, -- vertical padding
shadowBlurRadius = 10,
shadowColor = "#555555",
shadowOffsetX = 8,
shadowOffsetY = 8,
gobble = false, -- enable lsautogobble like feature
debug = false, -- enable debug output
}
```# 🚀 Usage
## Keymaps
```lua
-- Generate image of lines in a visual selection
vim.keymap.set('v', 's', function() silicon.visualise_api() end )
-- Generate image of a whole buffer, with lines in a visual selection highlighted
vim.keymap.set('v', 'bs', function() silicon.visualise_api({to_clip = true, show_buf = true}) end )
-- Generate visible portion of a buffer
vim.keymap.set('n', 's', function() silicon.visualise_api({to_clip = true, visible = true}) end )
-- Generate current buffer line in normal mode
vim.keymap.set('n', 's', function() silicon.visualise_api({to_clip = true}) end )
```## Command line
Calling `silicon.visualise_api` with `lua` in command line doesn't work due to `lua` not supporting ranges.
This means that the moment you hit enter, you leave visual mode before lua function is called. While this populates two registers, using them doesn't work with "v" mode maps.
A workaround has been implemented, and a shorthand that forces it is available as `.visualise_cmdline`:- Generate image of lines in a visual selection
```lua
lua require('silicon').visualise_cmdline()
```- Generate image of a whole buffer, with lines in a visual selection highlighted
```lua
lua require('silicon').visualise_cmdline({to_clip = true, show_buf = true})
```- Generate visible portion of a buffer
```lua
lua require('silicon').visualise_cmdline({to_clip = true, visible = true})
```## Notes
- The default path of image is the current working directory of the editor, but you can change it by
```lua
require("silicon").setup({
output = "/home/astro/Pictures/SILICON_$year-$month-$date-$time.png"),
})
```## Colorscheme reloading
Autogenerated silicon themes are unaware of dark/light variants.
Utility functions had been exposed that allow regenerating theme on demand:- `require("silicon.utils").build_tmTheme()` builds a new tmTheme file from current colorscheme
- `require("silicon.utils").reload_silicon_cache()` calls `silicon --build-cache`This lets one regenerate theme when switching background setting or otherwise reloading `ColorScheme`:
```lua
vim.api.nvim_create_augroup('SiliconRefresh', { clear = true })
vim.api.nvim_create_autocmd({ 'ColorScheme' },
{
group = 'SiliconRefresh',
callback = function()
silicon_utils.build_tmTheme()
silicon_utils.reload_silicon_cache({async = true})
end,
desc = 'Reload silicon themes cache on colorscheme switch',
}
)
```