mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-16 20:34:39 +02:00
feat(snacks): use terminal
This commit is contained in:
parent
45acfaacb5
commit
ad9d3d19b1
9 changed files with 77 additions and 89 deletions
|
@ -148,19 +148,22 @@ end
|
|||
function M.blame_line(opts)
|
||||
opts = vim.tbl_deep_extend("force", {
|
||||
count = 3,
|
||||
filetype = "git",
|
||||
size = {
|
||||
width = 0.6,
|
||||
height = 0.6,
|
||||
interactive = false,
|
||||
float = {
|
||||
win = {
|
||||
width = 0.6,
|
||||
height = 0.6,
|
||||
border = "rounded",
|
||||
},
|
||||
bo = { filetype = "git" },
|
||||
},
|
||||
border = "rounded",
|
||||
}, opts or {})
|
||||
local cursor = vim.api.nvim_win_get_cursor(0)
|
||||
local line = cursor[1]
|
||||
local file = vim.api.nvim_buf_get_name(0)
|
||||
local root = LazyVim.root.detectors.pattern(0, { ".git" })[1] or "."
|
||||
local cmd = { "git", "-C", root, "log", "-n", opts.count, "-u", "-L", line .. ",+1:" .. file }
|
||||
return require("lazy.util").float_cmd(cmd, opts)
|
||||
return Snacks.terminal(cmd, opts)
|
||||
end
|
||||
|
||||
-- stylua: ignore
|
||||
|
|
|
@ -72,15 +72,17 @@ function M.open(file, opts)
|
|||
end
|
||||
end
|
||||
|
||||
local float = require("lazy.util").float({
|
||||
local float = Snacks.float({
|
||||
file = file,
|
||||
size = { width = 0.6, height = 0.6 },
|
||||
win = { width = 0.6, height = 0.6 },
|
||||
wo = {
|
||||
spell = false,
|
||||
wrap = false,
|
||||
signcolumn = "yes",
|
||||
statuscolumn = " ",
|
||||
conceallevel = 3,
|
||||
},
|
||||
})
|
||||
vim.opt_local.spell = false
|
||||
vim.opt_local.wrap = false
|
||||
vim.opt_local.signcolumn = "yes"
|
||||
vim.opt_local.statuscolumn = " "
|
||||
vim.opt_local.conceallevel = 3
|
||||
if vim.diagnostic.enable then
|
||||
pcall(vim.diagnostic.enable, false, { bufnr = float.buf })
|
||||
else
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
---@class lazyvim.util.terminal
|
||||
---@overload fun(cmd: string|string[], opts: LazyTermOpts): LazyFloat
|
||||
---@overload fun(cmd: string|string[], opts: snacks.terminal.Config): snacks.terminal
|
||||
local M = setmetatable({}, {
|
||||
__call = function(m, ...)
|
||||
return m.open(...)
|
||||
end,
|
||||
})
|
||||
|
||||
---@type table<string,LazyFloat>
|
||||
local terminals = {}
|
||||
|
||||
---@param shell? string
|
||||
function M.setup(shell)
|
||||
vim.o.shell = shell or vim.o.shell
|
||||
|
@ -40,58 +37,12 @@ function M.setup(shell)
|
|||
end
|
||||
end
|
||||
|
||||
---@class LazyTermOpts: LazyCmdOptions
|
||||
---@field interactive? boolean
|
||||
---@field esc_esc? boolean
|
||||
---@field ctrl_hjkl? boolean
|
||||
|
||||
-- Opens a floating terminal (interactive by default)
|
||||
---@deprecated use Snacks.terminal instead
|
||||
---@param cmd? string[]|string
|
||||
---@param opts? LazyTermOpts
|
||||
---@param opts? snacks.terminal.Config
|
||||
function M.open(cmd, opts)
|
||||
opts = vim.tbl_deep_extend("force", {
|
||||
ft = "lazyterm",
|
||||
size = { width = 0.9, height = 0.9 },
|
||||
backdrop = LazyVim.has("edgy.nvim") and not cmd and 100 or nil,
|
||||
}, opts or {}, { persistent = true }) --[[@as LazyTermOpts]]
|
||||
|
||||
local termkey = vim.inspect({ cmd = cmd or "shell", cwd = opts.cwd, env = opts.env, count = vim.v.count1 })
|
||||
|
||||
if terminals[termkey] and terminals[termkey]:buf_valid() then
|
||||
terminals[termkey]:toggle()
|
||||
else
|
||||
terminals[termkey] = require("lazy.util").float_term(cmd, opts)
|
||||
local buf = terminals[termkey].buf
|
||||
vim.b[buf].lazyterm_cmd = cmd
|
||||
if opts.esc_esc == false then
|
||||
vim.keymap.set("t", "<esc>", "<esc>", { buffer = buf, nowait = true })
|
||||
end
|
||||
if opts.ctrl_hjkl == false then
|
||||
vim.keymap.set("t", "<c-h>", "<c-h>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-j>", "<c-j>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-k>", "<c-k>", { buffer = buf, nowait = true })
|
||||
vim.keymap.set("t", "<c-l>", "<c-l>", { buffer = buf, nowait = true })
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "gf", function()
|
||||
local f = vim.fn.findfile(vim.fn.expand("<cfile>"))
|
||||
if f ~= "" then
|
||||
vim.cmd("close")
|
||||
vim.cmd("e " .. f)
|
||||
end
|
||||
end, { buffer = buf })
|
||||
|
||||
vim.api.nvim_create_autocmd("BufEnter", {
|
||||
buffer = buf,
|
||||
callback = function()
|
||||
vim.cmd.startinsert()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.cmd("noh")
|
||||
end
|
||||
|
||||
return terminals[termkey]
|
||||
return Snacks.terminal(cmd, opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue