2024-02-19 14:27:17 +00:00
|
|
|
local table_utils = require("codesnap.utils.table")
|
2024-02-14 17:15:26 +00:00
|
|
|
local static = require("codesnap.static")
|
2024-02-19 14:27:17 +00:00
|
|
|
local client = require("codesnap.client")
|
|
|
|
local visual_utils = require("codesnap.utils.visual")
|
2024-02-14 17:15:26 +00:00
|
|
|
|
2024-02-21 10:33:44 +00:00
|
|
|
local main = {
|
|
|
|
cwd = static.cwd,
|
|
|
|
preview_switch = static.preview_switch,
|
|
|
|
}
|
2024-02-13 06:05:36 +00:00
|
|
|
|
|
|
|
function main.setup(config)
|
2024-02-19 14:27:17 +00:00
|
|
|
static.config = table_utils.merge(static.config, config == nil and {} or config)
|
|
|
|
|
|
|
|
if static.config.auto_load then
|
|
|
|
client:start()
|
|
|
|
end
|
|
|
|
|
|
|
|
client:send("config_setup", static.config)
|
|
|
|
end
|
|
|
|
|
|
|
|
function main.preview_code()
|
|
|
|
client:send("preview_code", { content = visual_utils.get_selected_text(), language = vim.bo.filetype })
|
2024-02-13 06:05:36 +00:00
|
|
|
end
|
|
|
|
|
2024-02-21 10:33:44 +00:00
|
|
|
function main.open_preview()
|
|
|
|
client:send("open_preview")
|
|
|
|
end
|
|
|
|
|
|
|
|
function main.stop_client()
|
|
|
|
client:stop()
|
|
|
|
end
|
|
|
|
|
2024-02-13 06:05:36 +00:00
|
|
|
return main
|