mirror of
https://github.com/mistricky/codesnap.nvim.git
synced 2024-12-31 14:07:30 -08:00
08f0b24cf4
* [Update] apply template * [Feat] update assets files (#35) * [Update] README add packer install config * [Feat] take snapshot via skia engine * [Feat] title component * [Feat] add watermark * [Feat] update padding of code panel * [Remove] pack ci script * [Release] v1.0.0 * [Update] apply template * [Chore] remove unused code * [Update] readme * [Release] v1.0.1 * [Update] apply template * [Update] readme * Update README.md * [Feat] compile nvim-0.9 FFI * [Release] v1.0.2 * [Update] apply template * [Update] README.md * [Feat] add multi platform support * [Feat] add workflow for build target binary package * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Update] files based on generated files by template generator * [Feat] build plugin after released * [Delete] build.yml * [Update] README * [Release] v1.0.3 * [Update] README * [Refactor] editor frame size calculation logic * [Refactor] update margin of watermark * [Feat] preset font family * [Refactor] update component interface * [Update] change theme to onedark * [Refactor] redefine render_error and throw it to lua scope * [Perf] build script * [Refactor] abstract component concept & implement it for all widgets * [Update] README.md --------- Co-authored-by: mistricky <mistricky@users.noreply.github.com>
62 lines
1.6 KiB
Lua
62 lines
1.6 KiB
Lua
local static = require("codesnap.static")
|
|
local table_utils = require("codesnap.utils.table")
|
|
local generator = require("generator")
|
|
local string_utils = require("codesnap.utils.string")
|
|
local visual_utils = require("codesnap.utils.visual")
|
|
|
|
local assets_folder = static.cwd .. "/assets"
|
|
|
|
local function get_extension()
|
|
local file_path = vim.fn.expand("%:p")
|
|
local file_extension = string.match(file_path, "%.([^%.]+)$")
|
|
|
|
return file_extension
|
|
end
|
|
|
|
local main = {
|
|
cwd = static.cwd,
|
|
preview_switch = static.preview_switch,
|
|
}
|
|
|
|
function main.setup(config)
|
|
static.config = table_utils.merge(static.config, config == nil and {} or config)
|
|
end
|
|
|
|
local function get_config()
|
|
local code = visual_utils.get_selected_text()
|
|
local extension = get_extension()
|
|
|
|
if string_utils.is_str_empty(code) then
|
|
error("Please select code which you want to take snapshot first")
|
|
end
|
|
|
|
if string_utils.is_str_empty(extension) then
|
|
error("Cannot detect current filetype")
|
|
end
|
|
|
|
return table_utils.merge({
|
|
code = code,
|
|
extension = extension,
|
|
fonts_folder = assets_folder .. "/fonts",
|
|
themes_folder = assets_folder .. "/themes",
|
|
theme = "base16-onedark",
|
|
}, static.config)
|
|
end
|
|
|
|
function main.copy_into_clipboard()
|
|
generator.copy_into_clipboard(get_config())
|
|
vim.cmd("delmarks <>")
|
|
vim.notify("Save snapshot into clipboard successfully")
|
|
end
|
|
|
|
function main.save_snapshot()
|
|
if string_utils.is_str_empty(static.config.save_path) then
|
|
error("Cannot find save_path from config")
|
|
end
|
|
|
|
generator.save_snapshot(get_config())
|
|
vim.cmd("delmarks <>")
|
|
vim.notify("Save snapshot in " .. static.config.save_path .. " successfully")
|
|
end
|
|
|
|
return main
|