mirror of
https://github.com/NotAShelf/slides.nvim.git
synced 2025-02-22 03:18:04 +00:00
format via stylua
This commit is contained in:
parent
b6f9a58d5d
commit
4c168fb470
2 changed files with 28 additions and 20 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -47,4 +47,4 @@ jobs:
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
version: v0.18.2
|
version: v0.18.2
|
||||||
args: --check lua tests
|
args: --check lua
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local state = {
|
local state = {
|
||||||
win = nil
|
win = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
bin = 'slides',
|
bin = "slides",
|
||||||
fullscreen = true,
|
fullscreen = true,
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = "shadow"
|
border = "shadow",
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.close()
|
function M.close()
|
||||||
|
@ -18,9 +18,12 @@ function M.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(user_config)
|
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
|
end
|
||||||
|
|
||||||
function M.show(file)
|
function M.show(file)
|
||||||
|
@ -29,25 +32,27 @@ function M.show(file)
|
||||||
local opts = {
|
local opts = {
|
||||||
style = config.style,
|
style = config.style,
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = config.fullscreen and vim.api.nvim_get_option("columns") or vim.api.nvim_win_get_width(window),
|
width = config.fullscreen and vim.api.nvim_get_option("columns")
|
||||||
height = config.fullscreen and vim.api.nvim_get_option("lines") or vim.api.nvim_win_get_height(window),
|
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,
|
row = 1,
|
||||||
col = 1,
|
col = 1,
|
||||||
border = config.border,
|
border = config.border,
|
||||||
}
|
}
|
||||||
|
|
||||||
local input = string.len(file) == 0 and vim.api.nvim_get_current_buf() or file
|
local input = string.len(file) == 0 and vim.api.nvim_get_current_buf() or file
|
||||||
local is_file = type(input) == 'string'
|
local is_file = type(input) == "string"
|
||||||
local filetype = is_file and vim.fn.fnamemodify(input, ':e'):gsub("\"", "") or
|
local filetype = is_file and vim.fn.fnamemodify(input, ":e"):gsub('"', "")
|
||||||
vim.api.nvim_buf_get_option(input, 'filetype')
|
or vim.api.nvim_buf_get_option(input, "filetype")
|
||||||
|
|
||||||
if not vim.tbl_contains({ 'md', 'markdown' }, filetype) then
|
if not vim.tbl_contains({ "md", "markdown" }, filetype) then
|
||||||
vim.api.nvim_err_writeln('Invalid filetype')
|
vim.api.nvim_err_writeln("Invalid filetype")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.executable(config.bin) ~= 1 then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,13 +61,16 @@ function M.show(file)
|
||||||
|
|
||||||
state.win = win
|
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)), {
|
vim.fn.termopen(
|
||||||
|
config.bin .. " " .. (is_file and input or vim.api.nvim_buf_get_name(input)),
|
||||||
|
{
|
||||||
on_exit = function()
|
on_exit = function()
|
||||||
M.close()
|
M.close()
|
||||||
end
|
end,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Reference in a new issue