codesnap.nvim/lua/codesnap/init.lua

116 lines
3.9 KiB
Lua
Raw Permalink Normal View History

local static = require("codesnap.static")
local visual_utils = require("codesnap.utils.visual")
[Release] v1.0.0 (#43) * [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>
2024-03-16 10:07:12 -07:00
local table_utils = require("codesnap.utils.table")
local string_utils = require("codesnap.utils.string")
local path_utils = require("codesnap.utils.path")
local module = require("codesnap.module")
local config_module = require("codesnap.config")
2024-04-27 04:07:41 -07:00
local highlight_module = require("codesnap.highlight")
[Release] v1.0.0 (#43) * [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>
2024-03-16 10:07:12 -07:00
2024-02-21 02:33:44 -08:00
local main = {
cwd = static.cwd,
2024-04-27 04:07:41 -07:00
highlight_mode_config = nil,
2024-02-21 02:33:44 -08:00
}
2024-02-12 22:05:36 -08:00
-- Prepare the path of the Rust module
-- Concat lib?.extension and ?.extension to package.cpath
package.cpath = path_utils.join(";", package.cpath, module.generator_file("?"), module.generator_file("lib?"))
[Release] v1.0.0 (#43) * [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>
2024-03-16 10:07:12 -07:00
function main.setup(config)
static.config = table_utils.merge_config(static.config, config == nil and {} or config)
end
-- Save snapshot to specified save_path
--- @param save_path string
function main.save(save_path)
local generator = require("generator")
if save_path == nil then
error("Save path is not specified", 0)
end
generator.save(save_path, config_module.get_config())
[Release] v1.0.0 (#43) * [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>
2024-03-16 10:07:12 -07:00
vim.cmd("delmarks <>")
vim.notify("Save snapshot in " .. save_path .. " successfully!")
2024-02-21 02:33:44 -08:00
end
-- Copy snapshot into clipboard
--- @param type? string
function main.copy(type)
local snapshot_type = type == nil and "png" or type
local generator = require("generator")
2024-04-27 04:07:41 -07:00
generator.copy(snapshot_type, config_module.get_config())
vim.cmd("delmarks <>")
vim.notify("The snapshot is copied into clipboard successfully!")
2024-04-27 04:07:41 -07:00
end
-- Generate ASCII code snapshot and copy it into clipboard
function main.copy_ascii()
local generator = require("generator")
2024-04-27 04:07:41 -07:00
generator.copy_ascii(config_module.get_config())
vim.cmd("delmarks <>")
vim.notify("The ASCII code snapshot is copied into clipboard successfully!")
2024-04-27 04:07:41 -07:00
end
-- function main.copy_into_clipboard_with_config(config)
-- require("generator").copy_into_clipboard(config)
-- vim.cmd("delmarks <>")
-- vim.notify("Save snapshot into clipboard successfully")
-- end
--
-- -- Take ASCII code snapshot into clipboard
-- function main.copy_ascii_snapshot(extension)
-- require("generator").copy_ascii(config_module.get_config(extension))
-- vim.cmd("delmarks <>")
-- vim.notify("Save snapshot into clipboard successfully")
-- end
--
-- function main.save_snapshot_with_config(config)
-- if string_utils.is_str_empty(static.config.save_path) then
-- error(
-- "If you want to save snapshot in somewhere, you should config the save_path before, refer: https://github.com/mistricky/codesnap.nvim?tab=readme-ov-file#save-the-snapshot",
-- 0
-- )
-- end
--
-- local matched_extension = string.match(static.config.save_path, "%.(.+)$")
--
-- if matched_extension ~= "png" and matched_extension ~= nil then
-- error("The extension of save_path should be .png", 0)
-- end
--
-- require("generator").save_snapshot(config)
-- vim.cmd("delmarks <>")
-- ---@diagnostic disable-next-line: need-check-nil
-- vim.notify("Save snapshot in " .. config.save_path .. " successfully")
-- end
--
-- -- Take a snapshot and copy it into clipboard
-- function main.copy_into_clipboard(extension)
-- main.copy_into_clipboard_with_config(config_module.get_config(extension))
-- end
--
-- -- Take a snapshot and save it into the specified path
-- function main.save_snapshot(extension)
-- main.save_snapshot_with_config(config_module.get_config(extension))
-- end
--
-- function main.highlight_mode_copy_into_clipboard(extension)
-- main.highlight_mode_config = config_module.get_config(extension)
--
-- highlight_module.create_highlight_selector_window(
-- "copy_into_clipboard_with_config",
-- visual_utils.get_selected_lines()
-- )
-- end
--
-- function main.highlight_mode_save_snapshot(extension)
-- main.highlight_mode_config = config_module.get_config(extension)
--
-- highlight_module.create_highlight_selector_window("save_snapshot_with_config", visual_utils.get_selected_lines())
-- end
2024-04-27 04:07:41 -07:00
2024-02-12 22:05:36 -08:00
return main