format via stylua

This commit is contained in:
raf 2023-12-31 13:14:21 +03:00
parent b6f9a58d5d
commit 4c168fb470
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 28 additions and 20 deletions

View file

@ -47,4 +47,4 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.18.2
args: --check lua tests
args: --check lua

View file

@ -1,14 +1,14 @@
local M = {}
local state = {
win = nil
win = nil,
}
local config = {
bin = 'slides',
bin = "slides",
fullscreen = true,
style = "minimal",
border = "shadow"
border = "shadow",
}
function M.close()
@ -18,9 +18,12 @@ function M.close()
end
function M.setup(user_config)
config = vim.tbl_deep_extend('force', {}, config, user_config or {})
config = vim.tbl_deep_extend("force", config, user_config or {})
vim.cmd [[command! -nargs=? -complete=file Slides :lua require"slides".show('<f-args>')]]
vim.cmd(
[[command! -nargs=? -complete=file Slides :lua require"slides".show('<f-args>')]]
)
vim.cmd([[command! SlidesClose :lua require"slides".close()]])
end
function M.show(file)
@ -29,25 +32,27 @@ function M.show(file)
local opts = {
style = config.style,
relative = "editor",
width = config.fullscreen and vim.api.nvim_get_option("columns") or vim.api.nvim_win_get_width(window),
height = config.fullscreen and vim.api.nvim_get_option("lines") or vim.api.nvim_win_get_height(window),
width = config.fullscreen and vim.api.nvim_get_option("columns")
or vim.api.nvim_win_get_width(window),
height = config.fullscreen and vim.api.nvim_get_option("lines")
or vim.api.nvim_win_get_height(window),
row = 1,
col = 1,
border = config.border,
}
local input = string.len(file) == 0 and vim.api.nvim_get_current_buf() or file
local is_file = type(input) == 'string'
local filetype = is_file and vim.fn.fnamemodify(input, ':e'):gsub("\"", "") or
vim.api.nvim_buf_get_option(input, 'filetype')
local is_file = type(input) == "string"
local filetype = is_file and vim.fn.fnamemodify(input, ":e"):gsub('"', "")
or vim.api.nvim_buf_get_option(input, "filetype")
if not vim.tbl_contains({ 'md', 'markdown' }, filetype) then
vim.api.nvim_err_writeln('Invalid filetype')
if not vim.tbl_contains({ "md", "markdown" }, filetype) then
vim.api.nvim_err_writeln("Invalid filetype")
return
end
if vim.fn.executable(config.bin) ~= 1 then
vim.api.nvim_err_writeln('Executable not found')
vim.api.nvim_err_writeln("Executable not found")
return
end
@ -56,13 +61,16 @@ function M.show(file)
state.win = win
vim.cmd('startinsert!')
vim.cmd("startinsert!")
vim.fn.termopen(config.bin .. ' ' .. (is_file and input or vim.api.nvim_buf_get_name(input)), {
on_exit = function()
M.close()
end
})
vim.fn.termopen(
config.bin .. " " .. (is_file and input or vim.api.nvim_buf_get_name(input)),
{
on_exit = function()
M.close()
end,
}
)
end
return M